public ActionResult EditUser(User updatedUser, FormCollection formCollection) { try { _membershipProviderApplicationService.UpdateUser(updatedUser, false); var updatedRoles = formCollection["Roles"].Replace("false", "").Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries); var usersRoles = _roleProviderApplicationService.GetRolesForUser(updatedUser.UserName); var rolesToRemove = usersRoles.Except(updatedRoles); foreach (var roleToRemove in rolesToRemove) { _roleProviderApplicationService.DeleteUserFromRole(updatedUser.UserName, roleToRemove); } var rolesToAdd = updatedRoles.Except(usersRoles); foreach (var roleToAdd in rolesToAdd) { _roleProviderApplicationService.AddUserToRole(updatedUser.UserName, roleToAdd); } return(RedirectToAction("Index")); } catch { return(RedirectToAction("EditUser", new { id = updatedUser.Id })); } }
/// <summary> /// Updates information about a user in the data source. /// </summary> /// <param name="user"></param> public override void UpdateUser(MembershipUser user) { ShopgunMembershipUser shopgunUser = user as ShopgunMembershipUser; _membershipProviderApplicationService.UpdateUser(shopgunUser.ToUser(), true); }