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));
            }
        }
Esempio n. 3
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));
        }
Esempio n. 4
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));
        }
        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));
            }
        }
Esempio n. 6
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));
        }
Esempio n. 7
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));
        }