public RoleView Create(long structure, string containerPrototype, string workspaceType, string roleType, string rule) { var containerPrototypeObj = ContainerPrototypeManager.Get(_dbContext, structure, containerPrototype); if (containerPrototypeObj == null) throw new ArgumentException("\"containerPrototype\" or \"structure\" is a invalid argument"); var workspaceTypeObj = WorkSpaceTypeManager.Get(_dbContext, structure, workspaceType); if (workspaceTypeObj == null) throw new ArgumentException("\"workspaceType\" or \"structure\" is a invalid argument"); var roleTypeObj = RoleTypeManager.Get(_dbContext, structure, roleType); if (roleTypeObj == null) throw new ArgumentException("\"roleType\" or \"structure\" is a invalid argument"); var ruleObj = RuleManager.Get(_dbContext, structure, rule); if (ruleObj == null) throw new ArgumentException("\"rule\" or \"structure\" is a invalid argument"); var role = new Role() { RoleType = roleTypeObj, ContainerPrototype = containerPrototypeObj, WorkSpaceType = workspaceTypeObj, RoleTypeStructureId = structure, Rule = ruleObj }; _dbContext.Roles.Add(role); _dbContext.SaveChanges(); return role.Convert(); }
public Role Create(long structure, string containerPrototype, string workspaceType, string roleType, IEnumerable<string> rules = null, RoleBarrier roleBarrier = RoleBarrier.None) { var role = new Role() { RoleTypeName = roleType, StructureId = structure, ContainerTypeName = containerPrototype, WorkSpaceTypeName = workspaceType, RoleBarrier = roleBarrier }; if (rules != null) foreach(var r in rules.Select(e => _dbManager.Rule.Get(structure, e))) role.Rules.Add(r); _dbManager.DbContext.Roles.Add(role); _dbManager.DbContext.SaveChanges(); return role; }