public ActionResult LoginRequest(LoginViewModel viewModel) { DataRepository helper = new DataRepository(); if (helper.UserCanLogIn(viewModel)) { viewModel.user = helper.GetUser(viewModel); Session["LoggedIn"] = "true"; Session["Username"] = viewModel.user.Username.ToString(); ViewData["ReloadPage"] = "true"; return PartialView(); } TempData["ErrorMessage"] = "Login Failed"; return PartialView(); }
//Login Screen public bool UserCanLogIn(LoginViewModel viewModel) { int count = db.Users.Count(x => x.Username == viewModel.username && x.Password == viewModel.password); if (count == 1) return true; else return false; }
public ActionResult Login(LoginViewModel viewModel) { return View(viewModel); }
public User GetUser(LoginViewModel viewModel) { return db.Users.First(x => x.Username == viewModel.username && x.Password == viewModel.password); }