コード例 #1
0
        public async Task <int> CountAllAsync(
            PaginationFilter pagination,
            GetAllUserFilter filter = null
            )
        {
            var queryable = _context.Users.AsQueryable();

            queryable = queryable.Where(x => x.IsDeleted == false);
            queryable = AddFilterOnQuery(filter, queryable);
            return(await queryable.CountAsync());
        }
コード例 #2
0
        public async Task <IEnumerable <User> > GetAllAsync(
            PaginationFilter pagination,
            GetAllUserFilter filter = null)
        {
            var queryable = _context.Users.AsQueryable();

            queryable = AddFilterOnQuery(filter, queryable);

            var skip = (pagination.PageNumber - 1) * pagination.PageSize;

            return(await queryable
                   .Skip(skip)
                   .Include(u => u.Admin)
                   .Include(u => u.Customer)
                   .Include(u => u.StorageManager)
                   .Take(pagination.PageSize)
                   .ToListAsync());
        }
コード例 #3
0
        private IQueryable <User> AddFilterOnQuery(
            GetAllUserFilter filter,
            IQueryable <User> queryable
            )
        {
            queryable = queryable.Where(x => x.IsDeleted == false);

            if (!string.IsNullOrEmpty(filter?.Email))
            {
                queryable = queryable.Where(x => x.Email.Contains(filter.Email));
            }

            if (filter?.Status > 0)
            {
                queryable = queryable.Where(x => x.Status == filter.Status);
            }

            if (filter?.RoleId > 0)
            {
                queryable = queryable.Where(x => x.RoleId == filter.RoleId);
            }

            return(queryable);
        }