public IActionResult Login([Bind] User user) { try { if (ModelState.IsValid) { var result = _userDB.loginUser(user); if (result.error) { TempData["msg"] = result.message; return(View("~/Views/Login/Index.cshtml")); } else { var temp = _userDB.getUser(user); if (temp != null) { _userDB.updateUserSignIn(temp.user_email); HttpContext.Session.SetString("firstName", temp.user_first_name); HttpContext.Session.SetString("lastName", temp.user_last_name); HttpContext.Session.SetString("userEmail", temp.user_email); HttpContext.Session.SetString("userRole", temp.user_role); Activity activity = new Activity { user_email = temp.user_email, user_first_name = temp.user_first_name, user_last_name = temp.user_last_name, activity_type = "Sign in", activity_details = "", last_activity = DateTime.Now, }; _activityDB.logActivity(activity); TempData["msg"] = result.message; return(RedirectToAction("Index", "Main")); } else { TempData["msg"] = "Failed to retrieve user information."; return(View("~/Views/Login/Index.cshtml")); } } } } catch (Exception e) { TempData["msg"] = e.Message; } return(View("~/Views/Login/Index.cshtml")); }