Exemplo n.º 1
0
        public static IEnumerable <Role> ApplyQuery(this IEnumerable <Role> query, RoleQueryParams queryParams, bool usePaging = true)
        {
            if (queryParams.Id.HasValue)
            {
                query = query.Where(x => x.Id == queryParams.Id.Value);
            }

            return(query.ApplyBaseQuery(queryParams));
        }
        public RolesWithFilterForCountSpecificatipon(RoleQueryParams queryParams)
            : base(x =>
                   (string.IsNullOrEmpty(queryParams.Search) ||
                    x.Name.ToLower().Contains(queryParams.Search) ||
                    x.RoleCategory.Name.ToLower().Contains(queryParams.Search) ||
                    x.Description.ToLower().Contains(queryParams.Search)
                   ) &&
                   (!queryParams.RoleCategoryId.HasValue || x.RoleCategoryId == queryParams.RoleCategoryId)

                   )
        {
        }
        public RolesWithRoleCategorySpecification(RoleQueryParams queryParams)
            : base(x =>
                   (string.IsNullOrEmpty(queryParams.Search) ||
                    x.Name.ToLower().Contains(queryParams.Search) ||
                    x.RoleCategory.Name.ToLower().Contains(queryParams.Search) ||
                    x.Description.ToLower().Contains(queryParams.Search)
                   ) &&
                   (!queryParams.RoleCategoryId.HasValue || x.RoleCategoryId == queryParams.RoleCategoryId)

                   )
        {
            AddInclude(x => x.RoleCategory);
            ApplyPaging(queryParams.PageSize * (queryParams.PageIndex - 1), queryParams.PageSize);
        }
Exemplo n.º 4
0
        //[SecuredOperation("Sudo,Roles.List,Roles.All", Priority = 1)]
        public async Task <Pagination <RoleForListDto> > GetRolesAsync(RoleQueryParams queryParams)
        {
            var spec  = new RolesWithRoleCategorySpecification(queryParams);
            var roles = await roleDal.ListEntityWithSpecAsync(spec);

            var countSpec  = new RolesWithFilterForCountSpecificatipon(queryParams);
            var totalItems = await roleDal.CountAsync(countSpec);

            if (roles == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { RolesListNotFound = Messages.RoleListNotFound });
            }
            ;

            var data = mapper.Map <List <Role>, List <RoleForListDto> >(roles);

            return(new Pagination <RoleForListDto>
                   (
                       queryParams.PageIndex,
                       queryParams.PageSize,
                       totalItems,
                       data
                   ));
        }
Exemplo n.º 5
0
 public async Task <ActionResult <Pagination <RoleForListDto> > > List([FromQuery] RoleQueryParams queryParams)
 {
     return(await roleService.GetRolesAsync(queryParams));
 }