Esempio n. 1
0
        public async Task <IEnumerable> GetListings(ListingsFilters filters)
        {
            if (filters == null)
            {
                return(await _context.SummaryListings.Join(_context.Listings, sL => sL.Id, l => l.Id, (sl, l) => new { sl, l })
                       .Select(i => new SummaryListings
                {
                    Id = i.sl.Id,
                    Name = i.sl.Name,
                    Longitude = i.sl.Longitude,
                    Latitude = i.sl.Latitude,
                    HostName = i.sl.HostName,
                    Neighbourhood = i.sl.Neighbourhood,
                    Price = i.sl.Price,
                    Rating = i.l.ReviewScoresRating,
                    Availability365 = i.l.Availability365
                }).ToListAsync());
            }
            else
            {
                var result = _context.SummaryListings.Join(_context.Listings, sL => sL.Id, l => l.Id, (sl, l) => new { sl, l })
                             .Select(i => new SummaryListings
                {
                    Id              = i.sl.Id,
                    Name            = i.sl.Name,
                    Longitude       = i.sl.Longitude,
                    Latitude        = i.sl.Latitude,
                    HostName        = i.sl.HostName,
                    Neighbourhood   = i.sl.Neighbourhood,
                    Price           = i.sl.Price,
                    Rating          = i.l.ReviewScoresRating,
                    Availability365 = i.l.Availability365
                });

                if (filters.Neighbourhood != null)
                {
                    result = result.Where(l => l.Neighbourhood == filters.Neighbourhood);
                }


                if (filters.MinPrice > 0 && filters.MaxPrice > 0)
                {
                    result = result.Where(l => l.Price > filters.MinPrice && l.Price < filters.MaxPrice);
                }
                else if (filters.MinPrice > 0 && filters.MaxPrice == 0)
                {
                    result = result.Where(l => l.Price > filters.MinPrice);
                }
                else if (filters.MinPrice == 0 && filters.MaxPrice > 0)
                {
                    result = result.Where(l => l.Price < filters.MaxPrice);
                }

                if (filters.MinRating > 0)
                {
                    result = result.Where(l => l.Rating > filters.MinRating);
                }
                return(await result.ToListAsync());
            }
        }
Esempio n. 2
0
 public IActionResult ClearFilter()
 {
     listingFilters = null;
     return(Redirect("../Listings"));
 }
Esempio n. 3
0
 public ListingsViewModel(ListingsFilters filters, IEnumerable <Neighbourhoods> neighbourhoods)
 {
     this.filters        = filters;
     this.neighbourhoods = neighbourhoods;
 }
Esempio n. 4
0
 public IActionResult Filter(ListingsFilters filters)
 {
     listingFilters = filters;
     return(Redirect("../Listings"));
 }