public ICollection <VisualizeScooterViewModel> ScootersForVisualization(FiltersInputModel filtersInput)
        {
            var scooterOffersToVisualize = new List <VisualizeScooterViewModel>();

            var filtersQuery = GetFiltersAsQuery(filtersInput);

            var scooterOffers = dbContext.ElectricScooterOffers.FromSqlRaw(
                "select * from ElectricScooterOffers " +
                $"where {filtersQuery}")
                                .ToList();


            foreach (var scooterOffer in scooterOffers)
            {
                var scooter = new VisualizeScooterViewModel()
                {
                    Id              = scooterOffer.Id,
                    Title           = scooterOffer.Title,
                    Condition       = scooterOffer.Condition.ToString(),
                    Year            = scooterOffer.Year,
                    Price           = scooterOffer.Price,
                    Kilometers      = scooterOffer.Kilometers,
                    MotorPower      = scooterOffer.MotorPower,
                    WaterproofLevel = scooterOffer.WaterproofLevel,
                    Battery         = scooterOffer.Battery
                };

                scooter.Image = ConvertByteArrayToImage(scooterOffer.OfferImage);

                scooterOffersToVisualize.Add(scooter);
            }

            return(scooterOffersToVisualize);
        }
Ejemplo n.º 2
0
        public void CheckIfGetOnlyUserMotorcyclesByFiltersReturnsTheCorrectMotorcyclesForThatParticularUser()
        {
            var dbContext = new AutomobileDbContext();
            var service   = new MotorcyclesService(dbContext);

            FiltersInputModel filtersInputModel = new FiltersInputModel()
            {
                Condition     = Condition.New,
                FuelType      = FuelType.Petrol,
                MinPrice      = 100,
                Make          = "All",
                Model         = "-- All --",
                Gearbox       = 0,
                MaxPrice      = 1000000,
                MinKilometers = 0,
                MaxKilometers = 1000000,
                MinYear       = 1900,
                MaxYear       = DateTime.Now.Year,
            };

            var motorcyclesCollection = service.GetOnlyUserMotorcycles("e4bf2992-cc46-4ebb-baf2-667f245a3582", filtersInputModel);

            var motorcyclesAvailableInDb = dbContext.MotorcycleOffers.Where(x =>
                                                                            x.Condition == Condition.New &&
                                                                            x.FuelType == FuelType.Petrol &&
                                                                            x.Price >= 100 && x.UserId == "e4bf2992-cc46-4ebb-baf2-667f245a3582");

            Assert.Equal(motorcyclesCollection.Count(), motorcyclesAvailableInDb.Count());
        }
Ejemplo n.º 3
0
        public void CheckIfMotorcyclesForVisualizationByFiltersAreReturningCorrectOffers()
        {
            var dbContext = new AutomobileDbContext();
            var service   = new MotorcyclesService(dbContext);

            FiltersInputModel filtersInputModel = new FiltersInputModel()
            {
                Condition         = Condition.New,
                FuelType          = FuelType.Petrol,
                MinPrice          = 100,
                Make              = "All",
                Model             = "-- All --",
                Gearbox           = 0,
                SteeringWheelSide = 0,
                MaxPrice          = 1000000,
                MinKilometers     = 0,
                MaxKilometers     = 1000000,
                MinYear           = 1900,
                MaxYear           = DateTime.Now.Year,
            };

            var motorcyclesCollection    = service.MotorcyclesForVisualization(filtersInputModel);
            var motorcyclesAvailableInDb = dbContext.MotorcycleOffers.Where(x =>
                                                                            x.Condition == Condition.New &&
                                                                            x.FuelType == FuelType.Petrol &&
                                                                            x.Price >= 100);

            Assert.Equal(motorcyclesCollection.Count(), motorcyclesAvailableInDb.Count());
        }
        public IActionResult UserCars(FiltersInputModel filtersInput)
        {
            var userId          = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var carsToVisualize = this.carsService.GetOnlyUserCars(userId, filtersInput);

            return(this.View(carsToVisualize));
        }
Ejemplo n.º 5
0
        public void CheckIfScootersForVisualizationByFiltersAreReturningCorrectOffers()
        {
            var dbContext = new AutomobileDbContext();
            var service   = new ElectricScootersService(dbContext);

            FiltersInputModel filtersInputModel = new FiltersInputModel()
            {
                Condition     = Condition.New,
                MinPrice      = 100,
                Make          = "All",
                Model         = "-- All --",
                MaxPrice      = 1000000,
                MinKilometers = 0,
                MaxKilometers = 1000000,
                MinMotorPower = 0,
                MaxMotorPower = 50000
            };

            var scootersCollection = service.ScootersForVisualization(filtersInputModel);

            var scootersAvailableInDb = dbContext.ElectricScooterOffers.Where(x =>
                                                                              x.Condition == Condition.New &&
                                                                              x.Price >= 100);

            Assert.Equal(scootersCollection.Count(), scootersAvailableInDb.Count());
        }
Ejemplo n.º 6
0
        public void CheckIfGetOnlyUserScootersByFiltersReturnsTheCorrectScootersForThatParticularUser()
        {
            var dbContext = new AutomobileDbContext();
            var service   = new ElectricScootersService(dbContext);

            FiltersInputModel filtersInputModel = new FiltersInputModel()
            {
                Condition     = Condition.New,
                MinPrice      = 100,
                Make          = "All",
                Model         = "-- All --",
                MaxPrice      = 1000000,
                MinKilometers = 0,
                MaxKilometers = 1000000,
                MinMotorPower = 0,
                MaxMotorPower = 5000
            };

            var scootersCollection = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d", filtersInputModel);

            var scootersAvailableInDb = dbContext.ElectricScooterOffers.Where(x =>
                                                                              x.Condition == Condition.New &&
                                                                              x.Price >= 100 && x.UserId == "b97261dd-b5c7-4c89-ab32-5d3934b2c85d");

            Assert.Equal(scootersCollection.Count(), scootersAvailableInDb.Count());
        }
        private string GetFiltersAsQuery(FiltersInputModel filtersInput)
        {
            var filters = "";

            bool makeFilter       = false;
            bool modelFilter      = false;
            bool priceRangeFilter = false;

            if (filtersInput.Condition != 0)
            {
                filters += $"Condition = {(int)filtersInput.Condition} ";
            }
            else
            {
                if (filtersInput.Make != "All" && filtersInput.Make != "-- All --")
                {
                    filters   += $"Make = '{filtersInput.Make}' ";
                    makeFilter = true;
                }
                else
                {
                    if (filtersInput.Model != "-- All --" && filtersInput.Model != "All")
                    {
                        filters   += $"Model = '{filtersInput.Model}' ";
                        makeFilter = true;
                    }
                    else
                    {
                        filters         += $"(Price >= {filtersInput.MinPrice} and Price <= {filtersInput.MaxPrice}) ";
                        priceRangeFilter = true;
                    }
                }
            }

            if ((filtersInput.Make != "All" && filtersInput.Make != "-- All --") && makeFilter == false)
            {
                filters += $"and Make = '{filtersInput.Make}' ";
            }

            if ((filtersInput.Model != "-- All --" && filtersInput.Model != "All") && modelFilter == false)
            {
                filters += $"and Model = '{filtersInput.Model}' ";
            }

            if (!priceRangeFilter)
            {
                filters += $"and (Price >= {filtersInput.MinPrice} and Price <= {filtersInput.MaxPrice}) ";
            }

            filters += $"and (Kilometers >= {filtersInput.MinKilometers} and Kilometers <= {filtersInput.MaxKilometers}) ";
            filters += $"and (MotorPower >= {filtersInput.MinMotorPower} and MotorPower <= {filtersInput.MaxMotorPower}) ";

            return(filters);
        }
Ejemplo n.º 8
0
        public ICollection <VisualizeCarViewModel> GetOnlyUserCars(string userId, FiltersInputModel filtersInput)
        {
            var carOffersToVisualize = new List <VisualizeCarViewModel>();

            var filtersQuery = GetFiltersAsQuery(filtersInput);

            var carOffers = dbContext.CarOffers.FromSqlRaw(
                "select * from CarOffers " +
                $"where {filtersQuery}")
                            .ToList();


            foreach (var carOffer in carOffers.Where(x => x.UserId == userId))
            {
                var car = new VisualizeCarViewModel()
                {
                    Id         = carOffer.Id,
                    Title      = carOffer.Title,
                    Condition  = carOffer.Condition.ToString(),
                    Year       = carOffer.Year,
                    FuelType   = carOffer.FuelType.ToString(),
                    HorsePower = carOffer.HorsePower,
                    Price      = carOffer.Price,
                    Kilometers = carOffer.Kilometers,
                    EngineSize = carOffer.EngineSize,
                    Gearbox    = carOffer.Gearbox.ToString(),
                    Doors      = carOffer.Doors
                };

                car.Image = ConvertByteArrayToImage(carOffer.OfferImage);

                carOffersToVisualize.Add(car);
            }

            return(carOffersToVisualize);
        }
Ejemplo n.º 9
0
        private string GetFiltersAsQuery(FiltersInputModel filtersInput)
        {
            var filters = "";

            bool colorFilter             = false;
            bool makeFilter              = false;
            bool modelFilter             = false;
            bool fuelTypeFilter          = false;
            bool gearboxFilter           = false;
            bool steeringWheelSideFilter = false;
            bool priceRangeFilter        = false;

            if (filtersInput.Condition != 0)
            {
                filters += $"Condition = {(int)filtersInput.Condition} ";
            }
            else
            {
                if (filtersInput.Color != null)
                {
                    filters    += $"Color = '{filtersInput.Color}' ";
                    colorFilter = true;
                }
                else
                {
                    if (filtersInput.Make != "All")
                    {
                        filters   += $"Make = '{filtersInput.Make}' ";
                        makeFilter = true;
                    }
                    else
                    {
                        if (filtersInput.Model != "-- All --")
                        {
                            filters    += $"Model = '{filtersInput.Model}' ";
                            modelFilter = true;
                        }
                        else
                        {
                            if (filtersInput.FuelType != 0)
                            {
                                filters       += $"FuelType = {(int)filtersInput.FuelType}";
                                fuelTypeFilter = true;
                            }
                            else
                            {
                                if (filtersInput.Gearbox != 0)
                                {
                                    filters      += $"Gearbox = {(int)filtersInput.Gearbox} ";
                                    gearboxFilter = true;
                                }
                                else
                                {
                                    if (filtersInput.SteeringWheelSide != 0)
                                    {
                                        filters += $"SteeringWheelSide = {(int)filtersInput.SteeringWheelSide} ";
                                        steeringWheelSideFilter = true;
                                    }
                                    else
                                    {
                                        filters         += $"(Price >= {filtersInput.MinPrice} and Price <= {filtersInput.MaxPrice}) ";
                                        priceRangeFilter = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (filtersInput.Color != null && colorFilter == false)
            {
                filters += $"and Color = '{filtersInput.Color}' ";
            }

            if (filtersInput.Make != "All" && makeFilter == false)
            {
                filters += $"and Make = '{filtersInput.Make}' ";
            }

            if (filtersInput.Model != "-- All --" && modelFilter == false)
            {
                filters += $"and Model = '{filtersInput.Model}' ";
            }

            if (filtersInput.FuelType != 0 && fuelTypeFilter == false)
            {
                filters += $"and FuelType = {(int)filtersInput.FuelType} ";
            }

            if (filtersInput.Gearbox != 0 && gearboxFilter == false)
            {
                filters += $"and Gearbox = {(int)filtersInput.Gearbox} ";
            }

            if (filtersInput.SteeringWheelSide != 0 && steeringWheelSideFilter == false)
            {
                filters += $"and SteeringWheelSide = {(int)filtersInput.SteeringWheelSide} ";
            }

            if (priceRangeFilter == false)
            {
                filters += $"and (Price >= {filtersInput.MinPrice} and Price <= {filtersInput.MaxPrice}) ";
            }

            filters += $"and (Kilometers >= {filtersInput.MinKilometers} and Kilometers <= {filtersInput.MaxKilometers}) ";
            filters += $"and (Year >= {filtersInput.MinYear} and Year <= {filtersInput.MaxYear}) ";

            return(filters);
        }
Ejemplo n.º 10
0
        public ICollection <VisualizeMotorcycleViewModel> GetOnlyUserMotorcycles(string userId, FiltersInputModel filtersInput)
        {
            var motorcycleOffersToVisualize = new List <VisualizeMotorcycleViewModel>();

            var filtersQuery = GetFiltersAsQuery(filtersInput);

            var motorcycleOffers = dbContext.MotorcycleOffers.FromSqlRaw(
                "select * from MotorcycleOffers " +
                $"where {filtersQuery}")
                                   .ToList();

            foreach (var motorcycleOffer in motorcycleOffers.Where(x => x.UserId == userId))
            {
                var motorcycle = new VisualizeMotorcycleViewModel()
                {
                    Id               = motorcycleOffer.Id,
                    Title            = motorcycleOffer.Title,
                    Condition        = motorcycleOffer.Condition.ToString(),
                    Year             = motorcycleOffer.Year,
                    FuelType         = motorcycleOffer.FuelType.ToString(),
                    HorsePower       = motorcycleOffer.HorsePower,
                    Price            = motorcycleOffer.Price,
                    Kilometers       = motorcycleOffer.Kilometers,
                    CubicCentimeters = motorcycleOffer.CubicCentimeters,
                    Gearbox          = motorcycleOffer.Gearbox.ToString(),
                };

                motorcycle.Image = ConvertByteArrayToImage(motorcycleOffer.OfferImage);

                motorcycleOffersToVisualize.Add(motorcycle);
            }

            return(motorcycleOffersToVisualize);
        }
        public IActionResult AllMotorcycles(FiltersInputModel filtersInput)
        {
            var motorcyclesToVisualize = this.motorcyclesService.MotorcyclesForVisualization(filtersInput);

            return(this.View(motorcyclesToVisualize));
        }
        public IActionResult AllCars(FiltersInputModel filtersInput)
        {
            var carsToVisualize = this.carsService.CarsForVisualization(filtersInput);

            return(this.View(carsToVisualize));
        }
        public IActionResult AllElectricScooters(FiltersInputModel filtersInput)
        {
            var scootersToVisualize = this.electricScootersService.ScootersForVisualization(filtersInput);

            return(this.View(scootersToVisualize));
        }