public ActionResult Update(UserAdminUpdate value) { if (value == null) { throw new ArgumentNullException("value"); } var user = this.UserService.GetById(value.Id); if (user == null) { return HttpNotFound(); } var privilege = new UserPrivilege(); if (!privilege.CanUpdateAny(user)) { return NotAuthorized(); } value.Validate(); if (value.IsValid) { // value to user value.ValueToModel(user); // update user this.UserService.Update(user); // update password if needed if (!string.IsNullOrEmpty(value.Password)) { this.AuthenticationService.Update(user, value.Password); } // preference var preference = user.Preference; // value to preference value.ValueToPreference(preference); // update user preference this.UserService.UpdatePreference(preference); value.SuccessMessage(Messages.UserUpdated.FormatInvariant(user.Name)); } else { value.CopyToModel(ModelState); } return base.View(Views.Update, value); }
public ActionResult Update(int id) { var user = this.UserService.GetById(id); if (user == null) { return HttpNotFound(); } var privilege = new UserPrivilege(); return privilege.CanUpdateAny(user) ? View(Views.Update, new UserAdminUpdate(user)) : NotAuthorized(); }
public ActionResult Reset(UserAuthenticationReset value) { if (value == null) { throw new ArgumentNullException("value"); } var user = this.UserService.GetById(value.Id); if (user == null) { return HttpNotFound(); } var privilege = new UserPrivilege(); if (!privilege.CanUpdateAny(user)) { return NotAuthorized(); } value.Validate(); if (value.IsValid) { this.AuthenticationService.Reset(user); var model = new UserAdminUpdate(user); model.SuccessMessage(Messages.UserPasswordReset.FormatInvariant(user.Name)); return base.View(Views.Update, model); } value.CopyToModel(ModelState); value.Initialize(user); return base.View(Views.Reset, value); }
public ActionResult Reset(int id) { var user = this.UserService.GetById(id); if (user == null) { return HttpNotFound(); } var privilege = new UserPrivilege(); if (!privilege.CanUpdateAny(user)) { return NotAuthorized(); } var value = new UserAuthenticationReset(); value.Initialize(user); return View(Views.Reset, value); }
public ActionResult Privilege(UserRolePrivilegeUpdate value) { var user = this.UserService.GetById(value.UserId); if (user == null) { return base.HttpNotFound(); } var privilege = new UserPrivilege(); if (!privilege.CanUpdateAny(user)) { return NotAuthorized(); } this.UserRoleService.UpdatePrivileges(user, value.Values); value.SuccessMessage(Messages.UserPrivilegeUpdated.FormatInvariant(user.Name)); var roles = this.UserRoleService.GetAll(); var privileges = this.UserRoleService.GetPrivileges(new UserRoleRelationUserSpecification(user.Id)); value.Initialize(user, roles, privileges); value.SuccessMessage(Messages.UserPrivilegeUpdated.FormatInvariant(user.Name)); return base.View(Views.Privilege, value); }
public ActionResult Privilege(int id) { var user = this.UserService.GetById(id); if (user == null) { return base.HttpNotFound(); } var privilege = new UserPrivilege(); if (!privilege.CanUpdateAny(user)) { return NotAuthorized(); } var roles = this.UserRoleService.GetAll(); var privileges = this.UserRoleService.GetPrivileges(new UserRoleRelationUserSpecification(user.Id)); var value = new UserRolePrivilegeUpdate(); value.Initialize(user, roles, privileges); return base.View(Views.Privilege, value); }