Esempio n. 1
0
        public async Task <GetOffersResponse> Handle(GetOffersRequest request, CancellationToken cancellationToken)
        {
            var offers = await offerService.GetOffers(request);

            var offersToReturn = mapper.Map <List <OfferListDto> >(offers);

            httpContextWriter.AddPagination(offers.CurrentPage, offers.PageSize, offers.TotalCount, offers.TotalPages);

            return(new GetOffersResponse {
                Offers = offersToReturn
            });
        }
Esempio n. 2
0
        public async Task <IActionResult> OnGetAsync([FromQuery] OffersFilterParams filterParams, bool clearFilters = false)
        {
            if (clearFilters)
            {
                FilterParamsContainer <OffersFilterParams> .Clear();
            }

            var offers = !filterParams.FilterEnabled
                ? await offerService.GetOffers()
                : await offersFilterService.FilterOffers(filterParams, new FiltersDictionary <Offer>
            {
                { new OfferPriceSpecification(filterParams.MinPrice, filterParams.MaxPrice), new OfferPriceFilter() },
                { new OfferLocationSpecification(filterParams.Location), new OfferLocationFilter() },
                { new OfferRoomsSpecification(filterParams.RoomsCount), new OfferRoomsFilter() },
                { new OfferPersonsSpecification(filterParams.PersonsCount), new OfferPersonsFilter() },
                { new OfferDatesSpecification(filterParams.StartDate, filterParams.EndDate), new OfferDatesFilter() }
            });

            Params = FilterParamsContainer <OffersFilterParams> .Store(filterParams, updateParams : true);

            Offers = mapper.Map <List <OfferListDto> >(offers).ToPagedList <OfferListDto>(filterParams.PageNumber, filterParams.PageSize);

            return(Page());
        }