public ActionResult RegisterUser(User user) { if (userRepository.AddUser(user.Name, user.Password)) return RedirectToAction("Index", "Lotto"); else { ModelState.AddModelError("RegisterUser", "Name already exists!"); return View(); } }
public bool AddUser(string name, string password) { User user = dbContext.Users.FirstOrDefault(p => p.Name == name); if (user == null) { User newUser = new User() { Name = name, Password = password }; dbContext.Users.Add(newUser); dbContext.SaveChanges(); return true; } return false; }
public bool SaveUser(User user) { User modifiedUser = dbContext.Users.FirstOrDefault(p => p.UserID == user.UserID); modifiedUser.Name = user.Name; modifiedUser.Password = user.Password; modifiedUser.IsActive = user.IsActive; modifiedUser.IsAdmin = user.IsAdmin; dbContext.SaveChanges(); return true; }
public ActionResult LogInUser(User user) { User authUser = authProvider.Authenticate(user.Name, user.Password); if (authUser != null) { HttpContext.Session["User"] = authUser; return RedirectToAction("Index", "Lotto"); } else { ModelState.AddModelError("LoginUser", "User not found"); return View(); } }