private static IPaginate <Tour> QueryForAllPlayers( ToursQuery request, IRepositoryReadOnly <Tour> toursRepo, Expression <Func <Tour, bool> > predicate) { if (request.QueryType == ToursQueryType.All) { return(toursRepo.GetList(predicate)); } //todo:: valdiate data int size = request.QueryType == ToursQueryType.Last ? (int)request.Last : 1; if (request.SeasonsId != null && request.SeasonsId.Length != 0) { var tours = new List <Tour>(); foreach (var seasonId in request.SeasonsId) { var toursPerSeason = toursRepo.GetList( predicate: t => t.SeasonId == seasonId, orderBy: q => q.OrderByDescending(t => t.Date), size: size).Items; tours.AddRange(toursPerSeason); } return(tours.ToPaginate(0, tours.Count)); } return(toursRepo.GetList( orderBy: q => q.OrderByDescending(t => t.Date), size: size)); }
private async Task <IPaginate <Tour> > FilterByPlayerIdAndIncomingStatus( ToursQuery request, IRepositoryReadOnly <Tour> toursRepo) { var leaguesId = await _leaguesService.GetPlayerJoinedLeagues(request.PlayerId); var actualSeasons = await _seasonsService.GetLeaguesSeasonsId( leaguesId, Array.Empty <int>(), LeaguesSeasonsIdQueryType.Actual); var tours = new List <Tour>(); foreach (var season in actualSeasons) { var tour = toursRepo.Single( t => t.SeasonId == season.SeasonId, q => q.OrderByDescending(t => t.Date)); if (tour != null && !tour.IsRegistrationClosed()) { tours.Add(tour); } } return(tours.ToPaginate(0, tours.Count)); }
public async Task <PagedResult <TourDto> > Handle(ToursQuery request, CancellationToken cancellationToken) { var toursRepo = _uow.GetReadOnlyRepository <Tour>(); Expression <Func <Tour, bool> > predicate = null; if (!(request.SeasonsId is null) && request.SeasonsId.Length != 0) { predicate = tour => request.SeasonsId.Contains(tour.SeasonId); } IPaginate <Tour> tours; int?count = null; if (request.PlayerId == 0) { tours = QueryForAllPlayers(request, toursRepo, predicate); } else { if (request.QueryType == ToursQueryType.Incoming) { tours = await FilterByPlayerIdAndIncomingStatus(request, toursRepo); } else { (count, tours) = await FilterByPlayerId(request, toursRepo, predicate); } } var toursDtos = new List <TourDto>(); foreach (var tour in tours.Items) { if (request.QueryType == ToursQueryType.Incoming && tour.IsEnded()) { // we want incoming tour, but this tour is ended - continue continue; } toursDtos.Add(_mapper.Map <TourDto>(tour)); } await EnrichTourDtoByLeagueId(toursDtos); if (request.QueryType == ToursQueryType.Incoming && request.PlayerId != 0) { EnrichByRegisterStatus(toursDtos, request.PlayerId); } return(PagedResult <TourDto> .Create( toursDtos, tours.Index, tours.Size, tours.Pages, count ?? tours.Count)); }
private async Task <(int, IPaginate <Tour>)> FilterByPlayerId( ToursQuery request, IRepositoryReadOnly <Tour> toursRepo, Expression <Func <Tour, bool> > predicate) { PagedResult <int> toursByPlayerIdDto = await _teamsService.GetToursByPlayerIdAsync( request.Size, request.Page, request.PlayerId); if (toursByPlayerIdDto.IsEmpty) { return(0, null); } var tourIds = toursByPlayerIdDto.Items.ToList(); predicate = predicate == null ? t => tourIds.Contains(t.Id) : predicate.AndAlso(t => tourIds.Contains(t.Id)); return((int)toursByPlayerIdDto.TotalResults, toursRepo.GetList(predicate, size: tourIds.Count)); }