Beispiel #1
0
        public ActionResult GetPlistAccountRoles(GetPlistAccountRoles requestData)
        {
            if (!ModelState.IsValid)
            {
                return(ModelState.ToJsonResult());
            }
            var data          = new List <AccountAssignRoleTr>();
            var privilegeType = AcElementType.Role.ToName();
            var accountRoles  = GetRequiredService <IRepository <Privilege> >().AsQueryable().Where(a => a.SubjectInstanceId == requestData.AccountId && a.ObjectType == privilegeType);

            if (requestData.IsAssigned.HasValue)
            {
                if (requestData.IsAssigned.Value)
                {
                    foreach (var ar in accountRoles)
                    {
                        RoleState role;
                        if (!AcDomain.RoleSet.TryGetRole(ar.ObjectInstanceId, out role))
                        {
                            throw new AnycmdException("意外的角色标识" + ar.ObjectInstanceId);
                        }
                        data.Add(new AccountAssignRoleTr
                        {
                            AccountId    = requestData.AccountId,
                            IsAssigned   = true,
                            RoleId       = ar.ObjectInstanceId,
                            CreateBy     = ar.CreateBy,
                            CreateOn     = ar.CreateOn,
                            CreateUserId = ar.CreateUserId,
                            Id           = ar.Id,
                            IsEnabled    = role.IsEnabled,
                            CategoryCode = role.CategoryCode,
                            Name         = role.Name,
                            SortCode     = role.SortCode,
                            Icon         = role.Icon
                        });
                    }
                }
                else
                {
                    foreach (var role in AcDomain.RoleSet)
                    {
                        if (!accountRoles.Any(a => a.ObjectInstanceId == role.Id))
                        {
                            data.Add(new AccountAssignRoleTr
                            {
                                AccountId    = requestData.AccountId,
                                IsAssigned   = false,
                                RoleId       = role.Id,
                                CreateBy     = null,
                                CreateOn     = null,
                                CreateUserId = null,
                                Id           = Guid.NewGuid(),
                                IsEnabled    = role.IsEnabled,
                                CategoryCode = role.CategoryCode,
                                Name         = role.Name,
                                SortCode     = role.SortCode,
                                Icon         = role.Icon
                            });
                        }
                    }
                }
            }
            else
            {
                foreach (var role in AcDomain.RoleSet)
                {
                    var ar = accountRoles.FirstOrDefault(a => a.ObjectInstanceId == role.Id);
                    if (ar == null)
                    {
                        data.Add(new AccountAssignRoleTr
                        {
                            AccountId    = requestData.AccountId,
                            IsAssigned   = false,
                            RoleId       = role.Id,
                            CreateBy     = null,
                            CreateOn     = null,
                            CreateUserId = null,
                            Id           = Guid.NewGuid(),
                            IsEnabled    = role.IsEnabled,
                            CategoryCode = role.CategoryCode,
                            Name         = role.Name,
                            SortCode     = role.SortCode,
                            Icon         = role.Icon
                        });
                    }
                    else
                    {
                        data.Add(new AccountAssignRoleTr
                        {
                            AccountId    = requestData.AccountId,
                            IsAssigned   = true,
                            RoleId       = ar.ObjectInstanceId,
                            CreateBy     = ar.CreateBy,
                            CreateOn     = ar.CreateOn,
                            CreateUserId = ar.CreateUserId,
                            Id           = ar.Id,
                            IsEnabled    = role.IsEnabled,
                            CategoryCode = role.CategoryCode,
                            Name         = role.Name,
                            SortCode     = role.SortCode,
                            Icon         = role.Icon
                        });
                    }
                }
            }
            int pageIndex = requestData.PageIndex;
            int 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 <AccountAssignRoleTr> {
                total = queryable.Count(), data = list
            }));
        }
Beispiel #2
0
        public ActionResult GetPlistAccountRoles(GetPlistAccountRoles requestData)
        {
            if (!ModelState.IsValid)
            {
                return ModelState.ToJsonResult();
            }
            var data = new List<AccountAssignRoleTr>();
            var privilegeType = AcElementType.Role.ToName();
            var accountRoles = GetRequiredService<IRepository<Privilege>>().AsQueryable().Where(a => a.SubjectInstanceId == requestData.AccountId && a.ObjectType == privilegeType);
            if (requestData.IsAssigned.HasValue)
            {
                if (requestData.IsAssigned.Value)
                {
                    foreach (var ar in accountRoles)
                    {
                        RoleState role;
                        if (!AcDomain.RoleSet.TryGetRole(ar.ObjectInstanceId, out role))
                        {
                            throw new AnycmdException("意外的角色标识" + ar.ObjectInstanceId);
                        }
                        data.Add(new AccountAssignRoleTr
                        {
                            AccountId = requestData.AccountId,
                            IsAssigned = true,
                            RoleId = ar.ObjectInstanceId,
                            CreateBy = ar.CreateBy,
                            CreateOn = ar.CreateOn,
                            CreateUserId = ar.CreateUserId,
                            Id = ar.Id,
                            IsEnabled = role.IsEnabled,
                            CategoryCode = role.CategoryCode,
                            Name = role.Name,
                            SortCode = role.SortCode,
                            Icon = role.Icon
                        });
                    }
                }
                else
                {
                    foreach (var role in AcDomain.RoleSet)
                    {
                        if (!accountRoles.Any(a => a.ObjectInstanceId == role.Id))
                        {
                            data.Add(new AccountAssignRoleTr
                            {
                                AccountId = requestData.AccountId,
                                IsAssigned = false,
                                RoleId = role.Id,
                                CreateBy = null,
                                CreateOn = null,
                                CreateUserId = null,
                                Id = Guid.NewGuid(),
                                IsEnabled = role.IsEnabled,
                                CategoryCode = role.CategoryCode,
                                Name = role.Name,
                                SortCode = role.SortCode,
                                Icon = role.Icon
                            });
                        }
                    }
                }
            }
            else
            {
                foreach (var role in AcDomain.RoleSet)
                {
                    var ar = accountRoles.FirstOrDefault(a => a.ObjectInstanceId == role.Id);
                    if (ar == null)
                    {
                        data.Add(new AccountAssignRoleTr
                        {
                            AccountId = requestData.AccountId,
                            IsAssigned = false,
                            RoleId = role.Id,
                            CreateBy = null,
                            CreateOn = null,
                            CreateUserId = null,
                            Id = Guid.NewGuid(),
                            IsEnabled = role.IsEnabled,
                            CategoryCode = role.CategoryCode,
                            Name = role.Name,
                            SortCode = role.SortCode,
                            Icon = role.Icon
                        });
                    }
                    else
                    {
                        data.Add(new AccountAssignRoleTr
                        {
                            AccountId = requestData.AccountId,
                            IsAssigned = true,
                            RoleId = ar.ObjectInstanceId,
                            CreateBy = ar.CreateBy,
                            CreateOn = ar.CreateOn,
                            CreateUserId = ar.CreateUserId,
                            Id = ar.Id,
                            IsEnabled = role.IsEnabled,
                            CategoryCode = role.CategoryCode,
                            Name = role.Name,
                            SortCode = role.SortCode,
                            Icon = role.Icon
                        });
                    }
                }
            }
            int pageIndex = requestData.PageIndex;
            int 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<AccountAssignRoleTr> { total = queryable.Count(), data = list });
        }