public ActionResult EditVehicle(int id) { var model = new VehicleEditVM(); var makeRepo = MakeRepositoryFactory.GetRepository(); var modelRepo = ModelRepositoryFactory.GetRepository(); var bodyStyleRepo = BodyStyleRepositoryFactory.GetRepository(); var transRepo = TransmissionRepositoryFactory.GetRepository(); var bodyColorRepo = BodyColorRepositoryFactory.GetRepository(); var interiorColorRepo = InteriorColorRepositoryFactory.GetRepository(); var vehicleRepo = VehicleRepositoryFactory.GetRepository(); model.Vehicle = vehicleRepo.GetbyId(id); model.Make = new SelectList(makeRepo.GetAll(), "MakeID", "MakeName"); model.Model = new SelectList(modelRepo.GetAll(), "ModelID", "ModelName"); model.BodyStyle = new SelectList(bodyStyleRepo.GetAll(), "BodyStyleID", "BodyDescription"); model.Transmission = new SelectList(transRepo.GetAll(), "TransmissionID", "Gears"); model.BodyColor = new SelectList(bodyColorRepo.GetAll(), "BodyColorID", "BodyColorName"); model.InteriorColor = new SelectList(interiorColorRepo.GetAll(), "InteriorColorID", "InteriorColorName"); var yearList = vehicleRepo.CreateSearchYears(); model.Years = yearList.ConvertAll(a => { return(new SelectListItem() { Text = a.ToString(), Value = a.ToString(), Selected = false }); }); return(View(model)); }
public ActionResult AddVehicle(VehicleViewModel model) { if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0) { model.Vehicle.Image = model.ImageUpload.FileName.ToString(); } if (ModelState.IsValid) { model.Vehicle.UserName = User.Identity.GetUserName(); var vehicleRepo = VehicleRepositoryFactory.GetRepository(); vehicleRepo.Add(model.Vehicle); return(View("Vehicles")); } else { var makeRepo = MakeRepositoryFactory.GetRepository(); var modelRepo = ModelRepositoryFactory.GetRepository(); var bodyRepo = BodyStyleRepositoryFactory.GetRepository(); var transRepo = TransmissionRepositoryFactory.GetRepository(); var colorRepo = ColorRepositoryFactory.GetRepository(); model.Makes = makeRepo.GetLookup(); model.Models = modelRepo.GetLookup(); model.DropDowns = VehicleTypeLookupmodel.NewUsedDropDownList(); model.BodyStyles = bodyRepo.GetAll(); model.Trans = transRepo.GetAll(); model.Colors = colorRepo.GetAll(); return(View(model)); } }
public ActionResult EditVehicle(int id) { var vehicleRepo = VehicleRepositoryFactory.GetRepository(); var makeRepo = MakeRepositoryFactory.GetRepository(); var modelRepo = ModelRepositoryFactory.GetRepository(); var bodyRepo = BodyStyleRepositoryFactory.GetRepository(); var transRepo = TransmissionRepositoryFactory.GetRepository(); var colorRepo = ColorRepositoryFactory.GetRepository(); VehicleViewModel model = new VehicleViewModel(); model.Vehicle = vehicleRepo.GetByID(id); model.Makes = makeRepo.GetLookup(); model.Models = modelRepo.GetLookupByMake(model.Vehicle.MakeID); model.DropDowns = VehicleTypeLookupmodel.NewUsedDropDownList(); model.BodyStyles = bodyRepo.GetAll(); model.Trans = transRepo.GetAll(); model.Colors = colorRepo.GetAll(); if (ModelState.IsValid) { return(View(model)); } else { return(View("Vehicles")); } }
public ActionResult AddVehicle(DetailsVM addVehicle) { if (addVehicle.Vehicle.Year < 2000 || addVehicle.Vehicle.Year > 2021) { ModelState.AddModelError("Vehicle.Year", "Please enter a year between 2000 and 2021."); } if (addVehicle.Vehicle.MSRP < 0) { ModelState.AddModelError("Vehicle.MSRP", "MSRP must be a positive number."); } if (addVehicle.Vehicle.SalePrice < 0) { ModelState.AddModelError("Vehicle.SalePrice", "SalePrice must be a positive number."); } if (addVehicle.Vehicle.MSRP < addVehicle.Vehicle.SalePrice) { ModelState.AddModelError("Vehicle.MSRP", "SalePrice must be lower than MSRP."); } if (ModelState.IsValid) { addVehicle.Vehicle.Picture = "placeholder.png"; VehicleRepositoryFactory.GetVehicleRepository().Add(addVehicle.Vehicle); return(RedirectToAction("EditVehicle", new { vinNumber = addVehicle.Vehicle.VinNumber })); } else { var viewModel = addVehicle; viewModel.BodyStyles = BodyStyleRepositoryFactory.GetBodyStyleRepository().GetBodyStyles(); viewModel.Colors = ColorRepositoryFactory.GetColorRepository().GetColors(); viewModel.Makes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); viewModel.Models = ModelRepositoryFactory.GetModelRepository().GetModels(); viewModel.Transmission = TransmissionTypeRepositoryFactory.GetTransmissionTypeRepository().GetTransmissions(); return(View(viewModel)); } }
public ActionResult Models(ModelAddViewModel vm) { var repo = ModelRepositoryFactory.GetRepository(); if (ModelState.IsValid) { var newModel = new Model(); newModel.UserId = User.Identity.GetUserId(); newModel.MakeId = vm.Make.MakeId; newModel.Name = vm.NewModelName; newModel.Year = DateTime.Now.Year; // can add possible Year option later repo.Insert(newModel); return(RedirectToAction("Models")); } else { var modelRepo = ModelRepositoryFactory.GetRepository(); var makeRepo = MakeRepositoryFactory.GetRepository(); vm = new ModelAddViewModel(); vm.ModelUserTable = modelRepo.GetModelUserTable(); vm.Makes = new SelectList(makeRepo.GetAll(), "MakeId", "Name"); return(View(vm)); } }
public List <string> GetModelsByMake(string makeName) { var makeRepo = MakeRepositoryFactory.GetMakeRepository(); var makeId = makeRepo.GetMakeIdByName(makeName); return(modelList.Where(m => m.MakeId == makeId).Select(mo => mo.ModelName).ToList()); }
public IHttpActionResult GetMakeDetails() { var repo = MakeRepositoryFactory.GetMakeRepository(); var MakeList = repo.GetMakeDetails(); return(Ok(MakeList)); }
public ActionResult Makes() { MakeViewModel makes = new MakeViewModel(); var makeRepo = MakeRepositoryFactory.GetRepository(); makes.MakeList = makeRepo.GetAll(); return(View("Makes", makes)); }
public ActionResult Models() { var viewModel = new AddModel(); viewModel.AdminMakes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); viewModel.AdminModels = ModelRepositoryFactory.GetModelRepository().GetModels(); return(View(viewModel)); }
public ActionResult Makes() { var repo = MakeRepositoryFactory.GetRepository(); var model = new MakesViewModel(); model.makes = repo.GetAll(); return(View(model)); }
public ActionResult Purchase(SaleVM sold) { var details = new DetailsVM(); details.Vehicle = VehicleRepositoryFactory.GetVehicleRepository().GetVehicleByVIN(sold.Sale.VinNumber); details.BodyStyles = BodyStyleRepositoryFactory.GetBodyStyleRepository().GetBodyStyles(); details.Colors = ColorRepositoryFactory.GetColorRepository().GetColors(); details.Makes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); details.Models = ModelRepositoryFactory.GetModelRepository().GetModels(); details.Transmission = TransmissionTypeRepositoryFactory.GetTransmissionTypeRepository().GetTransmissions(); sold.Details = details; if (sold.Sale.Phone == null && sold.Sale.Email == null) { ModelState.AddModelError("", "You must enter a phone number or an email address."); } if (sold.Sale.Zipcode.Length > 5) { ModelState.AddModelError("", "Zipcode should only be 5 digits long, please."); } if (sold.Sale.PurchasePrice < ((sold.Details.Vehicle.MSRP * 95) * .01m)) { ModelState.AddModelError("", "Purchase price should not be lower than 95% vehicle MSRP, please recalculate."); } if (sold.Sale.PurchasePrice > sold.Details.Vehicle.MSRP) { ModelState.AddModelError("", "Purchase price should not be greater than MSRP, please recalculate."); } var repo = SaleRepositoryFactory.GetSaleRepository(); if (ModelState.IsValid) { sold.Sale.UserID = User.Identity.GetUserId(); sold.Sale.PurchaseDate = DateTime.Now; } var result = repo.Add(sold.Sale); if (result != null) { var vehicleToUpdate = VehicleRepositoryFactory.GetVehicleRepository().GetVehicleByVIN(sold.Sale.VinNumber); vehicleToUpdate.IsPurchased = true; vehicleToUpdate.IsFeatured = false; VehicleRepositoryFactory.GetVehicleRepository().Edit(vehicleToUpdate); return(View("Index")); } // assign sold.UserID to currently logged in user // assign sold.PurchaseDate to DateTime.Now // if saving the purchase is a success, update vehicle.IsPurchased to true and vehicle.IsFeatured to false; return(View()); }
public ActionResult Makes() { var repo = MakeRepositoryFactory.GetRepository(); var vm = new MakeAddViewModel(); vm.MakeUserTable = repo.GetMakeUserTable(); return(View(vm)); }
public void CanLoadMakes() { var makeRepo = MakeRepositoryFactory.GetRepository(); var makes = makeRepo.GetAll(); Assert.AreEqual(6, makes.Count); Assert.AreEqual("Dodge", makes[0].MakeName); }
public ActionResult Add(VehicleAddViewModel model) { if (ModelState.IsValid) { var repo = VehicleRepositoryFactory.GetRepository(); try { if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0) { var savepath = Server.MapPath("~/Images"); string fileName = Path.GetFileNameWithoutExtension(model.ImageUpload.FileName); string extension = Path.GetExtension(model.ImageUpload.FileName); var filePath = Path.Combine(savepath, fileName + extension); int counter = 1; while (System.IO.File.Exists(filePath)) { filePath = Path.Combine(savepath, fileName + counter.ToString() + extension); counter++; } model.ImageUpload.SaveAs(filePath); model.Vehicle.Picture = Path.GetFileName(filePath); } repo.Insert(model.Vehicle); return(RedirectToAction("Details", new { id = model.Vehicle.VehicleID })); } catch (Exception ex) { throw ex; } } else { var makesRepo = MakeRepositoryFactory.GetRepository(); var modelRepo = ModelRepositoryFactory.GetRepository(); var conditionRepo = ConditionRepositoryFactory.GetRepository(); var vehicleTypeRepo = VehicleTypeRepositoryFactory.GetRepository(); var transmissionTypeRepo = TransmissionTypeRepositoryFactory.GetRepository(); var colorRepo = ColorRepositoryFactory.GetRepository(); model.Makes = new SelectList(makesRepo.GetAll(), "MakeID", "MakeName"); model.Models = new SelectList(modelRepo.GetAll(), "ModelID", "ModelName"); model.ConditionName = new SelectList(conditionRepo.GetAll(), "ConditionID", "ConditionName"); model.VehicleType = new SelectList(vehicleTypeRepo.GetAll(), "VehicleTypeID", "VehicleTypeName"); model.TransmissionType = new SelectList(transmissionTypeRepo.GetAll(), "TransmissionTypeID", "TransmissionTypeName"); model.CarColorName = new SelectList(colorRepo.GetAll(), "ColorID", "ColorName"); model.InteriorColorName = new SelectList(colorRepo.GetAll(), "ColorID", "ColorName"); return(View(model)); } }
public ActionResult Index() { var viewModel = new FeaturedVM(); viewModel.FeaturedVehicles = VehicleRepositoryFactory.GetVehicleRepository().GetFeaturedVehicles(); viewModel.Specials = SpecialRepositoryFactory.GetSpecialRepository().GetSpecials(); viewModel.FeaturedMakes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); viewModel.FeaturedModels = ModelRepositoryFactory.GetModelRepository().GetModels(); return(View(viewModel)); }
public HomeController() { _carsRepo = CarRepositoryFactory.GetRepository(); _specialsRepo = SpecialsRepositoryFactory.GetRepository(); _makeRepo = MakeRepositoryFactory.GetRepository(); _modelRepo = ModelRepositoryFactory.GetRepository(); _colorRepo = ColorRepositoryFactory.GetRepository(); _bodyStyleRepository = BodyStyleRepositoryFactory.GetRepository(); _transmissionRepository = TransmissionRepositoryFactory.GetRepository(); _customerContactRepository = CustomerContactRepositoryFactory.GetRepository(); }
public ActionResult Makes() { if (Request.IsAuthenticated) { ViewBag.UserID = AuthorizeUtilities.GetUserId(this); } var repo = MakeRepositoryFactory.GetRepository(); var model = repo.GetMakeList(); return(View(model)); }
public ActionResult Models() { var repo = ModelRepositoryFactory.GetRepository(); var model = new ModelsViewModel(); model.models = repo.GetAll(); var MakesRepo = MakeRepositoryFactory.GetRepository(); model.makes = new SelectList(MakesRepo.GetAll(), "MakeID", "Make"); return(View(model)); }
public ActionResult AddVehicle() { var viewModel = new DetailsVM(); viewModel.BodyStyles = BodyStyleRepositoryFactory.GetBodyStyleRepository().GetBodyStyles(); viewModel.Colors = ColorRepositoryFactory.GetColorRepository().GetColors(); viewModel.Makes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); viewModel.Models = ModelRepositoryFactory.GetModelRepository().GetModels(); viewModel.Transmission = TransmissionTypeRepositoryFactory.GetTransmissionTypeRepository().GetTransmissions(); return(View(viewModel)); }
public ActionResult Models() { var modelRepo = ModelRepositoryFactory.GetRepository(); var makeRepo = MakeRepositoryFactory.GetRepository(); var vm = new ModelAddViewModel(); vm.ModelUserTable = modelRepo.GetModelUserTable(); vm.Makes = new SelectList(makeRepo.GetAll(), "MakeId", "Name"); return(View(vm)); }
public ActionResult AddVehicle() { var model = new VehicleAddViewModel(); var make = MakeRepositoryFactory.GetRepository(); var models = ModelRepositoryFactory.GetRepository(); model.Make = new SelectList(make.GetAll(), "MakeId", "MakeName"); model.Models = new SelectList(models.GetAll(), "ModelId", "ModelName"); model.vehicle1 = new Vehicle(); return(View(model)); }
public ActionResult Makes() { var viewModel = new AddMake(); viewModel.AdminMakes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); foreach (var make in viewModel.AdminMakes) { make.UserID = UserManager.FindById(make.UserID).Email; } return(View(viewModel)); }
public ActionResult EditVehicle(string vinNumber) { var viewModel = new DetailsVM(); viewModel.Vehicle = VehicleRepositoryFactory.GetVehicleRepository().GetVehicleByVIN(vinNumber); viewModel.BodyStyles = BodyStyleRepositoryFactory.GetBodyStyleRepository().GetBodyStyles(); viewModel.Colors = ColorRepositoryFactory.GetColorRepository().GetColors(); viewModel.Makes = MakeRepositoryFactory.GetMakeRepository().GetMakes(); viewModel.Models = ModelRepositoryFactory.GetModelRepository().GetModels(); viewModel.Transmission = TransmissionTypeRepositoryFactory.GetTransmissionTypeRepository().GetTransmissions(); return(View(viewModel)); }
public ActionResult Add() { var MakesRepo = MakeRepositoryFactory.GetRepository(); var model = new AddVehicleModel(); model.Makes = new SelectList(MakesRepo.GetAll(), "MakeID", "Make"); var ModelsRepo = ModelRepositoryFactory.GetRepository(); model.Models = new SelectList(ModelsRepo.GetSelected(1), "ModelID", "Model"); return(View(model)); }
public ActionResult Makes(Make make) { var repo = MakeRepositoryFactory.GetMakeRepository(); make.UserId = User.Identity.GetUserId(); make.DateAdded = DateTime.Today; repo.AddMake(make); var model = new Make(); return(View(model)); }
public AdminController() { _carsRepo = CarRepositoryFactory.GetRepository(); _specialsRepo = SpecialsRepositoryFactory.GetRepository(); _makeRepo = MakeRepositoryFactory.GetRepository(); _modelRepo = ModelRepositoryFactory.GetRepository(); _colorRepo = ColorRepositoryFactory.GetRepository(); _bodyStyleRepository = BodyStyleRepositoryFactory.GetRepository(); _transmissionRepository = TransmissionRepositoryFactory.GetRepository(); _customerContactRepository = CustomerContactRepositoryFactory.GetRepository(); _purchaseLogRepository = PurchaseLogRepositoryFactory.GetRepository(); _userRepository = UserRepositoryFactory.GetRepository(); }
public ActionResult AddVehicle(VehicleAdminViewModel vm) { if (ModelState.IsValid) { var repo = VehicleRepositoryFactory.GetRepository(); try { vm.Vehicle.UserId = User.Identity.GetUserId(); if (vm.ImageUpload != null && vm.ImageUpload.ContentLength > 0) { var savepath = Server.MapPath("~/Images/Vehicles"); var fileName = Path.GetFileNameWithoutExtension(vm.ImageUpload.FileName); var extension = Path.GetExtension(vm.ImageUpload.FileName); var filePath = Path.Combine(savepath, fileName + extension); var counter = 1; while (System.IO.File.Exists(filePath)) { filePath = Path.Combine(savepath, fileName + counter.ToString() + extension); counter++; } vm.ImageUpload.SaveAs(filePath); vm.Vehicle.Image = Path.GetFileName(filePath); } repo.Insert(vm.Vehicle); return(RedirectToAction("EditVehicle", new { id = vm.Vehicle.VehicleId })); } catch (Exception ex) { throw ex; } } else { var vehicleRepo = VehicleRepositoryFactory.GetRepository(); var colorRepo = ColorRepositoryFactory.GetRepository(); var makeRepo = MakeRepositoryFactory.GetRepository(); var modelRepo = ModelRepositoryFactory.GetRepository(); vm.Makes = new SelectList(makeRepo.GetAll(), "MakeId", "Name"); vm.InteriorColors = new SelectList(colorRepo.GetAllInterior(), "InteriorColorId", "Name"); vm.ExteriorColors = new SelectList(colorRepo.GetAllExterior(), "ExteriorColorId", "Name"); return(View(vm)); } }
public ActionResult AddVehicle(VehicleAddViewModel model) { var make = MakeRepositoryFactory.GetRepository(); var models = ModelRepositoryFactory.GetRepository(); model.Make = new SelectList(make.GetAll(), "MakeId", "MakeName"); model.Models = new SelectList(models.GetAll(), "ModelId", "ModelName"); if (ModelState.IsValid) { model.vehicle1.IsSold = false; var repo = VehicleRepositoryFactory.GetRepository(); try { if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0) { var savepath = Server.MapPath("~/Images"); string fileName = Path.GetFileNameWithoutExtension(model.ImageUpload.FileName); string extension = Path.GetExtension(model.ImageUpload.FileName); var filePath = Path.Combine(savepath, fileName + extension); int counter = 1; while (System.IO.File.Exists(filePath)) { filePath = Path.Combine(savepath, fileName + counter.ToString() + extension); counter++; } model.ImageUpload.SaveAs(filePath); model.vehicle1.ImageFileName = Path.GetFileName(filePath); } repo.Insert(model.vehicle1); return(RedirectToAction("EditVehicle", new { id = model.vehicle1.VehicleId })); } catch (Exception ex) { throw ex; } } else { model.vehicle1 = new Vehicle(); return(View(model)); } }
public ActionResult EditVehicle(int id) { var model = new VehicleEditViewModel(); var makeRepo = MakeRepositoryFactory.GetRepository(); var modelsRepo = ModelRepositoryFactory.GetRepository(); var vehicleRepo = VehicleRepositoryFactory.GetRepository(); model.Make = new SelectList(makeRepo.GetAll(), "MakeId", "MakeName"); model.Models = new SelectList(modelsRepo.GetAll(), "ModelId", "ModelName"); model.vehicle1 = vehicleRepo.GetById(id); return(View(model)); }
public ActionResult AddVehicle() { var vm = new VehicleAdminViewModel(); var colorRepo = ColorRepositoryFactory.GetRepository(); var makeRepo = MakeRepositoryFactory.GetRepository(); var modelRepo = ModelRepositoryFactory.GetRepository(); vm.Makes = new SelectList(makeRepo.GetAll(), "MakeId", "Name"); vm.InteriorColors = new SelectList(colorRepo.GetAllInterior(), "InteriorColorId", "Name"); vm.ExteriorColors = new SelectList(colorRepo.GetAllExterior(), "ExteriorColorId", "Name"); return(View(vm)); }