'Registration Admin Approval verification in C# asp dot net MVC

I need "admin approval" for login as user after the registration. I am doing it in asp.net MVC, using ms sql, visual studio. I am new to it,need help badly, how many way I can do it and whats the process to do that. My thought: I made login Registration with email verify. Now I need to make admin verify. Here is my database table :

enter image description here

Database: I made a registration table(Tbl_User), Approval Table(Tbl_Approval). I need to confirm admin approval while login:

var approval = dc.Tbl_Approval.Where(m => m.Tbl_User.EmailID == login.EmailID).FirstOrDefault();
if (!approval.ApprovalStatus)
{
    ViewBag.Message = "Please wait for admin approval";
    return View();
}

For this I need to insert the Tbl_User data into Tbl_Approval table which is previously empty. so I need the query in the controller action(for Tbl_Approval) to get the (Tbl_User)list into Tbl_Approval table and edit the Approval status. I tried this:-

public ActionResult List()
{
     List<Tbl_User> userList = db.Tbl_User.ToList();
     Tbl_Approval approval = new Tbl_Approval();
     List<Tbl_Approval> approvalUserList = userList.Select(x => new Tbl_Approval { UserID = x.UserID }).ToList();
     return View(approvalUserList);
}

Please help me on the controller action to get the(Tbl_User) list into the Tbl_Approval table. Also suggest me any other good way to do this task.



Solution 1:[1]

You can create the Action method for approval process. When admin approves any particular user, you need to pass that userId. I have used EntityFramework for the example.

Here is the code that should work

    public ActionResult ApproveUser(int userId)
    {
        var user = context.Users.Find(userId);
        if(user != null)
        {
            user.ApproveStatus = 1;

            context.Entry(user).State = System.Data.Entity.EntityState.Modified;
            context.SaveChanges();
        }

        return View();
    }

Solution 2:[2]

TO solve this issue do the following i.e.

  1. Add the status column in your login table and set the default approval status for all new sign ups as not approved.

  2. Create a module for admin only in your web portal to view/approve the new sign ups.

  3. Create designated actions with view pages in your new module to view and approve the signups.

  4. I recommend creating a new controller for this new module that is accessible to the admin only and not to everyone else.

  5. When the admin login the system show notifications to him so, he can open and go to this new module and perform approval actions.

  6. When the admin performs the approval action update the approval status from not approve to approve.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Auneell
Solution 2 Suraj Rao