public ActionResult EditVehicle(int id)
        {
            {
                var model              = new EditVehiclesViewModel();
                var vehiclesRepo       = VehicleRepositoryFactory.GetRepository();
                var makesRepo          = MakesRepositoryFactory.GetRepository();
                var modelsRepo         = ModelsRepositoryFactory.GetRepository();
                var vehicleTypesRepo   = VehicleTypesRepositoryFactory.GetRepository();
                var bodyStylesRepo     = BodyStylesRepositoryFactory.GetRepository();
                var transmissionsRepo  = TransmissionsRepositoryFactory.GetRepository();
                var bodyColorsRepo     = BodyColorsRepositoryFactory.GetRepository();
                var interiorColorsRepo = InteriorColorsRepositoryFactory.GetRepository();

                model.VehicleToEdit = vehiclesRepo.SelectVehicle(id);
                model.Makes         = makesRepo.GetAllMakes();
                model.SelectedMake  = makesRepo.GetMakeForModel(model.VehicleToEdit.ModelId).MakeId;
                model.VehicleType   = new SelectList(vehicleTypesRepo.GetAllVehicleTypes(), "VehicleTypeId", "VehicleTypeDescription");
                model.BodyStyle     = new SelectList(bodyStylesRepo.GetAllBodyStyles(), "BodyStyleId", "BodyStyleDescription");
                model.Transmission  = new SelectList(transmissionsRepo.GetAllTransmissions(), "TransmissionId", "TransmissionDescription");
                model.BodyColor     = new SelectList(bodyColorsRepo.GetAllBodyColors(), "BodyColorId", "BodyColorDescription");
                model.InteriorColor = new SelectList(interiorColorsRepo.GetAllInteriorColors(), "InteriorColorId", "InteriorColorDescription");

                return(View(model));
            }
        }
        public ActionResult EditVehicle(EditVehiclesViewModel model)
        {
            if (ModelState.IsValid)
            {
                var repo = VehicleRepositoryFactory.GetRepository();

                try
                {
                    var oldVehicle = repo.SelectVehicle(model.VehicleToEdit.VehicleId);
                    if (model.ReplacePicture != null && model.ReplacePicture.ContentLength > 0)
                    {
                        var savepath  = Server.MapPath("~/Images");
                        var vehicleId = model.VehicleToEdit.VehicleId.ToString();
                        var filePath  = Path.Combine(savepath, "inventory-" + vehicleId + ".PNG");

                        model.ReplacePicture.SaveAs(filePath);
                        model.VehicleToEdit.VehiclePicture = Path.GetFileName(filePath);
                    }
                    else
                    {
                        model.VehicleToEdit.VehiclePicture = oldVehicle.VehiclePicture;
                    }

                    repo.UpdateVehicle(model.VehicleToEdit);

                    return(RedirectToAction("Vehicles"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var vehiclesRepo       = VehicleRepositoryFactory.GetRepository();
                var makesRepo          = MakesRepositoryFactory.GetRepository();
                var modelsRepo         = ModelsRepositoryFactory.GetRepository();
                var vehicleTypesRepo   = VehicleTypesRepositoryFactory.GetRepository();
                var bodyStylesRepo     = BodyStylesRepositoryFactory.GetRepository();
                var transmissionsRepo  = TransmissionsRepositoryFactory.GetRepository();
                var bodyColorsRepo     = BodyColorsRepositoryFactory.GetRepository();
                var interiorColorsRepo = InteriorColorsRepositoryFactory.GetRepository();

                model.VehicleToEdit = vehiclesRepo.SelectVehicle(model.VehicleToEdit.VehicleId);
                model.Makes         = makesRepo.GetAllMakes();
                model.VehicleType   = new SelectList(vehicleTypesRepo.GetAllVehicleTypes(), "VehicleTypeId", "VehicleTypeDescription");
                model.BodyStyle     = new SelectList(bodyStylesRepo.GetAllBodyStyles(), "BodyStyleId", "BodyStyleDescription");
                model.Transmission  = new SelectList(transmissionsRepo.GetAllTransmissions(), "TransmissionId", "TransmissionDescription");
                model.BodyColor     = new SelectList(bodyColorsRepo.GetAllBodyColors(), "BodyColorId", "BodyColorDescription");
                model.InteriorColor = new SelectList(interiorColorsRepo.GetAllInteriorColors(), "InteriorColorId", "InteriorColorDescription");

                return(View(model));
            }
        }
        public ActionResult AddVehicle()
        {
            {
                var model              = new AddVehiclesViewModel();
                var makesRepo          = MakesRepositoryFactory.GetRepository();
                var modelsRepo         = ModelsRepositoryFactory.GetRepository();
                var vehicleTypesRepo   = VehicleTypesRepositoryFactory.GetRepository();
                var bodyStylesRepo     = BodyStylesRepositoryFactory.GetRepository();
                var transmissionsRepo  = TransmissionsRepositoryFactory.GetRepository();
                var bodyColorsRepo     = BodyColorsRepositoryFactory.GetRepository();
                var interiorColorsRepo = InteriorColorsRepositoryFactory.GetRepository();

                model.Makes         = makesRepo.GetAllMakes();
                model.VehicleType   = new SelectList(vehicleTypesRepo.GetAllVehicleTypes(), "VehicleTypeId", "VehicleTypeDescription");
                model.BodyStyle     = new SelectList(bodyStylesRepo.GetAllBodyStyles(), "BodyStyleId", "BodyStyleDescription");
                model.Transmission  = new SelectList(transmissionsRepo.GetAllTransmissions(), "TransmissionId", "TransmissionDescription");
                model.BodyColor     = new SelectList(bodyColorsRepo.GetAllBodyColors(), "BodyColorId", "BodyColorDescription");
                model.InteriorColor = new SelectList(interiorColorsRepo.GetAllInteriorColors(), "InteriorColorId", "InteriorColorDescription");
                model.VehicleToAdd  = new Vehicles();

                return(View(model));
            }
        }