public ActionResult Edit(GroupEditModel model) { if (ModelState.IsValid) { SubjectManager subjectManager = new SubjectManager(); Group group = subjectManager.GetGroupById(model.GroupId); group.Name = model.GroupName; group.Description = model.Description; long[] users = group.Users.Select(g => g.Id).ToArray(); foreach (long userId in users) { subjectManager.RemoveUserFromGroup(userId, group.Id); } if (Session["Users"] != null) { foreach (GroupMembershipGridRowModel user in (GroupMembershipGridRowModel[]) Session["Users"]) { if (user.IsUserInGroup) { subjectManager.AddUserToGroup(user.Id, group.Id); } } } subjectManager.UpdateGroup(group); return Json(new { success = true }); } else { return PartialView("_EditPartial", model); } }
public ActionResult Edit(UserEditModel model) { if (ModelState.IsValid) { SubjectManager subjectManager = new SubjectManager(); User user = subjectManager.GetUserById(model.UserId); if (model.Password == model.ConfirmPassword && model.Password != null) { subjectManager.ChangePassword(user.Id, model.Password); } user.FullName = model.FullName; user.Email = model.Email; user.IsApproved = model.IsApproved; user.IsBlocked = model.IsBlocked; user.IsLockedOut = model.IsLockedOut; // removing long[] groups = user.Groups.Select(g => g.Id).ToArray(); foreach (long groupId in groups) { subjectManager.RemoveUserFromGroup(user.Id, groupId); } //adding if (Session["Groups"] != null) { foreach (UserMembershipGridRowModel group in (UserMembershipGridRowModel[]) Session["Groups"]) { if (group.IsUserInGroup) { subjectManager.AddUserToGroup(user.Id, group.Id); } } } subjectManager.UpdateUser(user); return Json(new { success = true }); } else { return PartialView("_EditPartial", model); } }