/// <summary> /// This method returns final price after calculation based on all active promotions /// </summary> /// <param name="skuIdList">Input list of items</param> /// <returns>total price</returns> public int CalculateTotalPrice(List <char> skuIdList) { try { List <Promotion> promotions = _promotionService.GetAllActivePromotions(); var skuIdGroups = skuIdList.GroupBy(i => i.ToString()); int total = 0; processedSKUList = new List <char>(); foreach (var skuIds in skuIdGroups) { List <Promotion> applicablePromoList = promotions.Where(p => p.SKUList.Any(s => s.ID.ToString() == skuIds.Key)).ToList(); int selectedSKUCount = skuIds.Count(); bool isPriceAdded = processedSKUList.Any(s => s == skuIds.Key.ToCharArray()[0]); if (applicablePromoList.Count() > 0 && !isPriceAdded) { foreach (Promotion promotion in applicablePromoList) { if (promotion.SKUList.Any(s => s.ID.ToString() == skuIds.Key)) { int discountPrice = promotion.DiscountPrice; if (promotion.PromotionType == "Multi") { total += CalculatePriceMultiItemPromo(promotion, selectedSKUCount); processedSKUList.Add(promotion.SKUList[0].ID); break; } else if (promotion.PromotionType == "Combo") { total += CalculatePriceComboItemPromo(promotion, selectedSKUCount, skuIdGroups); break; } } } } else { if (!isPriceAdded) { SKU skuItem = _skuService.GetSKUByID(skuIds.Key.ToCharArray()[0]); total += skuItem.Price; processedSKUList.Add(skuIds.Key.ToCharArray()[0]); } } } return(total); } catch (Exception ex) { throw ex; } }
protected static void SelectItems() { try { Console.WriteLine(); Console.WriteLine("Select space separated items among A,B,C,D"); string item = Console.ReadLine(); var selectedList = item.Split(" "); var isValidEntry = true; foreach (var selItem in selectedList) { if (!string.IsNullOrEmpty(selItem)) { SKU sku = _skuService.GetSKUByID(selItem.ToCharArray()[0]); if (sku != null) { selectedSKUList.Add(selItem.ToUpper().ToCharArray()[0]); } else { isValidEntry = false; Console.WriteLine(selItem + " is not valid item"); } } } if (!isValidEntry) { SelectItems(); } else { UserAction(); } } catch (Exception ex) { throw ex; } }