public IActionResult Add(SaleBindingModel s) { using (this.context) { if (ModelState.IsValid) { Car car = this.context .Cars .Include(c => c.PartCars) .ThenInclude(p => p.Part) .FirstOrDefault(c => c.Id == s.CarId); SaleReviewViewModel sale = new SaleReviewViewModel { Customer = s.Customer, Car = $"{car.Make} {car.Model}", Discount = s.Discount, CarPrice = car.PartCars.Sum(pc => pc.Part.Price), CarId = car.Id }; ViewBag.IsYoungDriver = this.context.Customers.FirstOrDefault(c => c.Name == s.Customer).IsYoungDriver ? "(+5%)" : ""; return(View(nameof(Review), sale)); } ViewBag.Customers = new SelectList(this.context .Customers .Select(c => c.Name) .ToList()); ViewBag.Cars = this.context .Cars .Select(c => new { Id = c.Id, Car = $"{c.Make} {c.Model}" }) .ToList(); ViewBag.Discounts = new SelectList(new List <double> { 0.0, 0.1, 0.2, 0.3, 0.4, 0.5 }); ModelState.AddModelError(string.Empty, "All fields are required."); return(View(s)); } }
public IActionResult Review(SaleReviewViewModel s) => View(s);