Пример #1
0
        public async Task <IActionResult> OnGetAsync([FromQuery] OffersFilterParams filterParams, bool clearFilters = false)
        {
            if (clearFilters)
            {
                FilterParamsContainer <OffersFilterParams> .Clear();
            }

            string currentUserId = HttpContext.GetCurrentUserId();

            var favoriteOffers = await(!filterParams.FilterEnabled
                ? favoritesService.GetFavoriteOffers(currentUserId)
                : 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() },
                { new OfferFavoriteSpecification(currentUserId), new OfferFavoriteFilter() }
            }));

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

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

            return(Page());
        }
Пример #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());
        }
Пример #3
0
 public async Task <IActionResult> OnPostFilterOffersAsync([Bind] OffersFilterParams filterParams, bool updateParams = true)
 => await this.OnGetAsync(FilterParamsContainer <OffersFilterParams> .Store(filterParams, updateParams : updateParams).EnableFiltering <OffersFilterParams>());