コード例 #1
0
        public ActionResult CarsAvailableForRent(RentViewModel rentViewModel)
        {
            //Добавить проверку по дате Аренды из rentViewModel
            var firstDayRent = rentViewModel.firstDayRent;
            var lastDayRent  = rentViewModel.lastDayRent;


            var carDtos       = carService.GetAvailableCarsForDates(rentViewModel.firstDayRent, rentViewModel.lastDayRent);
            var carViewModels = Mapper.Map <List <CarViewModel> >(carDtos);

            var bodyTypeDtos         = carService.GetAllBodyTypeDtos();
            var carClassDtos         = carService.GetAllCarClassDtos();
            var fuelTypeDtos         = carService.GetAllFuelTypeDtos();
            var gearboxTypeDtos      = carService.GetAllGearboxTypeDtos();
            var manufacturerDtos     = carService.GetAllManufacturerDtos();
            var transmissionTypeDtos = carService.GetAllTransmissionTypeDtos();
            CarSearchViewModel carSearchViewModel = new CarSearchViewModel(
                carViewModels,
                bodyTypeDtos,
                carClassDtos,
                fuelTypeDtos,
                gearboxTypeDtos,
                manufacturerDtos,
                transmissionTypeDtos
                );
            var places = placeService.GetAll();

            rentViewModel.Locations      = places;
            rentViewModel.PickUpLocation = places.SingleOrDefault(p => p.Id == rentViewModel.PickUpLocationId);
            rentViewModel.ReturnLocation = places.SingleOrDefault(p => p.Id == rentViewModel.ReturnLocationId);

            carSearchViewModel.rentViewModel = rentViewModel;

            return(View("CarSearchView", carSearchViewModel));
        }
コード例 #2
0
        public ActionResult SearchAvailableCarsByOptions(CarSearchViewModel carSearchViewModel)
        {
            CarSearchModel carSearchModel = Mapper.Map <CarSearchModel>(carSearchViewModel);

            var rentViewModel = carSearchViewModel.rentViewModel;

            var carDtos = carService.GetCarsByOptions(carSearchModel, rentViewModel.firstDayRent, rentViewModel.lastDayRent);

            var carViewModels = Mapper.Map <IEnumerable <CarViewModel> >(carDtos);

            //
            carSearchViewModel.CarViewModels        = carViewModels;
            carSearchViewModel.BodyTypeDtos         = carService.GetAllBodyTypeDtos();
            carSearchViewModel.CarClassDtos         = carService.GetAllCarClassDtos();
            carSearchViewModel.FuelTypeDtos         = carService.GetAllFuelTypeDtos();
            carSearchViewModel.GearboxTypeDtos      = carService.GetAllGearboxTypeDtos();
            carSearchViewModel.ManufacturerDtos     = carService.GetAllManufacturerDtos();
            carSearchViewModel.TransmissionTypeDtos = carService.GetAllTransmissionTypeDtos();

            var places = placeService.GetAll();

            carSearchViewModel.rentViewModel.Locations      = places;
            carSearchViewModel.rentViewModel.PickUpLocation = places
                                                              .SingleOrDefault(p => p.Id == carSearchViewModel.rentViewModel.PickUpLocationId);
            carSearchViewModel.rentViewModel.ReturnLocation = places
                                                              .SingleOrDefault(p => p.Id == carSearchViewModel.rentViewModel.ReturnLocationId);

            return(View("CarSearchView", carSearchViewModel));
        }
コード例 #3
0
        public async Task <IEnumerable <CarsAllViewModel> > Search(CarSearchViewModel car)
        {
            ;
            var cars = await this.carsService.GetCarsBySearch(car);

            return(cars);
        }
コード例 #4
0
        public async Task <IActionResult> Index(SearchBindingModel model)
        {
            var cookie = this.HttpContext.Request.Cookies;

            var sortDirectionKey = WebConstants.CookieUserSearchCarsSortDirectionKey;
            var sortDirection    = this.cookiesService.GetValueOrDefault <SortStrategyDirection>(cookie, sortDirectionKey);

            var sortTypeKey = WebConstants.CookieUserSearchCarsSortTypeKey;
            var sortType    = this.cookiesService.GetValueOrDefault <BaseCarSortStrategyType>(cookie, sortTypeKey);

            var sortStrategy = BaseCarSortStrategyFactory
                               .GetStrategy <BaseCar>(sortType, sortDirection);

            var splitedKeyWords = ParameterParser
                                  .ParseSearchKeyWordsParameter(model.KeyWords, WebConstants.MinSearchKeyWordLength)
                                  .Distinct()
                                  .ToArray();
            var filterStrategies = CarSearchFilterStrategyFactory.GetStrategies(splitedKeyWords);

            IEnumerable <CarInventoryConciseViewModel> carViewModels = new List <CarInventoryConciseViewModel>();
            int totalPagesCount = 0;

            if (filterStrategies.Count > 0)
            {
                var filteredCars          = this.carsService.GetFiltered <BaseCar>(filterStrategies.ToArray());
                var filteredAndSortedCars = sortStrategy.Sort(filteredCars);

                carViewModels = await(await this.carTestDriveService
                                      .GetCarTestDriveModelAsync <CarConciseTestDriveServiceModel>(filteredAndSortedCars, this.User, model.PageNumber))
                                .To <CarInventoryConciseViewModel>()
                                .ToArrayAsync();

                totalPagesCount = await PaginationHelper.CountTotalPagesCountAsync(filteredCars);
            }

            var searchModel = new CarSearchViewModel()
            {
                Cars = carViewModels,
                SortStrategyDirection = sortDirection,
                SortStrategyType      = sortType,
                CurrentPage           = model.PageNumber,
                TotalPagesCount       = totalPagesCount,
                KeyWords = splitedKeyWords
            };

            return(View(searchModel));
        }
コード例 #5
0
 public async Task <IEnumerable <CarsAllViewModel> > GetCarsBySearch(CarSearchViewModel carModel)
 {
     return(this.db.Cars.Where(x => x.Manufacturer == Enum.Parse <Manufacturer>(carModel.Manufacturer, true) &&
                               x.Year >= carModel.YearFrom && x.Year <= carModel.YearTo &&
                               x.Price >= carModel.PriceFrom && x.Price <= carModel.PriceTo)
            .Select(x => new CarsAllViewModel
     {
         Id = x.Id,
         Manufacturer = x.Manufacturer.ToString(),
         Model = x.Model,
         Image = x.ImageUrl,
         Year = x.Year,
         Price = x.Price,
         OwnerUsername = x.Owner.UserName,
         Contact = x.Contact,
         RatingUp = x.RatingUp,
         RatingDown = x.RatingDown,
     })
            .ToList());
 }
コード例 #6
0
        // GET: Admin/Cars
        public async Task <IActionResult> Index(CarSearchViewModel carSearch, int?newSearch, int?page)
        {
            var cars = _context.Cars
                       .Include(c => c.BodyType)
                       .Include(c => c.FuelType)
                       .Include(c => c.Model)
                       .ThenInclude(cm => cm.Brand)
                       .Include(c => c.Model)
                       .ThenInclude(cm => cm.Parent)
                       .Include(c => c.TransmissionType)
                       .Include(c => c.CarImages)
                       .AsNoTracking();


            if (newSearch != null)
            {
                page = 1;
            }

            if (carSearch.BrandId != null)
            {
                cars = cars.Where(c => c.Model.BrandId == carSearch.BrandId);
            }

            if (carSearch.ModelId != null)
            {
                cars = cars.Where(c => c.ModelId == carSearch.ModelId);
            }

            if (carSearch.FuelTypes != null && carSearch.FuelTypes.Length > 0)
            {
                IQueryable <Car> cars2 = cars.Where(c => c.FuelTypeId == carSearch.FuelTypes[0]);
                for (var i = 1; i < carSearch.FuelTypes.Length; i++)
                {
                    var i1 = i;
                    cars2 = cars2.Concat(cars.Where(c => c.FuelTypeId == carSearch.FuelTypes[i1]));
                }

                cars = cars2;

                ViewBag.CheckedFuelTypes = Request.Query["fuelTypes"].ToArray();
            }
            else
            {
                ViewBag.CheckedFuelTypes = null;
            }

            if (carSearch.BodyTypes != null && carSearch.BodyTypes.Length > 0)
            {
                IQueryable <Car> cars2 = cars.Where(c => c.BodyTypeId == carSearch.BodyTypes[0]);
                for (var i = 1; i < carSearch.BodyTypes.Length; i++)
                {
                    var i1 = i;
                    cars2 = cars2.Concat(cars.Where(c => c.BodyTypeId == carSearch.BodyTypes[i1]));
                }

                cars = cars2;

                ViewBag.CheckedBodyTypes = Request.Query["bodyTypes"].ToArray();
            }
            else
            {
                ViewBag.CheckedBodyTypes = null;
            }

            if (carSearch.TransmissionTypes != null && carSearch.TransmissionTypes.Length > 0)
            {
                IQueryable <Car> cars2 = cars.Where(c => c.TransmissionTypeId == carSearch.TransmissionTypes[0]);
                for (var i = 1; i < carSearch.TransmissionTypes.Length; i++)
                {
                    var i1 = i;
                    cars2 = cars2.Concat(cars.Where(c => c.TransmissionTypeId == carSearch.TransmissionTypes[i1]));
                }

                cars = cars2;

                ViewBag.CheckedTransmissionTypes = Request.Query["transmissionTypes"].ToArray();
            }
            else
            {
                ViewBag.CheckedTransmissionTypes = null;
            }

            if (carSearch.CarStates != null && carSearch.CarStates.Length > 0)
            {
                IQueryable <Car> cars2 = cars.Where(c => c.State == (Car.CarState)carSearch.CarStates[0]);
                for (var i = 1; i < carSearch.CarStates.Length; i++)
                {
                    var i1 = i;
                    cars2 = cars2.Concat(cars.Where(c => c.State == (Car.CarState)carSearch.CarStates[i1]));
                }

                cars = cars2;

                ViewBag.CheckedCarStates = Request.Query["carStates"].ToArray();
            }
            else
            {
                ViewBag.CheckedTransmissionTypes = null;
            }

            ViewBag.Colors = _context.Cars.Where(c => c.Count > 0).Select(c => c.Color).Distinct().ToList();

            if (carSearch.Colors != null && carSearch.Colors.Length > 0)
            {
                IQueryable <Car> cars2 = cars.Where(c => c.Color == carSearch.Colors[0]);
                for (var i = 1; i < carSearch.Colors.Length; i++)
                {
                    var i1 = i;
                    cars2 = cars2.Concat(cars.Where(c => c.Color == carSearch.Colors[i1]));
                }

                cars = cars2;

                ViewBag.CheckedColors = Request.Query["colors"].ToArray();
            }
            else
            {
                ViewBag.CheckedColors = null;
            }

            if ((carSearch.PriceFrom != null && carSearch.PriceTo != null) &&
                (carSearch.PriceFrom.Value <= carSearch.PriceTo.Value) &&
                (carSearch.PriceFrom.Value >= 0 && carSearch.PriceTo.Value >= 0))
            {
                cars = cars.Where(c => c.Price >= carSearch.PriceFrom && c.Price <= carSearch.PriceTo);
            }

            //ViewBag.QueryString = queryStringBuilder.ToString();
            ViewBag.CarSearchModel    = carSearch;
            ViewBag.QueryString       = carSearch.CreateRequest();
            ViewBag.TransmissionTypes = _context.TransmissionTypes;
            ViewBag.BodyTypes         = _context.BodyTypes;
            ViewBag.FuelTypes         = _context.FuelTypes;
            ViewBag.Brands            = new SelectList(_context.Brands, "Id", "Name", carSearch.BrandId);

            ViewBag.CarStates = Enum.GetValues(typeof(Car.CarState)).Cast <Car.CarState>()
                                .ToDictionary(t => (int)t, t => t.ToString());

            ViewBag.CarModels = carSearch.BrandId != null ? new SelectList(_context.CarModels.Where(cm => cm.BrandId == carSearch.BrandId), "Id", "Name", carSearch.ModelId) : null;


            int pageSize = 5;

            return(View(await PaginatedList <Car> .CreateAsync(cars.AsNoTracking(), page ?? 1, pageSize)));
        }