@using Microsoft.AspNetCore.Mvc.TagHelpers @model (Dictionary Items, int Level) @if (Model.Items.Any()) { @* Use titlecase and lowercase versions for backwards-compatibility *@ string[] cartKeys = ["cart", "subtotal", "discount", "tip", "total"]; @if (Model.Items.Keys.Any(key => cartKeys.Contains(key.ToLowerInvariant()))) { _ = Model.Items.TryGetValue("cart", out var cart) || Model.Items.TryGetValue("Cart", out cart); var hasTotal = Model.Items.TryGetValue("total", out var total) || Model.Items.TryGetValue("Total", out total); var hasSubtotal = Model.Items.TryGetValue("subtotal", out var subtotal) || Model.Items.TryGetValue("subTotal", out subtotal) || Model.Items.TryGetValue("Subtotal", out subtotal); var hasDiscount = Model.Items.TryGetValue("discount", out var discount) || Model.Items.TryGetValue("Discount", out discount); var hasTip = Model.Items.TryGetValue("tip", out var tip) || Model.Items.TryGetValue("Tip", out tip); if (cart is Dictionary { Keys.Count: > 0 } cartDict) { @foreach (var (key, value) in cartDict) { } } else if (cart is ICollection { Count: > 0 } cartCollection) { @foreach (var value in cartCollection) { } } @if (hasSubtotal && (hasDiscount || hasTip)) { } @if (hasDiscount) { } @if (hasTip) { } @if (hasTotal) { } } else { foreach (var (key, value) in Model.Items) { } }
Subtotal @subtotal
Discount @discount
Tip @tip
Total @total
}