public ActionResult NewAccount(NewAccountModel newAccountModel) { if (ModelState.IsValid) { var service = new AccountService(); try { service.AddNewUser(newAccountModel); FormsAuthentication.RedirectToLoginPage(); } catch (UpdateException updateEx) { var sqlEx = updateEx.InnerException as SqlException; ModelState.AddModelError("NewUserError", sqlEx.Number == 2601 ? "This UserName is already used by another user" : "Database error while creating new user"); } catch (Exception ex) { ModelState.AddModelError("NewUserError", "Unknown error while creating new user"); } } return View(newAccountModel); }
public void AddNewUser(NewAccountModel newAccount) { UserRepository.AddNewUser(new User { UserName = newAccount.UserName, Password = newAccount.Password, Point = 0 }); }
public AccountViewModel() { LoginModel = new LoginModel(); NewAccountModel = new NewAccountModel(); }