Esempio n. 1
0
 public void SaveUser(User user)
 {
     if (user.UserId == 0)
         _dbContext.Users.Add(user);
     else if (_dbContext.Entry<User>(user).State != System.Data.EntityState.Modified)
         _dbContext.Entry<User>(user).State = System.Data.EntityState.Modified;
     _dbContext.SaveChanges();
 }
Esempio n. 2
0
        public ActionResult Create(User user)
        {
            var existingUser = _userRepo.GetUser(user.UserName);

            if (existingUser != null)
                ModelState.AddModelError("UserName", "User name is already used");
            if (!ModelState.IsValid)
                return View(user);

            user.Role = (int)UserRole.QualityAssurance;
            user.Password = PasswordUtility.HashPassword(user.Password);
            _userRepo.SaveUser(user);

            return RedirectToAction("Details", new { id = user.UserId });
        }
Esempio n. 3
0
        public ActionResult Edit(int id, User user)
        {
            if (!ModelState.IsValid)
                return View(user);

            var userDb = _userRepo.GetUser(id);

            userDb.FirstName = user.FirstName;
            userDb.LastActivity = user.LastName;
            userDb.Email = user.Email;
            userDb.Phone = user.Phone;
            if (userDb.Password != user.Password)
                userDb.Password = PasswordUtility.HashPassword(user.Password);

            _userRepo.SaveUser(userDb);

            return RedirectToAction("Index");
        }
Esempio n. 4
0
 public void DeleteUser(User user)
 {
     _dbContext.Users.Remove(user);
     _dbContext.SaveChanges();
 }