private IEnumerable <Rental> FilterRentals(RentalsFilter filter) { var rentals = Context.Rentals.AsQueryable(); if (filter.MinumumRoom.HasValue) { rentals = rentals.Where(x => x.NumberOfRooms >= filter.MinumumRoom.Value); } //if (filter.PriceLimit.HasValue) //{ // rentals = rentals.Where(x => x.Price < filter.PriceLimit.Value); //} if (filter.PriceLimit.HasValue) { var query = Query <Rental> .Where(x => x.Price < filter.PriceLimit.Value); rentals = rentals.Where(x => query.Inject()); } return(rentals.OrderBy(x => x.Price)); ////return Context.Rentals.Find(query); //return Context.Rentals.AsQueryable().Where(x => x.Price < filter.PriceLimit.Value).AsEnumerable(); }
private IFindFluent <Rental, Rental> FilterRentals(RentalsFilter filters) { if (!filters.PriceLimit.HasValue && !filters.MinimumRooms.HasValue) { //We have to sort the collection before we enumerate it using ToList method return(Context.Rentals.Find(x => true)); } else if (filters.PriceLimit.HasValue && !filters.MinimumRooms.HasValue) { return(Context.Rentals.Find(Builders <Rental> .Filter.Lte(x => x.Price, filters.PriceLimit.Value))); //Also can be used the fluent Mongo expression which is similar to Linq //rentals = Context.Rentals.Find(x => x.Price <= filters.PriceLimit.Value).ToList(); } else if (filters.MinimumRooms.HasValue && !filters.PriceLimit.HasValue) { //Using LINQ //return Context.Rentals.AsQueryable().Where(x => x.NumberOfRooms >= filters.MinimumRooms); return(Context.Rentals.Find(x => x.NumberOfRooms >= filters.MinimumRooms)); } else { //Using LINQ //return Context.Rentals.AsQueryable().Where(x => x.NumberOfRooms >= filters.MinimumRooms.Value && x.Price >= filters.PriceLimit.Value); return(Context.Rentals.Find(x => x.NumberOfRooms >= filters.MinimumRooms.Value && x.Price <= filters.PriceLimit.Value)); } }
public ActionResult Index(RentalsFilter rentalsFilter) { var rentals = FilterRentals(rentalsFilter); var model = new RentalsList() { Rentals = rentals, RentalsFilter = rentalsFilter }; return(View(model)); }
private async Task <List <Rental> > FilterRentals(RentalsFilter filters) { if (!filters.PriceLimit.HasValue) { return(await GetRentals()); } else { return(await(await Context.Rentals.FindAsync(r => r.Price <= filters.PriceLimit)).ToListAsync()); } }
public ActionResult Index(RentalsFilter filters) { List <Rental> rentals = FilterRentals(filters); var model = new RentalsList { Rentals = rentals, Filters = filters }; return(View(model)); }
public ActionResult Index(RentalsFilter filters) { var rentals = FilterRentals(filters).SortBy(x => x.Price).ToList(); var model = new RentalList { Rentals = rentals, Filters = filters }; return(View(model)); }
public ActionResult Index(RentalsFilter filter) { var rentals = FilterRentals(filter); //.OrderByDescending(x => x.Price); //.SetSortOrder(SortBy<Rental>.Descending(x => x.Price)); var model = new RentalsList { Filter = filter, Rentals = rentals }; return(View(model)); }
private IMongoQueryable <Rental> FilterRental(RentalsFilter filter) { IMongoQueryable <Rental> rentals = ContextNew.Rentals.AsQueryable(); if (filter.MinimumRooms.HasValue) { rentals = rentals.Where(r => r.NumberOfRooms >= filter.MinimumRooms); } if (filter.PriceLimit.HasValue) { rentals = rentals.Where(r => r.Price <= filter.PriceLimit); } return(rentals); }
private List <Rental> FilterRentals(RentalsFilter filters) { IQueryable <Rental> rentals = _context.Rentals.AsQueryable() .OrderBy(x => x.Price); if (filters.MinimumRooms.HasValue) { rentals = rentals.Where(x => x.NumberOfRooms >= filters.MinimumRooms); } if (filters.PriceLimit.HasValue) { rentals = rentals.Where(x => x.Price <= filters.PriceLimit); } return(rentals.ToList()); }
private List <Rental> FilterRentals(RentalsFilter rentalsFilter) { List <Rental> rentals = null; if (!rentalsFilter.PriceLimit.HasValue) { rentals = realEstateContext.Rentals.Find(_ => true).ToList(); } else { // var filter = Builders<Rental>.Filter.Lte("Price", rentalsFilter.PriceLimit.Value); // var sorter = Builders<Rental>.Sort.Ascending(r=>r.Price); // rentals = realEstateContext.Rentals.FindSync(filter, new FindOptions<Rental, Rental>() { Sort = sorter }).ToList(); //} rentals = realEstateContext.Rentals.AsQueryable <Rental>().Where(r => r.Price <= rentalsFilter.PriceLimit.Value).OrderBy(r => r.Price).ToList(); } return(rentals); }
private IEnumerable<Rental> FilterRentals(RentalsFilter filters) { /* var rentals = new RentalsList(_rentalRepository.List()); if (filters.MinimumRooms.HasValue) { rentals = rentals .Where(r => r.NumberOfRooms >= filters.MinimumRooms); } if (filters.PriceLimit.HasValue) { var query = Query<Rental>.LTE(r => r.Price, filters.PriceLimit); rentals = rentals .Where(r => query.Inject()); } */ return _rentalRepository.List(); }
private IEnumerable <Rental> FilterRentals(RentalsFilter filters) { IQueryable <Rental> rentals = Context.Rentals.AsQueryable() .OrderBy(r => r.Price); if (filters.MinimumRooms.HasValue) { rentals = rentals .Where(r => r.NumberOfRooms >= filters.MinimumRooms); } if (filters.PriceLimit.HasValue) { var query = Query <Rental> .LTE(r => r.Price, filters.PriceLimit); rentals = rentals.Where(r => query.Inject()); } return(rentals); }
public async Task <ActionResult> Index(RentalsFilter filters) { var rentals = await FilterRentals(filters) .Select(r => new RentalViewModel { Id = r.Id, Address = r.Address, Description = r.Description, NumberOfRooms = r.NumberOfRooms, Price = r.Price }) .OrderBy(r => r.Price) .ThenByDescending(r => r.NumberOfRooms) .ToListAsync(); var model = new RentalsList { Rentals = rentals, Filters = filters }; return(View(model)); }
public async Task <IActionResult> GetFiltered([FromBody] RentalsFilter filters) { var rentals = await FilterRentals(filters); return(Ok(rentals)); }
//public readonly MongoCmsContext Context = new MongoCmsContext(); public ActionResult Index(RentalsFilter filters) { var rentals = FilterRentals(filters); var model = new RentalsList(rentals); return View(model); }