Esempio n. 1
0
        public async Task <IActionResult> Compare(AllCarsModel input)
        {
            var firstCar = await this.adService.GetCurrentCarAsync(input.CompareCarsInputModel.FirstCarId);

            var secondCar = await this.adService.GetCurrentCarAsync(input.CompareCarsInputModel.SecondCarId);

            if (firstCar == null || secondCar == null)
            {
                return(this.View("Error"));
            }

            var output = new ChoosenCarsForCompareViewModel
            {
                FirstCar = new ComparedCarViewModel
                {
                    Cc               = firstCar.Cc,
                    Color            = firstCar.Color,
                    Door             = firstCar.Door,
                    EuroStandart     = firstCar.EuroStandart,
                    Extras           = firstCar.Extras == null ? new List <string>() : firstCar.Extras.Split(",", StringSplitOptions.RemoveEmptyEntries).ToList(),
                    Fuel             = firstCar.Fuel,
                    Gearbox          = firstCar.Gearbox,
                    Horsepowers      = firstCar.Horsepowers,
                    ImgPath          = GlobalConstants.CloudinaryPathDimitur98 + firstCar.ImgsPaths.Split(",", StringSplitOptions.RemoveEmptyEntries).First().ToString(),
                    Km               = firstCar.Km,
                    Make             = firstCar.Make,
                    Model            = firstCar.Model,
                    Modification     = firstCar.Modification,
                    Price            = firstCar.Price,
                    Type             = firstCar.Type,
                    Condition        = firstCar.Condition,
                    YearOfProduction = firstCar.YearOfProduction.ToString("MM.yyyy"),
                    ModelToString    = this.adService.EnumParser(firstCar.Make.ToString(), firstCar.Model),
                },
                SecondCar = new ComparedCarViewModel
                {
                    Cc               = secondCar.Cc,
                    Color            = secondCar.Color,
                    Door             = secondCar.Door,
                    EuroStandart     = secondCar.EuroStandart,
                    Extras           = secondCar.Extras == null ? new List <string>() : secondCar.Extras.Split(",", StringSplitOptions.RemoveEmptyEntries).ToList(),
                    Fuel             = secondCar.Fuel,
                    Gearbox          = secondCar.Gearbox,
                    Horsepowers      = secondCar.Horsepowers,
                    ImgPath          = GlobalConstants.CloudinaryPathDimitur98 + secondCar.ImgsPaths.Split(",", StringSplitOptions.RemoveEmptyEntries).First().ToString(),
                    Km               = secondCar.Km,
                    Make             = secondCar.Make,
                    Model            = secondCar.Model,
                    Modification     = secondCar.Modification,
                    Price            = secondCar.Price,
                    Type             = secondCar.Type,
                    Condition        = secondCar.Condition,
                    YearOfProduction = secondCar.YearOfProduction.ToString("MM.yyyy"),
                    ModelToString    = this.adService.EnumParser(secondCar.Make.ToString(), secondCar.Model),
                },
            };

            return(this.View(output));
        }
Esempio n. 2
0
        public IActionResult Index()
        {
            AllCarsModel AllCars = new AllCarsModel();

            AllCars.cars = _service.GetCarsList();

            return(View("HomePage", AllCars));
        }
Esempio n. 3
0
        public AllCarsModel Paging(AllCarsModel data, int?take = null, int skip = 0)
        {
            data.AllCars = data.AllCars.Skip(skip).ToList();
            if (take.HasValue)
            {
                data.AllCars = data.AllCars.Take(take.Value).ToList();
            }

            return(data);
        }
Esempio n. 4
0
        public async Task <IActionResult> AllByCriteria(string id, SearchInputModel input, int page = 1)
        {
            // if (input.Make == 0)
            // {
            //    var searchModel = await this.searchService.GetDefaultSearchModel();
            //    input = AutoMapperConfig.MapperInstance.Map<SearchInputModel>(searchModel);
            // }
            var user = await this.userManager.GetUserAsync(this.User);

            if (id != null)
            {
                var searchModel = await this.searchService.GetSearchModelByIdAsync(id);

                input = AutoMapperConfig.MapperInstance.Map <SearchInputModel>(searchModel);
            }
            else
            {
                if (user != null)
                {
                    await this.searchService.SaveSearchModelAsync(user.Id, input);
                }
            }

            this.ViewData["searchModel"] = input as SearchInputModel;

            var ads = await this.homeService.GetAdsByCriteriaAsync(input);

            var result = new AllCarsModel
            {
                AllCars        = ads,
                SortInputModel = new SortInputModel {
                    SearchInputModel = new SearchInputModel(),
                },
                CurrentPage = page,
                Action      = "AllByCriteria",
            };

            var count = result.AllCars.Count;

            result.PagesCount = (int)Math.Ceiling((double)count / GlobalConstants.ItemsPerPage);
            if (result.PagesCount == 0)
            {
                result.PagesCount = 1;
            }

            var output = this.homeService.Paging(result, GlobalConstants.ItemsPerPage, (page - 1) * GlobalConstants.ItemsPerPage);

            return(this.View("All", output));
        }
Esempio n. 5
0
        public async Task PagingTest()
        {
            var options       = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());
            var carRepository = new EfDeletableEntityRepository <Car>(new ApplicationDbContext(options.Options));
            var adService     = new Mock <IAdService>();
            var viewService   = new Mock <IViewService>();

            var homeService = new HomeService(carRepository, adService.Object, viewService.Object);

            await SeedData(carRepository);

            var cars = await carRepository.All().Where(x => x.IsApproved).ToListAsync();

            // order of cars: car2, car3, car4, car5, car6
            var output = new AllCarsModel
            {
                AllCars = await homeService.GetAllAdsAsync(),
            };

            output.AllCars = output.AllCars.OrderBy(x => x.Id).ToArray();
            int carsPerPage = 2;
            int page        = 1;
            var result      = homeService.Paging(output, carsPerPage, (page - 1) * carsPerPage);

            Assert.Equal("car2", result.AllCars.ToArray()[0].Id);
            Assert.Equal("car3", result.AllCars.ToArray()[1].Id);

            output = new AllCarsModel
            {
                AllCars = await homeService.GetAllAdsAsync(),
            };
            output.AllCars = output.AllCars.OrderBy(x => x.Id).ToArray();
            page           = 2;
            result         = homeService.Paging(output, carsPerPage, (page - 1) * carsPerPage);
            Assert.Equal("car4", result.AllCars.ToArray()[0].Id);
            Assert.Equal("car5", result.AllCars.ToArray()[1].Id);

            output = new AllCarsModel
            {
                AllCars = await homeService.GetAllAdsAsync(),
            };
            output.AllCars = output.AllCars.OrderBy(x => x.Id).ToArray();
            page           = 3;
            result         = homeService.Paging(output, carsPerPage, (page - 1) * carsPerPage);
            Assert.Equal("car6", result.AllCars.ToArray()[0].Id);
        }
Esempio n. 6
0
        public async Task <IActionResult> All(int page = 1)
        {
            var searchModel = new SearchInputModel
            {
                Condition     = Condition.All,
                Location      = Location.All,
                Fuel          = Fuel.All,
                TypeOfVeichle = TypeOfVeichle.All,
                Gearbox       = Gearbox.All,
                Make          = Make.All,
                Model         = null,
                YearTo        = null,
                YearFrom      = null,
                PriceFrom     = null,
                PriceTo       = null,
            };
            var result = new AllCarsModel
            {
                AllCars        = await this.homeService.GetAllAdsAsync(),
                SortInputModel = new SortInputModel
                {
                    SearchInputModel = searchModel,
                },
                CurrentPage = page,
                Action      = "All",
            };
            var count = result.AllCars.Count;

            result.PagesCount = (int)Math.Ceiling((double)count / GlobalConstants.ItemsPerPage);
            if (result.PagesCount == 0)
            {
                result.PagesCount = 1;
            }

            var output = this.homeService.Paging(result, GlobalConstants.ItemsPerPage, (page - 1) * GlobalConstants.ItemsPerPage);

            this.ViewData["searchModel"] = searchModel as SearchInputModel;

            return(this.View(output));
        }
Esempio n. 7
0
        public async Task <IActionResult> Sort(SortInputModel sortModel, AllCarsModel input, SearchInputModel searchModle, int page = 1)
        {
            ICollection <CarAdsViewModel> ads;

            // this is true only when you go through pages
            if (searchModle.Make != 0)
            {
                input.SortInputModel = new SortInputModel {
                    OrderByYear = sortModel.OrderByYear, OrderByPrice = sortModel.OrderByPrice, SearchInputModel = searchModle
                };
            }

            var sortInputModel = new SortInputModel();

            if (input.SortInputModel.SearchInputModel == null)
            {
                ads = await this.homeService.GetAllAdsAsync();
            }
            else
            {
                ads = await this.homeService.GetAdsByCriteriaAsync(input.SortInputModel.SearchInputModel);

                this.ViewData["searchModel"]    = input.SortInputModel.SearchInputModel as SearchInputModel;
                this.ViewData["orderByYear"]    = input.SortInputModel.OrderByYear;
                this.ViewData["orderByPrice"]   = input.SortInputModel.OrderByPrice;
                sortInputModel.SearchInputModel = new SearchInputModel();
            }

            if (input.SortInputModel.OrderByYear == "2")
            {
                ads = ads.OrderBy(x => x.YearOfProduction).ToList();
            }
            else if (input.SortInputModel.OrderByYear == "1")
            {
                ads = ads.OrderByDescending(x => x.YearOfProduction).ToList();
            }
            else if (input.SortInputModel.OrderByPrice == "2")
            {
                ads = ads.OrderBy(x => x.Price).ToList();
            }
            else if (input.SortInputModel.OrderByPrice == "1")
            {
                ads = ads.OrderByDescending(x => x.Price).ToList();
            }

            var result = new AllCarsModel
            {
                AllCars        = ads,
                SortInputModel = sortInputModel,
                CurrentPage    = page,
                Action         = "Sort",
            };

            var count = result.AllCars.Count;

            result.PagesCount = (int)Math.Ceiling((double)count / GlobalConstants.ItemsPerPage);
            if (result.PagesCount == 0)
            {
                result.PagesCount = 1;
            }

            var output = this.homeService.Paging(result, GlobalConstants.ItemsPerPage, (page - 1) * GlobalConstants.ItemsPerPage);

            return(this.View("All", output));
        }