public void ApplyDiscount(IDiscountCalculator discountCalculator, int existingPoints) { if (discountCalculator == null) { return; } Discount = discountCalculator.GetDiscount(this, existingPoints); }
public async Task <IActionResult> Index() { StockProductsModel stockProductsModel = new StockProductsModel(); stockProductsModel.SaleOffs = await _mozarDbContext.Stock.OrderByDescending(x => x.DiscountPercentage) .Include(x => x.Product) .Include(x => x.Product.Images) .Take(6) .Select(x => new SaleOff() { ProductName = x.Product.Name, OldPrice = x.Price, NewPrice = _discountCalculator.GetDiscount(x.Price, x.DiscountPercentage), Images = new ProductSaleImage() { HoverImage = x.Product.Images.Skip(1).FirstOrDefault().Path, ProductImage = x.Product.Images.FirstOrDefault().Path } }).ToListAsync(); stockProductsModel.NewProducts = await _mozarDbContext.Stock.OrderByDescending(x => x.DiscountPercentage) .Include(x => x.Product) .Include(x => x.Product.Images) .Take(8) .Select(x => new NewProduct() { ProductName = x.Product.Name, OldPrice = x.Price, NewPrice = _discountCalculator.GetDiscount(x.Price, x.DiscountPercentage), Images = new ProductSaleImage() { HoverImage = x.Product.Images.Skip(1).FirstOrDefault().Path, ProductImage = x.Product.Images.FirstOrDefault().Path } }).ToListAsync(); return(View(stockProductsModel)); }
private void UpdatePrices() { SubTotal = Lines.Sum(item => item.Total); Tax = _order.TaxRate * SubTotal; _discount = _orderDiscountCalculator != null?_orderDiscountCalculator.GetDiscount(this) : 0; }