public async Task <IPagingModelResponse <TeamListItemDto> > GetTeamsAsync(int pageSize = 0, int pageNumber = 0) { Logger?.LogInformation($"{nameof(GetTeamsAsync)} has been invoked"); var response = new PagingModelResponse <TeamListItemDto>(); try { response.PageSize = pageSize; response.PageNumber = pageNumber; var query = TeamRepository.GetItems() .OrderByDescending(entity => entity.CreationDateTime) .AsNoTracking(); response.ItemCount = await query.CountAsync(); query = query.Paging(pageSize, pageNumber); response.Model = await query.ProjectTo <TeamListItemDto>().ToListAsync(); } catch (Exception ex) { response.SetError(ex, Logger); } return(response); }
public async Task <IPagingModelResponse <MatchListItemDto> > GetMatchesAsync( int pageSize = 0, int pageNumber = 0, int?leagueId = null, int?teamId = null, DateTime?startDate = null, DateTime?endDate = null) { Logger?.LogInformation($"{nameof(GetMatchesAsync)} has been invoked"); var response = new PagingModelResponse <MatchListItemDto>(); try { response.PageSize = pageSize; response.PageNumber = pageNumber; var query = MatchRepository.GetItems(); // - Filters - if (leagueId.HasValue) { query = query.Where(match => match.LeagueId == leagueId); } if (teamId.HasValue) { query = query.Where(match => match.Team1Id == teamId || match.Team2Id == teamId); } if (startDate.HasValue) { query = query.Where(match => match.Date >= startDate); } if (endDate.HasValue) { query = query.Where(match => match.Date <= endDate); } // - Ordering - query = query.OrderBy(match => match.Date).AsNoTracking(); // - Paging - response.ItemCount = await query.CountAsync(); query = query.Paging(pageSize, pageNumber); response.Model = await query.ProjectTo <MatchListItemDto>().ToListAsync(); } catch (Exception ex) { response.SetError(ex, Logger); } return(response); }
public async Task <IPagingModelResponse <OrderInfo> > GetOrdersAsync(Int32 pageSize, Int32 pageNumber, Int32?customerID = null, Int32?employeeID = null, Int32?shipperID = null) { Logger?.LogInformation("{0} has been invoked", nameof(GetOrdersAsync)); var response = new PagingModelResponse <OrderInfo>(); try { response.PageSize = pageSize; response.PageNumber = pageNumber; var query = SalesRepository.GetOrders(pageSize, pageNumber, customerID, employeeID, shipperID); response.ItemCount = await query.CountAsync(); response.Model = await query.Paging(pageSize, pageNumber).ToListAsync(); } catch (Exception ex) { response.SetError(ex, Logger); } return(response); }