public ActionResult AddConfirmation(AddSaleConfirmationVm vm) { var cookie = this.Request.Cookies.Get("sessionId"); if (cookie == null || !AuthenticationManager.IsAuthenticated(cookie.Value)) { return(this.RedirectToAction("Login", "User")); } return(View(vm)); }
public ActionResult Add([Bind(Include = "CustomerId, CarId, Discount")] AddSaleBm bind) { if (ModelState.IsValid) { AddSaleConfirmationVm confirmation = this.service.GetSaleConfirmattionVm(bind); return(RedirectToAction("AddConfirmation", confirmation)); } AddSaleVm addSaleVm = this.service.GetSaleVm(); return(this.View(addSaleVm)); }
public AddSaleConfirmationVm GetSaleCofirmationVm(AddSaleBm bind) { Car carModel = this.Context.Cars.Find(bind.CarId); Customer customerModel = this.Context.Customers.Find(bind.CustomerId); AddSaleConfirmationVm vm = new AddSaleConfirmationVm() { Discount = bind.Discount, CarPrice = (decimal)carModel.Parts.Sum(part => part.Price).Value, CarId = carModel.Id, CarRepresentation = $"{carModel.Make} {carModel.Model}", CustomerId = customerModel.Id, CustomerName = customerModel.Name }; vm.Discount += customerModel.IsYoungDriver ? 5 : 0; vm.FinalCarPrice = vm.CarPrice - vm.CarPrice * vm.Discount / 100; return(vm); }
public AddSaleConfirmationVm GetSaleConfirmattionVm(AddSaleBm bind) { Car car = this.Context.Cars.Find(bind.CarId); Customer customer = this.Context.Customers.Find(bind.CustomerId); AddSaleConfirmationVm vm = new AddSaleConfirmationVm() { Discount = bind.Discount, CarId = car.Id, CarPrice = (double)car.Parts.Sum(a => a.Price), CustomerId = customer.Id, CustomerName = customer.Name, CarRepresentation = car.Make + " " + car.Model, }; vm.Discount += customer.IsYoungDriver ? 5 : 0; vm.FinalCarPrice = vm.CarPrice + vm.Discount / 100.0; return(vm); }