/// <summary> /// Create new AccountModel according to Admin instance and /// information indicating whether given admin is current active one. /// </summary> /// <param name="admin"> /// Admin instance to be modeled. /// </param> /// <param name="isActiveAdmin"> /// Indicates whether given admin is current active admin of system. /// </param> public AccountModel(Admin admin, bool isActiveAdmin) { this.Id = admin.Id; this.Username = admin.Username; this.ProfileModel = new AdminProfileModel(admin.Profile); this.IsActiveAdmin = isActiveAdmin; }
public ActionResult Edit(AccountModel model, String returnUrl) { if (ModelState.IsValid) { Admin currentAdmin = new Admin { Username = User.Identity.Name }; model.ProfileModel.UpdateAdminProfile(currentAdmin.Profile); RepositoryFactory.AdminsRepository.UpdateAdmin(currentAdmin); if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } return RedirectToAction("Details"); } return View(model); }
public ActionResult Create(AccountModel model) { if (ModelState.IsValid) { bool createdSuccessfully; try { WebSecurity.CreateUserAndAccount(model.Username, model.NewPassword); createdSuccessfully = true; } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); createdSuccessfully = false; } if (createdSuccessfully) { Admin adminToUpdate = new Admin { Username = model.Username }; model.ProfileModel.UpdateAdminProfile(adminToUpdate.Profile); RepositoryFactory.AdminsRepository.UpdateAdmin(adminToUpdate); return RedirectToAction("AllAccounts"); } } return View(model); }