private async Task<int> ProcessPromotions2(List<CartItems> cartItems) { var result = 0; var promotions = await _promotionRepository.GetAsync(); var skus = await _sKURepository.GetAsync(); var engine = new QuantityHandler(_promotionRepository); engine.NextHandler(new MultipromotionHandler(_promotionRepository, _sKURepository)); foreach (var item in cartItems) { var sku = skus.FirstOrDefault(d => d.SKU == item.SKU); var promotion = promotions.FirstOrDefault(d => d.IsActive && d.SKU.Contains(item.SKU)); var request = new Request(item.SKU, item.Quantity, promotion.PromotionType, promotion.Value, sku.Value); result += await engine.RunAsync(request); } return result; }
public override async Task <int> RunAsync(Request item) { var result = 0; var amountToSubtract = 0; var promotions = await _promotionRepository.GetAsync(); var skus = await _sKURepository.GetAsync(); if (item.PromotionType.Equals(PromotionType.MultiSku)) { foreach (var sku in VisitedSku) { var data = skus.FirstOrDefault(d => d.SKU == sku); amountToSubtract += data == null ? 0 : data.Value; } VisitedSku.Add(item.Sku); var preparedSku = string.Join(" & ", VisitedSku); var promotion = promotions.FirstOrDefault(d => d.IsActive && d.SKU.Equals(preparedSku)); if (promotion == null) { result += item.UnitPrice; } else { VisitedSku.Clear(); result -= amountToSubtract; result += promotion.Value; } return(result); } else { return(await base.RunAsync(item)); } }