public void RegisterUser(User user) { if(_repository.GetUsers().ToList().Any( it => it.UserName == user.UserName)) { throw new UserAlreadyExist(); } _repository.AddUser(user); }
public ActionResult Register(RegisterModel model) { if(ModelState.IsValid) { var user = new User { Id = Guid.NewGuid(), Password = model.Password, UserName = model.UserName }; try { _authentificator.RegisterUser(user); } catch (UserAlreadyExist) { return View(model); } return RedirectToAction("Okey"); } return View(model); }
public void AddUser(User user) { _dataBaseContext.Users.Add(user); _dataBaseContext.SaveChanges(); }