public ActionResult AddSystemAdmin(AdministratorSetupModel model, string returnUrl) { ICardHolderService CardHolderService; // move tests here to make sure that we handle them better if ((model.Password != null) && (model.RepeatPassword != null)) { if (model.Password != model.RepeatPassword) { ModelState.AddModelError("RepeatPassword", "The password does not match."); } } if ((model.SecondPassword != null) && (model.RepeatSecondPassword != null)) { if (model.SecondPassword != model.RepeatSecondPassword) { ModelState.AddModelError("RepeatSecondPassword", "The password does not match."); } } if (String.IsNullOrEmpty(model.UserName)) { ModelState.AddModelError("UserName", "Value cannot be null or empty."); } if (String.IsNullOrEmpty(model.Password)) { ModelState.AddModelError("Password", "Value cannot be null or empty."); } if (String.IsNullOrEmpty(model.SecondPassword)) { ModelState.AddModelError("SecondPassword", "Value cannot be null or empty."); } MembershipProvider _provider = Membership.Providers["GiftUserMembershipProvider"]; if (model.UserName != null) { if (_provider.GetUserNameByEmail(model.UserName + "@system") != "") { ModelState.AddModelError("UserName", "UserName@system is already on the system"); } } if (ModelState.IsValid) { try { CardHolderService = new CardHolderService(); CardHolderService.CreateSystemAdmin(model.UserName, model.Password, model.SecondPassword); return(RedirectToAction("Index")); } catch (Exception Ex) { ModelState.AddModelError("", Common.StandardExceptionErrorMessage(Ex)); } } // If we got this far, something failed, redisplay form return(View(model)); }