コード例 #1
0
 public IActionResult Login(UserVM userVM)
 {
     if (ModelState.IsValid)
     {
         var user = UserVM.LoginUser(bussinseContext, userVM);
         if (user == null)
         {
             ViewBag.LoginError = true;
             ViewBag.Message    = "UserName or password is incorrect";
             return(View(userVM));
         }
         HttpContext.Session.SetInt32("CurrentUserId", user.id);
         HttpContext.Session.SetString("UserName", user.userName);
         HttpContext.Session.SetInt32("UserRole", user.role.Value);
     }
     return(RedirectToAction("Index", "Home"));
 }