public ActionResult AddConfirmation(AddSaleConfirmationViewModel salesConfirmVm) { var cookie = this.Request.Cookies.Get("sessionId"); if (cookie == null || !AuthenticationManager.IsAuthenticated(cookie.Value)) { return(this.RedirectToAction("Login", "Users")); } return(this.View(salesConfirmVm)); }
public ActionResult AddSales([Bind(Include = "CustomerId, CarId, Discount")] AddSaleBm addSaleBm) { if (this.ModelState.IsValid) { AddSaleConfirmationViewModel salesConfirmVm = this.service.GetConfirmatinModel(addSaleBm); return(this.RedirectToAction("AddConfirmation", salesConfirmVm)); } AddSalesViewModel addSalesVm = service.GenerateAddSalesForm(); return(this.View(addSalesVm)); }
public AddSaleConfirmationViewModel GetConfirmatinModel(AddSaleBm addSaleBm) { AddSaleConfirmationViewModel confVm = new AddSaleConfirmationViewModel(); confVm.CarId = addSaleBm.CarId; confVm.CustomerId = addSaleBm.CustomerId; Customer customer = this.Context.Customers.Find(confVm.CustomerId); Car car = this.Context.Cars.Find(confVm.CarId); if (customer.IsYoungDriver) { confVm.TotalDiscount = 5 + addSaleBm.Discount; } confVm.CustomerName = customer.Name; confVm.TotalDiscount = addSaleBm.Discount; confVm.CarName = car.Make + " " + car.Model; confVm.CarPrice = (decimal)car.Parts.Sum(p => p.Price).Value; confVm.FinalCarPrice = confVm.CarPrice - confVm.CarPrice * confVm.TotalDiscount / 100; return(confVm); }