public ActionResult BulkUpdate(BulkUpdateModel model, string submitButton) { //check the other submit buttons and act on them, or continue switch (submitButton) { case "Cancel": return(RedirectToAction("Index", "Users")); } //case "Save": if (ModelState.IsValid) { var changeType = ChangeType.Status; if (Session["__SavedChangeType"] != null) { changeType = Session["__SavedChangeType"] is ChangeType ? (ChangeType)Session["__SavedChangeType"] : ChangeType.Status; //clear the session } try { //get the users to act on var usrMgr = new UserFactory(); //determine the action if (changeType == ChangeType.Status) { //if status, update status for those users bool active = model.Action == "Active"; foreach (var userName in GetActionableUsernames()) { usrMgr.UpdateUserStatus(userName, active); } } else { //if roles, update roles for those users - role is the current action var roleName = model.Action; //clear all first, then update foreach (var userName in GetActionableUsernames()) { //clear all their group permissions CurrentAuthorizationManager.RemoveMemberGroups(userName); // now add them to the specific group for this store they will have access to CurrentAuthorizationManager.AddGroupMember(roleName, userName); } } // send them back to the user listing page. return(RedirectToAction("Index", "Users")); } catch (Exception e) { ModelState.AddModelError("", "Could not update users profile."); } } // If we got this far, something failed, redisplay form model.Groups = GetGroups(); return(View(model)); }
public new ActionResult Edit(ProfileModel model, string submitButton, string password, string status, FormCollection formColl) { // Rebind model since locale of thread has been set since original binding of model by MVC if (TryUpdateModel(model, formColl.ToValueProvider())) { UpdateModel(model, formColl.ToValueProvider()); } // Revalidate model after rebind. ModelState.Clear(); TryValidateModel(model); //we dont care about the validation for questions and answers, so remove them from the model state ModelState.Remove("Question1.Question"); ModelState.Remove("Question1.Answer"); ModelState.Remove("Question2.Question"); ModelState.Remove("Question2.Answer"); //check the other submit buttons and act on them, or continue switch (submitButton) { case "Change Password": return(ResetPassword(model)); case "Clear Password History": return(ClearPasswordHistory(model)); case "Unlock User": return(UnlockUser(model)); //check the other submit buttons and act on them, or continue case "Cancel": return(RedirectToAction("Index", "Users")); case "Customer Roles": return(RedirectToAction("CustomerRoles", "Users", new { username = model.Username })); } //case "Save": ModelState.Remove("Password.NewPassword"); if (ModelState.IsValid) { try { var usrMgr = new UserFactory(); // update the users profile bool active = status == "Active"; usrMgr.UpdateUserProfile(model, active); //now we have to check to see if they are a technician. if they are, create a technician in the pems db var settingsFactory = new SettingsFactory(); int userId = usrMgr.GetUserId(model.Username); settingsFactory.Set(userId, Constants.User.IsTechnician, model.IsTechnician.ToString()); (new TechnicianFactory()).SetTechnician(model, CurrentCity); //clear all their group permissions CurrentAuthorizationManager.RemoveMemberGroups(model.Username); // now add them to the specific group for this store they will have access to CurrentAuthorizationManager.AddGroupMember(model.Role, model.Username); // send them back to the user listing page. return(RedirectToAction("Index", "Users")); } catch (Exception e) { ModelState.AddModelError("", "Could not update users profile."); } } // If we got this far, something failed, redisplay form model.Groups = GetGroups(model.Username); return(View(model)); }
/// <summary> /// Creates a group for a store by store name /// </summary> /// <param name="storeName"></param> /// <param name="groupName"></param> /// <param name="groupDescription"></param> /// <returns></returns> public ActionResult CreateStoreGroup(string storeName, string groupName, string groupDescription) { CurrentAuthorizationManager.CreateGroup(groupName, groupDescription); return(View()); }