コード例 #1
0
        public VehicleViewModel GetById(int id)
        {
            var foundVehicle = _vehicles.FirstOrDefault(x => x.VehicleId == id);

            MakeRepoMock makeRepo = new MakeRepoMock();
            var          makes    = makeRepo.GetAll();

            ModelRepoMock modelRepo = new ModelRepoMock();
            var           models    = modelRepo.GetAll();

            VehicleViewModel returnVehicle = new VehicleViewModel()
            {
                Color        = foundVehicle.Color,
                Description  = foundVehicle.Description,
                Interior     = foundVehicle.Interior,
                Make         = makes.FirstOrDefault(x => x.MakeId == foundVehicle.MakeId).Name,
                Model        = models.FirstOrDefault(x => x.ModelId == foundVehicle.ModelId).MakeName,
                SalePrice    = foundVehicle.SalePrice,
                Mileage      = foundVehicle.Mileage,
                MSRP         = foundVehicle.MSRP,
                Sold         = foundVehicle.Sold,
                Style        = foundVehicle.Style,
                Transmission = foundVehicle.Transmission,
                Type         = foundVehicle.Type,
                VehicleId    = foundVehicle.VehicleId,
                Vin          = foundVehicle.Vin,
                Year         = foundVehicle.Year
            };

            return(returnVehicle);
        }
コード例 #2
0
        public VehicleInventoryViewModel GetVehicleInventoryReport()
        {
            VehicleInventoryViewModel report = new VehicleInventoryViewModel();

            report.NewInventory  = new List <InventoryReport>();
            report.UsedInventory = new List <InventoryReport>();

            MakeRepoMock makeRepo = new MakeRepoMock();
            var          makes    = makeRepo.GetAll();

            ModelRepoMock modelRepo = new ModelRepoMock();
            var           models    = modelRepo.GetAll();

            foreach (var v in _vehicles)
            {
                InventoryReport r = new InventoryReport()
                {
                    Count      = 1,
                    MakeName   = makes.FirstOrDefault(x => x.MakeId == v.MakeId).Name,
                    ModelName  = models.FirstOrDefault(x => x.ModelId == v.ModelId).ModelName,
                    TotalStock = v.SalePrice,
                    Year       = v.Year
                };
                if (v.Type == "New")
                {
                    report.NewInventory.Add(r);
                }
                else
                {
                    report.UsedInventory.Add(r);
                }
            }
            return(report);
        }
コード例 #3
0
        public IEnumerable <VehicleViewModel> GetUsedVehiclesSorted(string searchText = null, decimal minPrice = 0, decimal maxPrice = 900000000, int minYear = 0, int maxYear = 2100)
        {
            if (searchText == null)
            {
                searchText = "";
            }
            List <VehicleViewModel> foundVehicles = new List <VehicleViewModel>();
            MakeRepoMock            makeRepo      = new MakeRepoMock();
            var           makes     = makeRepo.GetAll();
            ModelRepoMock modelRepo = new ModelRepoMock();
            var           models    = modelRepo.GetAll();

            foreach (var v in _vehicles)
            {
                VehicleViewModel model = new VehicleViewModel()
                {
                    Make  = makes.FirstOrDefault(x => x.MakeId == v.MakeId).Name,
                    Model = models.FirstOrDefault(x => x.ModelId == v.ModelId).ModelName
                };
                if (v.Year >= minYear && v.Year <= maxYear)
                {
                    if (v.SalePrice >= minPrice && v.SalePrice <= maxPrice)
                    {
                        if (model.Model.Contains(searchText) || model.Make.Contains(searchText))
                        {
                            if (v.Type == "Used")
                            {
                                model.Interior     = v.Interior;
                                model.Mileage      = v.Mileage;
                                model.MSRP         = v.MSRP;
                                model.SalePrice    = v.SalePrice;
                                model.Sold         = v.Sold;
                                model.Style        = v.Style;
                                model.Transmission = v.Transmission;
                                model.Type         = v.Type;
                                model.VehicleId    = v.VehicleId;
                                model.Vin          = v.Vin;
                                model.Year         = v.Year;
                                foundVehicles.Add(model);
                            }
                        }
                    }
                }
            }
            return(foundVehicles);
        }