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()); }
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()); }
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); }