public IActionResult Review(SaleReviewModel saleReviewModel) { this.sales.Create(saleReviewModel.CarId, saleReviewModel.CustomerId, saleReviewModel.Discount); this.logger.Create(this.User, nameof(Create), ControllerAsString); return(RedirectToAction(nameof(All))); }
public IActionResult ReviewCreate(SaleFormModel model) { if (!this.customerService.Exists(model.CustomerId)) { this.ModelState.AddModelError(nameof(model.CustomerId), "Invalid customer."); } if (!this.carService.Exists(model.CarId)) { this.ModelState.AddModelError(nameof(model.CarId), "Invalid car."); } if (!this.ModelState.IsValid) { model.Cars = this.GetCarsSelectList(); model.Customers = this.GetCustomersSelectList(); return(this.View(nameof(Create), model)); } var customer = this.customerService.GetByIdWithAdditionalDiscount(model.CustomerId); var car = this.carService.GetByIdWithPrice(model.CarId); var reviewModel = new SaleReviewModel { CustomerId = model.CustomerId, CarId = model.CarId, Discount = model.Discount, Customer = customer.Name, AdditionalDiscount = customer.AdditionalDiscount, Car = car.MakeModel, Price = car.Price, }; return(this.View(reviewModel)); }
public IActionResult FinalizeCreate(SaleReviewModel model) { if (!this.customerService.Exists(model.CustomerId)) { this.ModelState.AddModelError(nameof(model.CustomerId), "Invalid customer."); } if (!this.carService.Exists(model.CarId)) { this.ModelState.AddModelError(nameof(model.CarId), "Invalid car."); } if (!this.ModelState.IsValid) { var createModel = new SaleFormModel { CarId = model.CarId, CustomerId = model.CustomerId, Discount = model.Discount, Cars = this.GetCarsSelectList(), Customers = this.GetCustomersSelectList() }; return(this.View(nameof(Create), createModel)); } this.saleService.Create(model.CustomerId, model.CarId, model.TotalDiscount); return(this.RedirectToAction(nameof(All))); }
public IActionResult ReviewCreate(SaleFormModel saleModel) { if (!ModelState.IsValid) { saleModel.Cars = this.GetCars(); saleModel.Customers = this.GetCustomers(); return(View(nameof(Create), saleModel)); } SaleReviewModel saleReviewModel = this.sales.SaleReview( saleModel.CarId, saleModel.CustomerId, saleModel.Discount ); return(View(saleReviewModel)); }
public SaleReviewModel GetReviewSale(int carId, int customerId, double discountPercentage) { Customer customer = this.dbContext.Customers.Find(customerId); if (customer == null) { throw new NullReferenceException($"Cannot find customer with id: {customerId}"); } Car car = this.dbContext.Cars .Include(c => c.PartCars) .ThenInclude <Car, PartCars, Part>(cp => cp.Part) .FirstOrDefault(c => c.Id == carId); if (car == null) { throw new NullReferenceException($"Cannot find car with id: {carId}"); } double totalDiscount = discountPercentage; if (customer.IsYoungDriver) { totalDiscount += 5; } decimal carPrice = car.PartCars.Sum(p => p.Part.Price); decimal finalPrice = carPrice * Convert.ToDecimal(((100.0 - totalDiscount) / 100.0)); SaleReviewModel reviewModel = new SaleReviewModel() { CalculatedDiscountText = (discountPercentage / 100).ToString("P2") + (customer.IsYoungDriver ? $"({0.05.ToString("P2")})" : string.Empty), CustomerName = customer.Name, CarDetails = $"{car.Make} {car.Model}", TotalDiscount = totalDiscount / 100, CarPrice = carPrice, FinalCarPrice = finalPrice, CarId = car.Id, CustomerId = customer.Id, }; return(reviewModel); }
public IActionResult FinalizeCreate(SaleReviewModel saleModel) { if (!this.ModelState.IsValid) { var createModel = new SaleFormModel { CarsDropdown = this.GetCarsSelectListItem(), CustomersDropdown = this.GetCustomersSelectListItem() }; return(this.RedirectToAction(nameof(Create), createModel)); } this.saleService.Create( saleModel.CustomerId, saleModel.CarId, saleModel.Discount); return(this.RedirectToAction(nameof(All))); }
public IActionResult FinalizeCreate(SaleReviewModel saleModel) { if (!ModelState.IsValid) { var createModel = new SaleFormModel { Cars = this.GetCars(), Customers = this.GetCustomers(), }; return(View(nameof(Create), createModel)); } this.sales.CreateNewSale( saleModel.CarId, saleModel.CustomerId, saleModel.Discount ); var userId = _userManager.GetUserId(HttpContext.User); this.logs.Add(userId, "Add", "Sale", DateTime.Now); return(RedirectToAction(nameof(AllSales))); }