public string Print() { StringBuilder builder = new StringBuilder(); builder.AppendLine($"{"Category Name",15} {"Product Name",15} {"Quantity",10} {"Unit Price",12} {"Total Price",12}"); var categoryWithProducts = ProductsWithQuantity.GroupBy(p => p.Key.Category.Title).ToDictionary(e => e.Key, e => e.ToList()); foreach (var category in categoryWithProducts) { foreach (var product in category.Value) { builder.AppendLine($"{category.Key,15} {product.Key.Title,15} {product.Value,10} {product.Key.Price,12} {(product.Key.Price * product.Value),12}\t"); } } var totalAmount = GetTotalAmount(); var totalAmountAfterDiscount = GetTotalAmountAfterDiscounts(); var totalDeliveryCost = GetDeliveryCost(); builder.AppendLine($"\nTotal Amount: {Math.Round(totalAmount, 2)}"); builder.AppendLine($"Total Discount: {Math.Round(totalAmount - totalAmountAfterDiscount, 2)}"); builder.AppendLine($"Total Amount After Discounts: {Math.Round(totalAmountAfterDiscount, 2)}"); builder.AppendLine($"Delivery Cost: {Math.Round(totalDeliveryCost, 2)}"); builder.AppendLine($"Payable Amount: {Math.Round((double)totalAmountAfterDiscount + (double)totalDeliveryCost, 2)}"); return(builder.ToString()); }
public int GetDeliveryCount() { return(ProductsWithQuantity.GroupBy(e => e.Key.Category.Title).Count()); }