Пример #1
0
        public ActionResult InsertCarMake(CarMakes model)
        {
            CarMakes make = new CarMakes();

            var makeRepo = CarMakesRepositoryFactory.GetRepository();

            var repo = CarMakesRepositoryFactory.GetRepository();

            var carMakes = makeRepo.GetAll();

            make.MakeName = model.MakeName;

            DateTime today = DateTime.Today;

            make.DateAdded = today;

            make.Email = User.Identity.Name;

            if (make.MakeName == null)
            {
                ModelState.AddModelError("MakeName", "Make name cannot be blank");
            }

            if (ModelState.IsValid)
            {
                repo.Insert(make);

                return(View("Makes"));
            }
            else
            {
                return(View("Makes"));
            }
        }
        public IEnumerable <FeaturedVehicles> GetFeatured()
        {
            var repo = GetAll();

            var makeRepo = CarMakesRepositoryFactory.GetRepository();

            var makes = makeRepo.GetAll();

            var modelRepo = CarModelItemRepositoryFactory.GetRepository();

            var models = modelRepo.GetAll();


            var featured = from v in repo
                           join make in makes on v.MakeID equals make.MakeID
                           join model in models on v.ModelID equals model.ModelID
                           where v.IsFeaturedVehicle == true
                           select new FeaturedVehicles
            {
                VehicleID     = v.VehicleID,
                ImageFileName = v.ImageFileName,
                YearBuilt     = v.YearBuilt,
                MakeName      = make.MakeName,
                ModelName     = model.ModelName,
                SalesPrice    = v.SalesPrice
            };

            return(featured);
        }
Пример #3
0
        public ActionResult Models()
        {
            var viewModel = new ModelsVM();

            viewModel.SetMakeItems(CarMakesRepositoryFactory.GetRepository().GetAll());

            return(View(viewModel));
        }
Пример #4
0
        public IHttpActionResult GetAllMakes()
        {
            var repo = CarMakesRepositoryFactory.GetRepository();

            try
            {
                return(Ok(repo.GetAll()));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #5
0
        public ActionResult Models()
        {
            CarModelItemViewModel vm = new CarModelItemViewModel();

            var makeRepo = CarMakesRepositoryFactory.GetRepository();

            List <CarMakes> carMakes = makeRepo.GetAll();

            var carMakeNames = (from carmake in carMakes
                                select carmake.MakeName).ToList();

            vm.CarMakeNames = new SelectList(carMakes, "MakeName", "MakeName", 1);

            return(View(vm));
        }
Пример #6
0
        public ActionResult AddVehicle()
        {
            List <string> MakeNames = new List <string>();

            AddVehicleViewModel vm = new AddVehicleViewModel();

            var makeRepo = CarMakesRepositoryFactory.GetRepository();

            List <CarMakes> carMakes = makeRepo.GetAll();

            var carMakeNames = (from carmake in carMakes
                                select carmake.MakeName).ToList();

            vm.CarMakeNames = new SelectList(carMakes, "MakeName", "MakeName", 1);

            return(View(vm));
        }
Пример #7
0
        public ActionResult Makes(MakesVM makesVM)
        {
            if (ModelState.IsValid)
            {
                var repo = CarMakesRepositoryFactory.GetRepository();

                var make = new CarMake();

                make.Name = makesVM.MakeName;

                repo.Insert(make);

                return(RedirectToAction("Makes"));
            }

            return(View("Makes", makesVM));
        }
Пример #8
0
        public ActionResult UpdateVehicle(int id)
        {
            var makesRepo             = CarMakesRepositoryFactory.GetRepository();
            var vehicleTypesRepo      = VehicleTypesRepositoryFactory.GetRepository();
            var bodyStylesRepo        = BodyStylesRepositoryFactory.GetRepository();
            var transmissionTypesRepo = TransmissionTypesRepositoryFactory.GetRepository();
            var colorsRepo            = ColorsRepositoryFactory.GetRepository();
            var interiorColorsRepo    = InteriorColorsRepositoryFactory.GetRepository();
            var vehiclesRepo          = VehiclesRepositoryFactory.GetRepository();
            var modelsRepo            = CarModelsRepositoryFactory.GetRepository();

            var viewModel = new UpdateVehicleVM();

            viewModel.SetMakeItems(makesRepo.GetAll());
            viewModel.SetVehicleTypeItems(vehicleTypesRepo.GetAll());
            viewModel.SetBodyStyleItems(bodyStylesRepo.GetAll());
            viewModel.SetTransmissionTypeItems(transmissionTypesRepo.GetAll());
            viewModel.SetColorItems(colorsRepo.GetAll());
            viewModel.SetInteriorColorItems(interiorColorsRepo.GetAll());
            viewModel.SetMakeModelItems(modelsRepo.GetDetailsAll());

            var vehicleToUpdate = vehiclesRepo.GetById(id);
            var modelToUpdate   = modelsRepo.GetById(vehicleToUpdate.ModelId);
            var makeToUpdate    = makesRepo.GetById(modelToUpdate.MakeId);

            viewModel.VehicleId          = vehicleToUpdate.VehicleId;
            viewModel.VIN                = vehicleToUpdate.VIN;
            viewModel.ModelName          = modelToUpdate.Name;
            viewModel.MakeName           = makeToUpdate.Name;
            viewModel.VehicleTypeId      = vehicleToUpdate.VehicleTypeId;
            viewModel.BodyStyleId        = vehicleToUpdate.BodyStyleId;
            viewModel.ModelYear          = vehicleToUpdate.ModelYear;
            viewModel.TransmissionTypeId = vehicleToUpdate.TransmissionTypeId;
            viewModel.ColorId            = vehicleToUpdate.ColorId;
            viewModel.InteriorColorId    = vehicleToUpdate.InteriorColorId;
            viewModel.Mileage            = vehicleToUpdate.Mileage;
            viewModel.MSRP               = vehicleToUpdate.MSRP;
            viewModel.SalePrice          = vehicleToUpdate.SalePrice;
            viewModel.Description        = vehicleToUpdate.Description;
            viewModel.IsFeatured         = vehicleToUpdate.IsFeatured;

            return(View(viewModel));
        }
Пример #9
0
        public ActionResult AddVehicle()
        {
            var makesRepo             = CarMakesRepositoryFactory.GetRepository();
            var vehicleTypesRepo      = VehicleTypesRepositoryFactory.GetRepository();
            var bodyStylesRepo        = BodyStylesRepositoryFactory.GetRepository();
            var transmissionTypesRepo = TransmissionTypesRepositoryFactory.GetRepository();
            var colorsRepo            = ColorsRepositoryFactory.GetRepository();
            var interiorColorsRepo    = InteriorColorsRepositoryFactory.GetRepository();

            var viewModel = new AddVehicleVM();

            viewModel.SetMakeItems(makesRepo.GetAll());
            viewModel.SetVehicleTypeItems(vehicleTypesRepo.GetAll());
            viewModel.SetBodyStyleItems(bodyStylesRepo.GetAll());
            viewModel.SetTransmissionTypeItems(transmissionTypesRepo.GetAll());
            viewModel.SetColorItems(colorsRepo.GetAll());
            viewModel.SetInteriorColorItems(interiorColorsRepo.GetAll());

            return(View(viewModel));
        }
Пример #10
0
        public ActionResult EditVehicle(int id)
        {
            var repo = VehicleRepositoryFactory.GetRepository();

            EditVehicleViewModel vm = new EditVehicleViewModel();

            var vehicle = repo.GetByID(id);

            vm.VehicleID = id;

            vm.MakeID = vehicle.MakeID;

            vm.ModelID = vehicle.ModelID;

            var makeRepo = CarMakesRepositoryFactory.GetRepository();

            List <CarMakes> carMakes = makeRepo.GetAll();

            vm.CarMakeNames = new SelectList(carMakes, "MakeName", "MakeName", 1);

            var makeID = (from make in carMakes
                          where vm.CarMakeName == make.MakeName
                          select make.MakeID).FirstOrDefault();

            vehicle.MakeID = makeID;

            var modelRepo = CarModelItemRepositoryFactory.GetRepository();

            List <CarModelItem> carModels = modelRepo.GetAll();

            var modelName = (from carmodel in carModels
                             where vm.MakeID == carmodel.MakeID
                             select carmodel.ModelName).FirstOrDefault();

            vm.ModelName = modelName;

            vm.SalesTypeID = vehicle.SalesTypeID;

            vm.BodyTypeID = vehicle.BodyTypeID;

            vm.YearBuilt = vehicle.YearBuilt;

            vm.TransmissionID = vehicle.TransmissionID;

            vm.ExtColorID = vehicle.ExtColorID;

            vm.IntColorID = vehicle.IntColorID;

            vm.Mileage = vehicle.Mileage;

            vm.VINNumber = vehicle.VINNumber;

            vm.MSRP = vehicle.MSRP;

            vm.SalesPrice = vehicle.SalesPrice;

            vm.VehicleDescription = vehicle.VehicleDescription;

            vm.ImageFileName = vehicle.ImageFileName;

            return(View(vm));
        }
Пример #11
0
        public ActionResult AddVehicle(AddVehicleVM addVehicleVM)
        {
            var duplicateVehicle = from v in VehiclesRepositoryFactory.GetRepository().GetAll()
                                   where v.VIN == addVehicleVM.VIN
                                   select v;

            if (duplicateVehicle.Count() != 0)
            {
                ModelState.AddModelError("VIN", "VIN already exists in database. Duplicate vehicles are not allowed.");
            }

            if (ModelState.IsValid)
            {
                var vehicleToAdd = new Vehicle();
                var modelToAdd   = new CarModel();
                var makeToAdd    = new CarMake();

                var employeeId = int.Parse(User.Identity.GetEmployeeId());

                vehicleToAdd.EmployeeId = employeeId;

                var repo = VehiclesRepositoryFactory.GetRepository();

                if (addVehicleVM.File != null && addVehicleVM.File.ContentLength > 0)
                {
                    var newId = repo.GetAll().Max(v => v.VehicleId) + 1;

                    var fileSplit = Path.GetFileName(addVehicleVM.File.FileName).Split('.');

                    var fileExtension = fileSplit[fileSplit.Length - 1];

                    var fileName = "inventory-x-" + newId + "." + fileExtension;
                    var path     = Path.Combine(Server.MapPath("~/Images/"), fileName);
                    addVehicleVM.File.SaveAs(path);

                    vehicleToAdd.ImageFileName = fileName;
                }

                modelToAdd.Name                 = addVehicleVM.ModelName;
                makeToAdd.Name                  = addVehicleVM.MakeName;
                vehicleToAdd.VIN                = addVehicleVM.VIN;
                vehicleToAdd.BodyStyleId        = addVehicleVM.BodyStyleId;
                vehicleToAdd.ModelYear          = addVehicleVM.ModelYear;
                vehicleToAdd.TransmissionTypeId = addVehicleVM.TransmissionTypeId;
                vehicleToAdd.ColorId            = addVehicleVM.ColorId;
                vehicleToAdd.InteriorColorId    = addVehicleVM.InteriorColorId;
                vehicleToAdd.Mileage            = addVehicleVM.Mileage;
                vehicleToAdd.MSRP               = addVehicleVM.MSRP;
                vehicleToAdd.SalePrice          = addVehicleVM.SalePrice;
                vehicleToAdd.Description        = addVehicleVM.Description;
                vehicleToAdd.VehicleTypeId      = addVehicleVM.VehicleTypeId;


                repo.Insert(vehicleToAdd, modelToAdd, makeToAdd);

                return(RedirectToAction("Vehicles"));
            }

            var makesRepo             = CarMakesRepositoryFactory.GetRepository();
            var vehicleTypesRepo      = VehicleTypesRepositoryFactory.GetRepository();
            var bodyStylesRepo        = BodyStylesRepositoryFactory.GetRepository();
            var transmissionTypesRepo = TransmissionTypesRepositoryFactory.GetRepository();
            var colorsRepo            = ColorsRepositoryFactory.GetRepository();
            var interiorColorsRepo    = InteriorColorsRepositoryFactory.GetRepository();
            var modelsRepo            = CarModelsRepositoryFactory.GetRepository();

            addVehicleVM.SetMakeItems(makesRepo.GetAll());
            addVehicleVM.SetVehicleTypeItems(vehicleTypesRepo.GetAll());
            addVehicleVM.SetBodyStyleItems(bodyStylesRepo.GetAll());
            addVehicleVM.SetTransmissionTypeItems(transmissionTypesRepo.GetAll());
            addVehicleVM.SetColorItems(colorsRepo.GetAll());
            addVehicleVM.SetInteriorColorItems(interiorColorsRepo.GetAll());
            addVehicleVM.SetMakeModelItems(modelsRepo.GetDetailsAll());

            return(View("AddVehicle", addVehicleVM));
        }
        public IEnumerable <VehicleItem> GetVehicleItems()
        {
            List <VehicleItem> vehicleItems = new List <VehicleItem>();

            var repo = VehicleRepositoryFactory.GetRepository();

            var vehicles = repo.GetAll();

            var salesRepo = SalesInformationRepositoryFactory.GetRepository();

            var sales = salesRepo.GetSales();

            var bodyRepo = BodyTypesRepositoryFactory.GetRepository();

            var bodyTypes = bodyRepo.GetAll();

            var makeRepo = CarMakesRepositoryFactory.GetRepository();

            var makes = makeRepo.GetAll();

            var modelRepo = CarModelItemRepositoryFactory.GetRepository();

            var models = modelRepo.GetAll();

            var transRepo = TransmissionTypesRepositoryFactory.GetRepository();

            var transTypes = transRepo.GetAll();

            var extColorRepo = ExtColorsRepositoryFactory.GetRepository();

            var extColors = extColorRepo.GetAll();

            var intColorRepo = IntColorsRepositoryFactory.GetRepository();

            var intColors = intColorRepo.GetAll();

            var items = from v in vehicles
                        join make in makes on v.MakeID equals make.MakeID
                        join model in models on v.ModelID equals model.ModelID
                        join body in bodyTypes on v.BodyTypeID equals body.BodyTypeID
                        join tran in transTypes on v.TransmissionID equals tran.TransmissionID
                        join ext in extColors on v.ExtColorID equals ext.ExtColorID
                        join color in intColors on v.IntColorID equals color.IntColorID
                        select new VehicleItem {
                VehicleID            = v.VehicleID,
                SalesTypeID          = v.SalesTypeID,
                YearBuilt            = v.YearBuilt,
                MakeName             = make.MakeName,
                ModelName            = model.ModelName,
                BodyTypeName         = body.BodyTypeName,
                TransmissionTypeName = tran.TransmissionTypeName,
                ExtColorName         = ext.ExtColorName,
                IntColorName         = color.IntColorName,
                Mileage            = v.Mileage,
                VINNumber          = v.VINNumber,
                SalesPrice         = v.SalesPrice,
                MSRP               = v.MSRP,
                VehicleDescription = v.VehicleDescription,
                ImageFileName      = v.ImageFileName
            };

            List <VehicleItem> vitems = items.ToList();

            return(vitems);
        }
Пример #13
0
 public MakesVM()
 {
     Makes     = CarMakesRepositoryFactory.GetRepository().GetAll();
     MakeItems = CarMakesRepositoryFactory.GetRepository().GetDetailsAllInStock();
 }
Пример #14
0
        public ActionResult InsertCarModel(CarModelItemViewModel model)
        {
            CarModels carmodel = new CarModels();

            var makeRepo = CarMakesRepositoryFactory.GetRepository();

            var repo = CarModelsRepositoryFactory.GetRepository();

            var carModels = makeRepo.GetAll();

            var makeID = (from carmod in carModels
                          where model.MakeName == carmod.MakeName
                          select carmod.MakeID).FirstOrDefault();

            carmodel.MakeID = makeID;

            carmodel.ModelName = model.ModelName;

            DateTime today = DateTime.Today;

            carmodel.DateAdded = today;

            carmodel.Email = User.Identity.Name;

            if (model.ModelName == null)
            {
                ModelState.AddModelError("ModelName", "Model name cannot be blank");
            }

            if (model.MakeName == null)
            {
                ModelState.AddModelError("MakeName", "Make name cannot be blank");
            }

            if (ModelState.IsValid)
            {
                var mRepo = CarMakesRepositoryFactory.GetRepository();

                List <CarMakes> carMakes = mRepo.GetAll();

                var carMakeNames = (from carmake in carMakes
                                    select carmake.MakeName).ToList();

                model.CarMakeNames = new SelectList(carMakes, "MakeName", "MakeName", 1);

                repo.Insert(carmodel);

                return(View("Models", model));
            }
            else
            {
                var mRepo = CarMakesRepositoryFactory.GetRepository();

                List <CarMakes> carMakes = mRepo.GetAll();

                var carMakeNames = (from carmake in carMakes
                                    select carmake.MakeName).ToList();

                model.CarMakeNames = new SelectList(carMakes, "MakeName", "MakeName", 1);

                return(View("Models", model));
            }
        }
Пример #15
0
        public ActionResult UpdateVehicle(UpdateVehicleVM updateVehicleVM)
        {
            if (ModelState.IsValid)
            {
                var originalVehicle = VehiclesRepositoryFactory.GetRepository().GetDetailsById(updateVehicleVM.VehicleId);

                var vehicleToUpdate = new Vehicle();
                var modelToUpdate   = new CarModel();
                var makeToUpdate    = new CarMake();

                var employeeId = int.Parse(User.Identity.GetEmployeeId());

                vehicleToUpdate.EmployeeId = employeeId;

                var repo = VehiclesRepositoryFactory.GetRepository();

                if (updateVehicleVM.File != null && updateVehicleVM.File.ContentLength > 0)
                {
                    var newId = repo.GetAll().Max(v => v.VehicleId) + 1;

                    var fileSplit = Path.GetFileName(updateVehicleVM.File.FileName).Split('.');

                    var fileExtension = fileSplit[fileSplit.Length - 1];

                    var fileName = "inventory-x-" + newId + "." + fileExtension;
                    var path     = Path.Combine(Server.MapPath("~/Images/"), fileName);
                    updateVehicleVM.File.SaveAs(path);

                    vehicleToUpdate.ImageFileName = fileName;
                }

                else
                {
                    vehicleToUpdate.ImageFileName = originalVehicle.ImageFileName;
                }

                vehicleToUpdate.VehicleId          = updateVehicleVM.VehicleId;
                vehicleToUpdate.VIN                = updateVehicleVM.VIN;
                modelToUpdate.Name                 = updateVehicleVM.ModelName;
                makeToUpdate.Name                  = updateVehicleVM.MakeName;
                vehicleToUpdate.VehicleTypeId      = updateVehicleVM.VehicleTypeId;
                vehicleToUpdate.BodyStyleId        = updateVehicleVM.BodyStyleId;
                vehicleToUpdate.ModelYear          = updateVehicleVM.ModelYear;
                vehicleToUpdate.TransmissionTypeId = updateVehicleVM.TransmissionTypeId;
                vehicleToUpdate.ColorId            = updateVehicleVM.ColorId;
                vehicleToUpdate.InteriorColorId    = updateVehicleVM.InteriorColorId;
                vehicleToUpdate.Mileage            = updateVehicleVM.Mileage;
                vehicleToUpdate.MSRP               = updateVehicleVM.MSRP;
                vehicleToUpdate.SalePrice          = updateVehicleVM.SalePrice;
                vehicleToUpdate.Description        = updateVehicleVM.Description;
                vehicleToUpdate.IsFeatured         = updateVehicleVM.IsFeatured;

                repo.Update(vehicleToUpdate, modelToUpdate, makeToUpdate);

                return(RedirectToAction("Vehicles"));
            }

            var makesRepo             = CarMakesRepositoryFactory.GetRepository();
            var vehicleTypesRepo      = VehicleTypesRepositoryFactory.GetRepository();
            var bodyStylesRepo        = BodyStylesRepositoryFactory.GetRepository();
            var transmissionTypesRepo = TransmissionTypesRepositoryFactory.GetRepository();
            var colorsRepo            = ColorsRepositoryFactory.GetRepository();
            var interiorColorsRepo    = InteriorColorsRepositoryFactory.GetRepository();
            var vehiclesRepo          = VehiclesRepositoryFactory.GetRepository();
            var modelsRepo            = CarModelsRepositoryFactory.GetRepository();

            updateVehicleVM.SetMakeItems(makesRepo.GetAll());
            updateVehicleVM.SetVehicleTypeItems(vehicleTypesRepo.GetAll());
            updateVehicleVM.SetBodyStyleItems(bodyStylesRepo.GetAll());
            updateVehicleVM.SetTransmissionTypeItems(transmissionTypesRepo.GetAll());
            updateVehicleVM.SetColorItems(colorsRepo.GetAll());
            updateVehicleVM.SetInteriorColorItems(interiorColorsRepo.GetAll());
            updateVehicleVM.SetMakeModelItems(modelsRepo.GetDetailsAll());

            return(View("UpdateVehicle", updateVehicleVM));
        }
Пример #16
0
        public ActionResult AddVehicle(AddVehicleViewModel model)
        {
            VehicleInventory vehicle = new VehicleInventory();

            var repo = VehicleRepositoryFactory.GetRepository();

            var makeRepo = CarMakesRepositoryFactory.GetRepository();

            List <CarMakes> carMakes = makeRepo.GetAll();

            var makeID = (from make in carMakes
                          where model.CarMakeName == make.MakeName
                          select make.MakeID).FirstOrDefault();

            vehicle.MakeID = makeID;

            var modelRepo = CarModelItemRepositoryFactory.GetRepository();

            List <CarModelItem> carModels = modelRepo.GetAll();

            var modelID = (from carmodel in carModels
                           where model.ModelName == carmodel.ModelName
                           select carmodel.ModelID).FirstOrDefault();

            vehicle.ModelID = modelID;

            vehicle.SalesTypeID = model.SalesTypeID;

            vehicle.BodyTypeID = model.BodyTypeID;

            vehicle.YearBuilt = model.YearBuilt;

            vehicle.TransmissionID = model.TransmissionID;

            vehicle.ExtColorID = model.ExtColorID;

            vehicle.IntColorID = model.IntColorID;

            vehicle.Mileage = model.Mileage;

            if (vehicle.SalesTypeID == 1 && vehicle.Mileage > 1000)
            {
                ModelState.AddModelError("Mileage", "Mileage on new car must be below 1000");
            }
            if (vehicle.SalesTypeID == 2 && vehicle.Mileage < 1000)
            {
                ModelState.AddModelError("Mileage", "Mileage on used car must be above 1000");
            }

            vehicle.VINNumber = model.VINNumber;

            vehicle.MSRP = model.MSRP;

            if (vehicle.MSRP < 0)
            {
                ModelState.AddModelError("MSRP", "MSRP must be a positive number");
            }

            vehicle.SalesPrice = model.SalesPrice;

            if (vehicle.SalesPrice < 0)
            {
                ModelState.AddModelError("SalesPrice", "Sales price must be a positive number");
            }

            vehicle.VehicleDescription = model.VehicleDescription;

            vehicle.IsFeaturedVehicle = null;

            if (model.UploadedFile != null)
            {
                if (model.UploadedFile.ContentType != "image/jpeg" && model.UploadedFile.ContentType != "image/jpg" && model.UploadedFile.ContentType != "image/png")
                {
                    ModelState.AddModelError("UploadedFile", "Please upload a Jpeg, Jpg, or Png file");
                }
            }

            if (ModelState.IsValid)
            {
                repo.AddVehicle(vehicle);

                if (model.UploadedFile != null && model.UploadedFile.ContentLength > 0)
                {
                    if (model.UploadedFile.ContentType == "image/jpeg")
                    {
                        vehicle.ImageFileName = "inventory-" + vehicle.VehicleID + ".jpeg";
                        string path = Path.Combine(Server.MapPath("~/images"), "inventory-" + vehicle.VehicleID + ".jpeg");
                        model.UploadedFile.SaveAs(path);
                        repo.UpdateVehicle(vehicle);
                    }
                    if (model.UploadedFile.ContentType == "image/png")
                    {
                        vehicle.ImageFileName = "inventory-" + vehicle.VehicleID + ".png";
                        string path = Path.Combine(Server.MapPath("~/images"), "inventory-" + vehicle.VehicleID + ".png");
                        model.UploadedFile.SaveAs(path);
                        repo.UpdateVehicle(vehicle);
                    }
                    if (model.UploadedFile.ContentType == "image/jpg")
                    {
                        vehicle.ImageFileName = "inventory-" + vehicle.VehicleID + ".jpg";
                        string path = Path.Combine(Server.MapPath("~/images"), "inventory-" + vehicle.VehicleID + ".jpg");
                        model.UploadedFile.SaveAs(path);
                        repo.UpdateVehicle(vehicle);
                    }
                }

                return(RedirectToAction("Vehicles"));
            }
            else
            {
                var mRepo = CarMakesRepositoryFactory.GetRepository();

                List <CarMakes> makes = mRepo.GetAll();

                var carMakeNames = (from carmake in makes
                                    select carmake.MakeName).ToList();

                model.CarMakeNames = new SelectList(carMakes, "MakeName", "MakeName", 1);

                return(View("AddVehicle", model));
            }
        }
Пример #17
0
        public List <VehicleInventoryReport> GetUsedInventoryReport()
        {
            List <VehicleInventoryReport> reports = new List <VehicleInventoryReport>();

            var repo = VehicleRepositoryFactory.GetRepository();

            var vehicles = repo.GetAll();

            var salesRepo = SalesInformationRepositoryFactory.GetRepository();

            var sales = salesRepo.GetSales();

            var salesTypeRepo = SalesTypeRepositoryFactory.GetRepository();

            var salesTypes = salesTypeRepo.GetAll();

            var bodyRepo = BodyTypesRepositoryFactory.GetRepository();

            var bodyTypes = bodyRepo.GetAll();

            var makeRepo = CarMakesRepositoryFactory.GetRepository();

            var makes = makeRepo.GetAll();

            var modelRepo = CarModelItemRepositoryFactory.GetRepository();

            var models = modelRepo.GetAll();

            var transRepo = TransmissionTypesRepositoryFactory.GetRepository();

            var transTypes = transRepo.GetAll();

            var extColorRepo = ExtColorsRepositoryFactory.GetRepository();

            var extColors = extColorRepo.GetAll();

            var intColorRepo = IntColorsRepositoryFactory.GetRepository();

            var intColors = intColorRepo.GetAll();

            var items = from v in vehicles
                        join sale in salesTypes on v.SalesTypeID equals sale.SalesTypeID
                        join make in makes on v.MakeID equals make.MakeID
                        join model in models on v.ModelID equals model.ModelID
                        join s in sales on v.VehicleID equals s.VehicleID
                        where v.SalesTypeID == 2
                        select new VehicleInventoryReport
            {
                VehicleID   = v.VehicleID,
                SalesTypeID = v.SalesTypeID,
                YearBuilt   = v.YearBuilt,
                MakeName    = make.MakeName,
                ModelName   = model.ModelName,
                Count       = sales.Select(x => x.SalesID).Count(),
                StockValue  = vehicles.Sum(x => x.MSRP)
            };

            List <VehicleInventoryReport> report = items.ToList();

            return(report);
        }