Ejemplo n.º 1
0
        public ActionResult Vehicles()
        {
            var repo = VehiclesRepositoryFactory.GetRepository();

            var model = repo.GetDetailsAll();

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Purchase(PurchaseVM purchaseVM)
        {
            if (String.IsNullOrWhiteSpace(purchaseVM.Email) && String.IsNullOrWhiteSpace(purchaseVM.Phone))
            {
                ModelState.AddModelError("m.Email", "Must Provide Either Email or Phone");
            }

            if (ModelState.IsValid)
            {
                Customer customer = new Customer();
                Purchase purchase = new Purchase();
                Address  address  = new Address();

                customer.FirstName = purchaseVM.FirstName;
                customer.LastName  = purchaseVM.LastName;
                if (!String.IsNullOrWhiteSpace(purchaseVM.Email))
                {
                    customer.Email = purchaseVM.Email;
                }
                if (!String.IsNullOrWhiteSpace(purchaseVM.Phone))
                {
                    customer.Phone = purchaseVM.Phone;
                }

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

                purchase.VehicleId      = purchaseVM.VehicleId;
                purchase.EmployeeId     = employeeId;
                purchase.PurchasePrice  = purchaseVM.PurchasePrice;
                purchase.PurchaseTypeId = purchaseVM.PurchaseTypeId;

                address.StreetAddress1 = purchaseVM.StreetAddress1;
                if (!String.IsNullOrWhiteSpace(purchaseVM.StreetAddress2))
                {
                    address.StreetAddress2 = purchaseVM.StreetAddress2;
                }
                address.City    = purchaseVM.City;
                address.StateId = purchaseVM.StateId;
                address.ZipCode = purchaseVM.ZipCode;

                var repo = PurchasesRepositoryFactory.GetRepository();

                repo.Insert(customer, purchase, address);

                return(RedirectToAction("Index"));
            }

            purchaseVM.Vehicle = VehiclesRepositoryFactory.GetRepository().GetDetailsById(purchaseVM.VehicleId);
            purchaseVM.SetStateItems(StatesRepositoryFactory.GetRepository().GetAll());
            purchaseVM.SetPurchaseTypeItems(PurchaseTypesRepositoryFactory.GetRepository().GetAll());

            return(View("Purchase", purchaseVM));
        }
Ejemplo n.º 3
0
        public ActionResult Purchase(int id)
        {
            var viewModel = new PurchaseVM();

            viewModel.VehicleId = id;
            viewModel.Vehicle   = VehiclesRepositoryFactory.GetRepository().GetDetailsById(id);
            viewModel.MSRP      = viewModel.Vehicle.MSRP;
            viewModel.SalePrice = viewModel.Vehicle.SalePrice;
            viewModel.SetStateItems(StatesRepositoryFactory.GetRepository().GetAll());
            viewModel.SetPurchaseTypeItems(PurchaseTypesRepositoryFactory.GetRepository().GetAll());

            return(View(viewModel));
        }
Ejemplo n.º 4
0
        public IHttpActionResult UsedVehicles(string searchQuery, short?minPrice, short?maxPrice, short?minYear, short?maxYear)
        {
            VehicleQuery query = new VehicleQuery();

            query.SearchQuery = searchQuery;
            query.MinPrice    = minPrice;
            query.MaxPrice    = maxPrice;
            query.MinYear     = minYear;
            query.MaxYear     = maxYear;

            var repo = VehiclesRepositoryFactory.GetRepository();

            var model = repo.GetDetailsAllByVehicleTypeId(2, query).Take(20);

            return(Ok(model));
        }
Ejemplo n.º 5
0
        public ActionResult Delete(int vehicleId)
        {
            var repo = VehiclesRepositoryFactory.GetRepository();

            var vehicle = repo.GetDetailsById(vehicleId);

            var imageFileName = vehicle.ImageFileName;

            repo.Delete(vehicleId);

            if ((System.IO.File.Exists(Path.Combine(Server.MapPath("~/Images/"), imageFileName))))
            {
                System.IO.File.Delete(Path.Combine(Server.MapPath("~/Images/"), imageFileName));
            }

            return(RedirectToAction("Vehicles"));
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
0
        public ActionResult Index()
        {
            var model = VehiclesRepositoryFactory.GetRepository().GetDetailsAll();

            return(View(model));
        }
Ejemplo n.º 10
0
        public ActionResult Used()
        {
            var model = VehiclesRepositoryFactory.GetRepository().GetDetailsAllByVehicleTypeId(2);

            return(View(model));
        }
Ejemplo n.º 11
0
        public ActionResult Details(int id)
        {
            var model = VehiclesRepositoryFactory.GetRepository().GetDetailsById(id);

            return(View(model));
        }
Ejemplo n.º 12
0
 public HomeVM()
 {
     FeaturedVehicleItems = VehiclesRepositoryFactory.GetRepository().GetFeaturedDetailsAll();
     SpecialItems         = SpecialsRepositoryFactory.GetRepository().GetAll();
 }