Пример #1
0
        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));
        }
Пример #2
0
        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));
        }