public ActionResult Create(RegisterAdminUserViewModel model) { if (ModelState.IsValid) { AdminUser user = (AdminUser)model.GetUser(); user.IsCustomerAdmin = false; user.UserName = model.Email; try { var result = userManager.Create(user, model.Password); if (result.Succeeded) { SetRoles(user.Id); SetRoleSuperAdmin(user.Id, model.IsSuperAdmin); return(RedirectToAction("Index", "AdminUser")); } else { var errors = string.Join(",", result.Errors); ModelState.AddModelError(string.Empty, errors); } } catch (DbEntityValidationException e) { var errors = string.Join("; ", e.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage)); ModelState.AddModelError(string.Empty, errors); } catch (Exception e) { ModelState.AddModelError("", e); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Create() { RegisterAdminUserViewModel model = new RegisterAdminUserViewModel(); return(View(model)); }