public string print() { StringBuilder stringBuilder = new StringBuilder(); var campaignDiscount = getAvailableCampaign(); double couponDiscountPerProduct = getCouponDiscount(); if (couponDiscountPerProduct.CompareTo(0.0) != 0) { couponDiscountPerProduct = getCouponDiscount() / getNumberOfProducts(); } var calculatedDiscounts = new Dictionary <string, double>(); var products = ShoppingCartItems.GroupBy(p => p.Key.Category.Title).ToDictionary(it => it.Key, it => it.ToList()); stringBuilder.AppendLine($"{"Category ",15} {"Product ",15} {"Quantity",15} {"Unit Price",15} {"Total Price",15} {"Total Discount For Campaign", 15} {"Total Discount For Coupon", 15}"); foreach (var item in products) { foreach (var p in item.Value) { stringBuilder.AppendLine($"{item.Key,15} {p.Key.Title,15} {p.Value,15} {p.Key.Price,15} {p.Value * p.Key.Price,15} {getAvailableCampaignDiscountByProduct(calculatedDiscounts,campaignDiscount,p.Key),15} {couponDiscountPerProduct, 15}\t"); } } stringBuilder.AppendLine($"Total Amount: {getTotalAmount()}"); stringBuilder.AppendLine($"Total Amount After Discounts: {getTotalAmountAfterDiscounts()}"); stringBuilder.AppendLine($"Delivery Cost: {getDeliveryCost()}"); return(stringBuilder.ToString()); }
public int getNumberOfDeliveries() { if (ShoppingCartItems == null) { throw new NullReferenceException("ShoppingCartItems is Null"); } return(ShoppingCartItems.GroupBy(it => it.Key.Category.Title).Count());; }