groceries/Groceries/Home/Index.cshtml
2023-07-23 20:00:53 +01:00

43 lines
1.3 KiB
Plaintext

@using Groceries.Data
@using Humanizer
@model ItemTagQuantity?
@section head {
@*<meta name="turbo-cache-control" content="no-preview" />*@
}
<section class="card">
<header class="card__header">
<h2>Item Quantity (last 90 days)</h2>
</header>
<div class="card__content">
@if (Model != null)
{
@if (Model.IsDivisible)
{
var quantity = Convert.ToDouble(Model.Quantity);
var weekQuantity = Math.Round(quantity / 12);
<strong>@(Model.IsMetric ? quantity.ToMetric() : quantity)@Model.Unit @Model.Tag</strong>
<small>(@(Model.IsMetric ? weekQuantity.ToMetric() : weekQuantity)@Model.Unit per week)</small>
}
else
{
var name = Model.Unit != null ? $"{Model.Tag} {Model.Unit}" : Model.Tag;
var avgQuantity = Model.Quantity / 12;
var avgPeriod = "week";
if (avgQuantity < 1)
{
avgQuantity *= 4;
avgPeriod = "month";
}
<strong>@name.ToQuantity(Convert.ToInt32(Model.Quantity))</strong>
<small>(@name.ToQuantity(Convert.ToInt32(avgQuantity)) per @avgPeriod)</small>
}
}
</div>
</section>