public SaleFinilizeServiceModel ReviewSale(int customerId, int carId, int discountId) { var customer = this.db.Customers.Find(customerId); var car = this.db.Cars.Where(c => c.Id == carId) .Select(c => new CarWIthPartsModel { Model = c.Model, Make = c.Make, Parts = c.Parts.Select(p => new PartModel { Name = p.Part.Name, Price = p.Part.Price }) }) .FirstOrDefault(); var discount = this.db.Sales.Find(discountId); var sale = new SaleFinilizeServiceModel { CustomerId = customer.Id, CustomerName = customer.Name, CarId = carId, CarName = $"{car.Model} {car.Make}", DiscountId = discountId, Discount = discount.Discount, CarPrice = car.Parts.Sum(p => p.Price) }; sale.FinalCarPrice = sale.CarPrice * (1 - (decimal)(sale.Discount)); return(sale); }
public IActionResult Finalize(SaleFinilizeServiceModel model) { if (!ModelState.IsValid) { return(View(model)); } this.saleService.Create(model.CarId, model.CustomerId, model.Discount); return(RedirectToAction(nameof(All))); }