public ActionResult GetPlistSsdSetRoles(GetPlistSsdSetRoles requestData) { if (!ModelState.IsValid) { return(ModelState.ToJsonResult()); } SsdSetState ssdSet; if (!AcDomain.SsdSetSet.TryGetSsdSet(requestData.SsdSetId, out ssdSet)) { throw new ValidationException("非法的静态职责分离角色集标识" + requestData.SsdSetId); } var data = new List <SsdSetAssignRoleTr>(); var ssdSetRoles = AcDomain.SsdSetSet.GetSsdRoles(ssdSet); if (requestData.IsAssigned.HasValue) { if (requestData.IsAssigned.Value) { data.AddRange(from ssdSetRole in ssdSetRoles let role = AcDomain.RoleSet.GetRole(ssdSetRole.RoleId) select new SsdSetAssignRoleTr { Id = ssdSetRole.Id, SsdSetId = requestData.SsdSetId, IsAssigned = requestData.IsAssigned.Value, RoleId = ssdSetRole.RoleId, IsEnabled = role.IsEnabled, CategoryCode = role.CategoryCode, Name = role.Name, SortCode = role.SortCode, Icon = role.Icon, CreateOn = ssdSetRole.CreateOn }); } else { data.AddRange(from role in AcDomain.RoleSet where ssdSetRoles.All(a => a.RoleId != role.Id) select new SsdSetAssignRoleTr { Id = Guid.NewGuid(), SsdSetId = requestData.SsdSetId, IsAssigned = requestData.IsAssigned.Value, RoleId = role.Id, CreateOn = null, IsEnabled = role.IsEnabled, CategoryCode = role.CategoryCode, Name = role.Name, SortCode = role.SortCode, Icon = role.Icon }); } } else { foreach (var role in AcDomain.RoleSet) { var ssdRole = ssdSetRoles.FirstOrDefault(a => a.RoleId == role.Id); if (ssdRole == null) { data.Add(new SsdSetAssignRoleTr { Id = Guid.NewGuid(), SsdSetId = requestData.SsdSetId, IsAssigned = false, RoleId = role.Id, CreateOn = null, IsEnabled = role.IsEnabled, CategoryCode = role.CategoryCode, Name = role.Name, SortCode = role.SortCode, Icon = role.Icon }); } else { data.Add(new SsdSetAssignRoleTr { Id = ssdRole.Id, SsdSetId = requestData.SsdSetId, IsAssigned = true, RoleId = ssdRole.RoleId, CreateOn = ssdRole.CreateOn, IsEnabled = role.IsEnabled, CategoryCode = role.CategoryCode, Name = role.Name, SortCode = role.SortCode, Icon = role.Icon }); } } } var pageIndex = requestData.PageIndex; var pageSize = requestData.PageSize; var queryable = data.AsQueryable(); if (!string.IsNullOrEmpty(requestData.Key)) { queryable = queryable.Where(a => a.Name.Contains(requestData.Key) || a.CategoryCode.Contains(requestData.Key)); } var list = queryable.OrderBy(requestData.SortField + " " + requestData.SortOrder).Skip(pageIndex * pageSize).Take(pageSize); return(this.JsonResult(new MiniGrid <SsdSetAssignRoleTr> { total = queryable.Count(), data = list })); }
public ActionResult GetPlistSsdSetRoles(GetPlistSsdSetRoles requestData) { if (!ModelState.IsValid) { return ModelState.ToJsonResult(); } SsdSetState ssdSet; if (!AcDomain.SsdSetSet.TryGetSsdSet(requestData.SsdSetId, out ssdSet)) { throw new ValidationException("非法的静态职责分离角色集标识" + requestData.SsdSetId); } var data = new List<SsdSetAssignRoleTr>(); var ssdSetRoles = AcDomain.SsdSetSet.GetSsdRoles(ssdSet); if (requestData.IsAssigned.HasValue) { if (requestData.IsAssigned.Value) { data.AddRange(from ssdSetRole in ssdSetRoles let role = AcDomain.RoleSet.GetRole(ssdSetRole.RoleId) select new SsdSetAssignRoleTr { Id = ssdSetRole.Id, SsdSetId = requestData.SsdSetId, IsAssigned = requestData.IsAssigned.Value, RoleId = ssdSetRole.RoleId, IsEnabled = role.IsEnabled, CategoryCode = role.CategoryCode, Name = role.Name, SortCode = role.SortCode, Icon = role.Icon, CreateOn = ssdSetRole.CreateOn }); } else { data.AddRange(from role in AcDomain.RoleSet where ssdSetRoles.All(a => a.RoleId != role.Id) select new SsdSetAssignRoleTr { Id = Guid.NewGuid(), SsdSetId = requestData.SsdSetId, IsAssigned = requestData.IsAssigned.Value, RoleId = role.Id, CreateOn = null, IsEnabled = role.IsEnabled, CategoryCode = role.CategoryCode, Name = role.Name, SortCode = role.SortCode, Icon = role.Icon }); } } else { foreach (var role in AcDomain.RoleSet) { var ssdRole = ssdSetRoles.FirstOrDefault(a => a.RoleId == role.Id); if (ssdRole == null) { data.Add(new SsdSetAssignRoleTr { Id = Guid.NewGuid(), SsdSetId = requestData.SsdSetId, IsAssigned = false, RoleId = role.Id, CreateOn = null, IsEnabled = role.IsEnabled, CategoryCode = role.CategoryCode, Name = role.Name, SortCode = role.SortCode, Icon = role.Icon }); } else { data.Add(new SsdSetAssignRoleTr { Id = ssdRole.Id, SsdSetId = requestData.SsdSetId, IsAssigned = true, RoleId = ssdRole.RoleId, CreateOn = ssdRole.CreateOn, IsEnabled = role.IsEnabled, CategoryCode = role.CategoryCode, Name = role.Name, SortCode = role.SortCode, Icon = role.Icon }); } } } var pageIndex = requestData.PageIndex; var pageSize = requestData.PageSize; var queryable = data.AsQueryable(); if (!string.IsNullOrEmpty(requestData.Key)) { queryable = queryable.Where(a => a.Name.Contains(requestData.Key) || a.CategoryCode.Contains(requestData.Key)); } var list = queryable.OrderBy(requestData.SortField + " " + requestData.SortOrder).Skip(pageIndex * pageSize).Take(pageSize); return this.JsonResult(new MiniGrid<SsdSetAssignRoleTr> { total = queryable.Count(), data = list }); }