Rajesh Gami

Rajesh Gami

  • 79
  • 24.4k
  • 1.3m

Simple question please help

Apr 12 2018 10:53 PM
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.
 
  1. public ActionResult Login()  
  2.         {  
  3.             return View();  
  4.         }  
  5.         [HttpPost]  
  6.         public ActionResult Login(UserMaster_Model user)  
  7.         {  
  8.   
  9.             if (ModelState.IsValid)  
  10.             {  
  11.                 var details = (from userlist in _userMaster.GetAll()  
  12.                                where userlist.USMType == "Admin" && userlist.USMEmail == user.USMEmail && userlist.USMPassword == user.USMPassword  
  13.                                select new  
  14.                                {  
  15.                                    userlist.USMUserName,  
  16.                                    userlist.USMId,  
  17.                                    userlist.USMEmail  
  18.                                }).ToList();  
  19.                 if (details.FirstOrDefault() != null)  
  20.                 {  
  21.                     Session["USMUserName"] = details.FirstOrDefault().USMUserName;  
  22.                     Session["USMId"] = details.FirstOrDefault().USMId;  
  23.                     Session["USMEmail"] = details.FirstOrDefault().USMEmail;  
  24.                     return RedirectToAction("Dashboard");  
  25.                 }  
  26.                 else  
  27.                 {  
  28.                     ViewBag.ErrorMessage = "Invalid User Name OR Password";  
  29.                 }  
  30.             }  
  31.             else  
  32.             {  
  33.                 ViewBag.ErrorMessage = "Enter Username & Password";  
  34.             }  
  35.   
  36.   
  37.             return View(user);  
  38.         } 
 and user side login for below code
  1. public ActionResult Login()  
  2.         {  
  3.             return View();  
  4.         }  
  5.         [HttpPost]  
  6.         public ActionResult Login(UserMaster_Model user)  
  7.         {  
  8.             if (ModelState.IsValid)  
  9.             {  
  10.                 var details = (from userlist in _userMaster.GetAll()  
  11.                                where userlist.USMEmail == user.USMEmail && userlist.USMPassword == user.USMPassword  
  12.                                select new  
  13.                                {  
  14.                                    userlist.USMId,  
  15.                                    userlist.USMEmail,  
  16.                                    userlist.USMUserName  
  17.                                }).FirstOrDefault();  
  18.                 if (details != null)  
  19.                 {  
  20.                     Session["USMUserName"] = details.USMUserName;  
  21.                     Session["USMId"] = details.USMId;  
  22.                     Session["USMEmail"] = details.USMEmail;  
  23.                     return RedirectToAction("Index""CompanyMaster");  
  24.                 }  
  25.                 else  
  26.                 {  
  27.                     ViewBag.ErrorMessage = "Invalid User Name OR Password";  
  28.                 }  
  29.             }  
  30.             else  
  31.             {  
  32.                 ViewBag.ErrorMessage = "Enter Username AND Password";  
  33.             }  
  34.             return View(user);  
  35.         } 
 
 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
 
 
 

Answers (2)