public ActionResult Create(RoleAdminModel model) { if (!ModelState.IsValid) { TempData["ModelErrors"] = FindModelErrors(); TempData["RoleAdminModel"] = model; return RedirectToAction("New"); } using (new UnitOfWorkScope()) { var organization = OrganizationRepository.GetDefaultOrganization(readOnly: false); // All roles that are created outside of the db install script are not System Roles var role = new Role { Name = model.Name, Description = model.Description, IsSystemRole = false }; organization.Roles.Add(role); roleRepository.Save(); TempData["UserFeedback"] = string.Format("'{0}' was created successfully", role.Name); return RedirectToAction("List", new { id = role.RoleID }); } }
public ActionResult Update(RoleAdminModel model) { if (!ModelState.IsValid) { TempData["ModelErrors"] = FindModelErrors(); TempData["RoleAdminModel"] = model; return RedirectToAction("Admin", new { id = model.RoleID }); } using (roleRepository) { var role = roleRepository.GetRoleByID(model.RoleID); if (role == null) { return HttpNotFound("The role you are looking for could not be found."); } // If role is a "System Role" we don't want anybody editing or deleting it. if (role.IsSystemRole) { return new HttpStatusCodeResult(403, "You do not have permission to edit this security role."); } MapRole(model, role); roleRepository.Save(); TempData["UserFeedback"] = string.Format("'{0}' was updated successfully.", role.Name); } return RedirectToAction("List"); }
private static void MapRole(RoleAdminModel model, Role role) { role.Name = model.Name; role.Description = model.Description; }
public void Update_Should_Update_Role_Properties_When_Successful() { var role = EntityHelpers.GetValidRole(); roleRepository.Add(role); var id = role.RoleID; var model = new RoleAdminModel { RoleID = id, Name = "New Role", Description = "Some description" }; controller.Update(model); role = roleRepository.GetRoleByID(id); Assert.AreEqual(model.Name, role.Name); Assert.AreEqual(model.Description, role.Description); }