Exemplo n.º 1
0
        //public readonly MongoCmsContext Context = new MongoCmsContext();

        public ActionResult Index(RentalsFilter filters)
        {
            var rentals = FilterRentals(filters);
            var model   = new RentalsList(rentals);

            return(View(model));
        }
        public async Task <ActionResult> Index(RentalsFilter filters)
        {
            var filterDefinition = filters.ToFilterDefinition();

            //Find way
            //var rentals = await Context.Rentals
            //    .Find(filterDefinition)
            //    .SortBy(r => r.Price)
            //    .ThenByDescending(r => r.NumberOfRooms)
            //    .ToListAsync();
            //Linq

            var rentals = await FilterRentals(filters)
                          .OrderBy(r => r.Price)
                          .ThenByDescending(r => r.NumberOfRooms)
                          .ToListAsync();

            var model = new RentalsList
            {
                Rentals = rentals,
                Filters = filters
            };

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult Index(RentalsFilter filters)
        {
            var rentals = FilterRentals(filters);

            var model = new RentalsList
            {
                Rentals = rentals,
                Filters = filters
            };

            return View(model);
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Index(RentalsFilter filters)
        {
            List <Rental> rentals = await _rentalService.FilerRentals(filters)
                                    .OrderBy(r => r.Price)
                                    .ToListAsync();

            RentalsListVM model = new RentalsListVM()
            {
                Filters = filters,
                Rentals = rentals
            };

            return(View(model));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Index(RentalsFilter filters)
        {
            //var rentals = FilterRentals(filters);

            //var rentals = await ContextNew.Rentals
            //    .Find(new BsonDocument())
            //    .ToListAsync();

            //var filterDefinition = Builders<Rental>.Filter.Where(r => r.NumberOfRooms >= filters.MinimumRooms);
            //var rentals = await ContextNew.Rentals
            //    .Find(filterDefinition)
            //    .ToListAsync();

            //var rentals = await ContextNew.Rentals
            //    .Find(filters.ToFilterDefinition())
            //    .Project(r => new RentalViewModel
            //    {
            //        Id = r.Id,
            //        Description = r.Description,
            //        NumberOfRooms = r.NumberOfRooms,
            //        Price = r.Price,
            //        Address = r.Address
            //    })
            //    //.Sort(Builders<Rental>.Sort.Ascending(r => r.Price))
            //    .SortBy(r => r.Price)
            //    .ThenByDescending(r => r.NumberOfRooms)
            //    .ToListAsync();

            var rentals = await FilterRentals(filters)
                          .Select(r => new RentalViewModel
            {
                Id            = r.Id,
                Description   = r.Description,
                NumberOfRooms = r.NumberOfRooms,
                Price         = r.Price,
                Address       = r.Address
            })
                          .OrderBy(r => r.Price)
                          .ThenByDescending(r => r.NumberOfRooms)
                          .ToListAsync();

            var model = new RentalsList
            {
                Rentals = rentals,
                Filters = filters
            };

            return(View(model));
        }
        // GET: Rentals
        public ActionResult Index(RentalsFilter filters)
        {
            if (filters.MinimumRooms == null)
            {
                filters.MinimumRooms = 0;
                filters.PriceLimit   = 1000000;
            }
            var rentals = FilterRentals(filters);
            var model   = new RentalsList
            {
                Rentals = rentals,
                Filters = filters
            };

            return(View(model));
        }
        private IMongoQueryable <Rental> FilterRentals(RentalsFilter filters)
        {
            IMongoQueryable <Rental> rentals = Context.Rentals.AsQueryable();

            if (filters.MinimumRooms.HasValue)
            {
                rentals = rentals.Where(r => r.NumberOfRooms >= filters.MinimumRooms);
            }

            if (filters.PriceLimit.HasValue)
            {
                rentals = rentals.Where(r => r.Price <= filters.PriceLimit);
            }

            return(rentals);
        }
Exemplo n.º 8
0
        public IMongoQueryable <Rental> FilerRentals(RentalsFilter filters)
        {
            var rentals = _repo.GetAll().AsQueryable();

            if (filters.PriceLimit.HasValue)
            {
                rentals = rentals.Where(x => x.Price <= filters.PriceLimit);
            }

            if (filters.MinimumRooms.HasValue)
            {
                rentals = rentals.Where(x => x.NumberOfRooms >= filters.MinimumRooms);
            }

            return(rentals);
        }
Exemplo n.º 9
0
        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());
        }
Exemplo n.º 10
0
        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;
        }
        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.RoomCount >= filters.MinimumRooms);
            }

            if (filters.PriceLimit >= 0)
            {
                var query = Query <Rental> .LTE(r => r.Price, filters.PriceLimit);

                rentals = rentals.Where(r => query.Inject());
            }

            return(rentals);
        }