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); }
public IHttpActionResult GetAllModels() { var repo = CarModelItemRepositoryFactory.GetRepository(); try { return(Ok(repo.GetAll())); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult GetModelsByMakes(string makeName) { var repo = CarModelItemRepositoryFactory.GetRepository(); try { return(Ok(repo.GetModelsByMake(makeName))); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
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)); } }
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)); }
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); }
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); }