示例#1
0
 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();
     }
 }
示例#2
0
 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;
 }
示例#3
0
        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;
        }
示例#4
0
        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();
            }
        }