예제 #1
0
        public static GetOffersResult GetOffers(GetOffersByFiltersParameters parameters)
        {
            var url   = $"{SchemeAndHost}/api/offers/get-offers";
            var jData = JsonConvert.SerializeObject(parameters);

            return(ApiProvider.ExecutePostSync <GetOffersResult>(url, jData));
        }
예제 #2
0
        public GetOffersResult GetOffers(GetOffersByFiltersParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var filter       = parameters.Filter;
            var pagingFilter = parameters.PagingFilter;

            var context = new BloodSearchContext();

            var query = filter.Type == OfferTypeEnum.Any ?
                        context.Offers :
                        context.Offers.Where(x => x.Type == filter.Type);

            var items = query.Where(x => filter.Statuses.Any(z => z == x.State)).ToList();

            var totalOffers = items.Select(ConvertOffer);

            if (filter.Categories.Any())
            {
                totalOffers = totalOffers.Where(x => filter.Categories.FirstOrDefault() == x.Offer.Category);
            }

            if (filter.RegionId.HasValue)
            {
                totalOffers = totalOffers.Where(x => filter.RegionId.Value == x.Offer.GeoAddress.Id);
            }

            if (filter.Statuses.Any())
            {
                totalOffers = totalOffers.Where(x => filter.Statuses.Any(z => z == x.State));
            }

            var totalCount = totalOffers.Count();

            var offers = totalOffers.OrderBy(x => x.Id)
                         .Skip((pagingFilter.PageNumber - 1) * pagingFilter.PageSize)
                         .Take(pagingFilter.PageSize)
                         .ToList();

            return(new GetOffersResult {
                Offers = offers,
                TotalCount = totalCount
            });
        }