public ActionResult Purchase(PurchaseViewModel model) { var LookupValueRepo = LookupValueFactory.GetRepository(); var ADORep = RepositoryFactory.GetRepository(); //Apply Rule purchase price must be no less than 95% of Sale price decimal?salePrice = model.VehicleDetail.SalePrice; if (model.PurchasePrice < (salePrice * 0.95m)) { ModelState.AddModelError("PurchasePrice", "Purchase Price must be no less than 95% of sale price"); } decimal?MSRP = model.VehicleDetail.MSRP; //MSRP Rule. Purchase must not exceed MSRP if (model.PurchasePrice > MSRP) { ModelState.AddModelError("PurchasePrice", "Purchase Price must not exceed MSRP"); } if (!ModelState.IsValid) //Reload vehicle and set states and purchase types { model.SetPurchaseTypes(LookupValueRepo.GetPurchaseTypes()); model.SetStates(LookupValueRepo.GetStates()); model.VehicleDetail = ADORep.GetVehicleDetail(model.VehicleDetail.VehicleId); return(View(model)); } //Set sales model Sales sales = new Sales(); sales.CustomerName = model.CustomerName; sales.Phone = model.Phone; sales.Street1 = model.Street1; sales.Street2 = model.Street2; sales.City = model.City; sales.State = model.State; sales.ZipCode = model.ZipCode; sales.VehicleId = model.VehicleDetail.VehicleId; sales.PurchaseType = model.PurchaseType; sales.PurchasePrice = model.PurchasePrice; //Find id of logged in user var userName = User.Identity.GetUserName(); GuildCars.UI.Models.Identity.GuildCarsDbContext context = new GuildCars.UI.Models.Identity.GuildCarsDbContext(); var userId = context.Users.FirstOrDefault(u => u.UserName == userName).Id; sales.UserId = userId; ADORep.PurchaseVehicle(sales); //update/Make purchase return(View(model)); }
public ActionResult Purchase(int id) { var LookupValueRepo = LookupValueFactory.GetRepository(); var ADORep = RepositoryFactory.GetRepository(); PurchaseViewModel model = new PurchaseViewModel(); model.VehicleDetail = ADORep.GetVehicleDetail(id); model.SetPurchaseTypes(LookupValueRepo.GetPurchaseTypes()); model.SetStates(LookupValueRepo.GetStates()); return(View(model)); }
// GET: Sales public ActionResult Index() { var LookupValueRepo = LookupValueFactory.GetRepository(); //Populates the dropdown list values for Years and Price SearchViewModel model = new SearchViewModel(); model.SetMinYearValues(LookupValueRepo.GetYears()); model.SetMaxYearValues(LookupValueRepo.GetYears()); model.SetMinPriceValues(LookupValueRepo.GetPrices()); model.SetMaxPriceValues(LookupValueRepo.GetPrices()); return(View(model)); }
public ActionResult AddVehicle() { var LookupRepo = LookupValueFactory.GetRepository(); var repo = RepositoryFactory.GetRepository(); var model = new AddEditVehicleViewModel(); //set lookup values model.SetBodyStyles(LookupRepo.GetBodyStyles()); model.SetMakes(repo.GetMakes()); model.SetCondition(LookupRepo.GetCondition()); model.SetExteriorColor(LookupRepo.GetExteriorColor()); model.SetInteriorColor(LookupRepo.GetInteriorColor()); model.SetTransmissions(LookupRepo.GetTransmissionTypes()); model.SetYears(LookupRepo.GetYears()); return(View(model)); }
public ActionResult EditVehicle(int id) { var repo = RepositoryFactory.GetRepository(); var LookupValueRepo = LookupValueFactory.GetRepository(); VehicleQueryModel vcm = repo.GetVehicleDetail(id); AddEditVehicleViewModel aevm = new AddEditVehicleViewModel(); //Set lookup values aevm.SetBodyStyles(LookupValueRepo.GetBodyStyles()); aevm.SetCondition(LookupValueRepo.GetCondition()); aevm.SetExteriorColor(LookupValueRepo.GetExteriorColor()); aevm.SetInteriorColor(LookupValueRepo.GetInteriorColor()); aevm.SetMakes(repo.GetMakes()); aevm.SetTransmissions(LookupValueRepo.GetTransmissionTypes()); aevm.SetYears(LookupValueRepo.GetYears()); //Get the models for the make of this vehicle aevm.SetModels(repo.GetModelsByMakeId(vcm.MakeId)); // Translate the Vechicle Query model to the AddEditVehicleViewModel aevm.Condition = vcm.ConditionType.ToString(); aevm.Transmission = vcm.TransmissionType.ToString(); aevm.VIN = vcm.VIN.ToString(); aevm.Year = vcm.Year; aevm.MSRP = vcm.MSRP; aevm.SalePrice = vcm.SalePrice; aevm.ModelId = vcm.ModelId; aevm.MakeId = vcm.MakeId; aevm.ImageFileName = vcm.ImageFileName.ToString(); aevm.Mileage = vcm.Mileage; aevm.InteriorColor = vcm.InteriorColor.ToString(); aevm.ExteriorColor = vcm.ExteriorColor.ToString(); aevm.Description = vcm.Description.ToString(); aevm.BodyStyle = vcm.BodyStyle.ToString(); aevm.VehicleId = vcm.VehicleId; aevm.FeaturedFlag = vcm.FeaturedFlag; aevm.UserId = vcm.UserId; return(View(aevm)); }