public ActionResult EditResourceStructure(ResourceStructureModel model) { using (ResourceStructureManager rsManager = new ResourceStructureManager()) { //check name ResourceStructure temp = rsManager.GetResourceStructureByName(StringHelper.CutSpaces(model.Name)); if (temp != null && temp.Id != model.Id) { ModelState.AddModelError("NameExist", "Name already exist"); } ResourceStructure rs = rsManager.GetResourceStructureById(model.Id); if (rs == null) { ModelState.AddModelError("Errors", "ResourceStructure does not exist."); } if (rs.ResourceAttributeUsages.Select(a => a.ResourceStructureAttribute).ToList().Count() < 1) { ModelState.AddModelError("Errors", "Resource Structure has no attributes."); } if (rs.Parent != null) { if (rs.Parent.Id == rs.Id) { ModelState.AddModelError("Errors", "Parent resource structure can not be themselves."); } } if (ModelState.IsValid) { rs.Name = model.Name; rs.Description = model.Description; rsManager.Update(rs); return(RedirectToAction("ResourceStructure")); } else { return(View("_editResourceStructure", model)); } } }
public ActionResult Create(CreateResourceStructureModel model) { using (ResourceStructureManager rsManager = new ResourceStructureManager()) using (var pManager = new EntityPermissionManager()) using (var entityTypeManager = new EntityManager()) using (UserManager userManager = new UserManager()) { //check name ResourceStructure temp = rsManager.GetResourceStructureByName(StringHelper.CutSpaces(model.Name)); if (temp != null) { ModelState.AddModelError("NameExist", "Name already exist"); } if (ModelState.IsValid) { ResourceStructure rS = rsManager.Create(model.Name, model.Description, null, null); //Start -> add security ---------------------------------------- var userTask = userManager.FindByNameAsync(HttpContext.User.Identity.Name); userTask.Wait(); var user = userTask.Result; Entity entityType = entityTypeManager.FindByName("ResourceStructure"); //31 is the sum from all rights: Read = 1, Write = 4, Delete = 8, Grant = 16 int rights = (int)RightType.Read + (int)RightType.Write + (int)RightType.Delete + (int)RightType.Grant; pManager.Create(user, entityType, rS.Id, rights); //End -> add security ------------------------------------------ ResourceStructureModel rSmodel = new ResourceStructureModel(rS); rSmodel.FirstCreated = true; return(View("_editResourceStructure", rSmodel)); } else { return(View("_createResourceStructure", model)); } } }