i want to create login page for admin and user in MVC5.
if registration time select user then after login automatically goto user panel.
and if admin then automatically go to admin panel in MVC
here is my code for admin.
- public ActionResult Login()
- {
- return View();
- }
- [HttpPost]
- public ActionResult Login(UserMaster_Model user)
- {
- if (ModelState.IsValid)
- {
- var details = (from userlist in _userMaster.GetAll()
- where userlist.USMType == "Admin" && userlist.USMEmail == user.USMEmail && userlist.USMPassword == user.USMPassword
- select new
- {
- userlist.USMUserName,
- userlist.USMId,
- userlist.USMEmail
- }).ToList();
- if (details.FirstOrDefault() != null)
- {
- Session["USMUserName"] = details.FirstOrDefault().USMUserName;
- Session["USMId"] = details.FirstOrDefault().USMId;
- Session["USMEmail"] = details.FirstOrDefault().USMEmail;
- return RedirectToAction("Dashboard");
- }
- else
- {
- ViewBag.ErrorMessage = "Invalid User Name OR Password";
- }
- }
- else
- {
- ViewBag.ErrorMessage = "Enter Username & Password";
- }
- return View(user);
- }
- public ActionResult Login()
- {
- return View();
- }
- [HttpPost]
- public ActionResult Login(UserMaster_Model user)
- {
- if (ModelState.IsValid)
- {
- var details = (from userlist in _userMaster.GetAll()
- where userlist.USMEmail == user.USMEmail && userlist.USMPassword == user.USMPassword
- select new
- {
- userlist.USMId,
- userlist.USMEmail,
- userlist.USMUserName
- }).FirstOrDefault();
- if (details != null)
- {
- Session["USMUserName"] = details.USMUserName;
- Session["USMId"] = details.USMId;
- Session["USMEmail"] = details.USMEmail;
- return RedirectToAction("Index", "CompanyMaster");
- }
- else
- {
- ViewBag.ErrorMessage = "Invalid User Name OR Password";
- }
- }
- else
- {
- ViewBag.ErrorMessage = "Enter Username AND Password";
- }
- return View(user);
- }
both code are in different controller, i want to both code are use in one action one controller How is possible ?
give me answer for only MVC.
thanks in advance

Rajesh GamiPosted Apr 13, 2018, 1:29 AM
Ketan MokariyaPosted Apr 13, 2018, 1:06 AM
When registering user, Store user with its type Admin or User, So when any user login you need to check user its type in db .As you are doing for admin. Better first validate user and then check for type as given below.