public ActionResult Create(UserInfoModel model) { if (model.ConfirmPassword != model.Password) { ModelState.AddModelError("Password", "Your passwords must match"); } if (model.Password.Length < 5) { ModelState.AddModelError("Password", "Password must be at least 5 characters"); } if (model.Password.Length > 30) { ModelState.AddModelError("Password", "Password must be between 5 and 30 characters"); } if (!ModelState.IsValid) { model.ValidationErrors = GetValidationErrors(ModelState); return(View("~/Views/Registration/User.cshtml", model)); } UserInfoRepository repo = new UserInfoRepository(); model.Roles = JsonConvert.DeserializeObject <Role[]>(model.RoleString); repo.Save(model); return(RedirectToAction("Edit", new { id = model.Id, Message = "Your employee was successfully created." })); }
public ActionResult Update(UserInfoModel model) { ModelState["Password"].Errors.Clear(); ModelState["ConfirmPassword"].Errors.Clear(); if (!ModelState.IsValid) { model.ValidationErrors = GetValidationErrors(ModelState); return(View("~/Views/Registration/User.cshtml", model)); } UserInfoRepository repo = new UserInfoRepository(); model.Roles = JsonConvert.DeserializeObject <Role[]>(model.RoleString); repo.Save(model); return(RedirectToAction("Edit", new { id = model.Id, Message = "Your employee was successfully created." })); }