diff --git a/src/Money.Blazor.Host/Components/OutcomeCreate.razor b/src/Money.Blazor.Host/Components/OutcomeCreate.razor index a3f9b786..66d1d722 100644 --- a/src/Money.Blazor.Host/Components/OutcomeCreate.razor +++ b/src/Money.Blazor.Host/Components/OutcomeCreate.razor @@ -2,6 +2,49 @@ + @if (Templates != null) + { + +
+ @foreach (var model in Templates) + { +
+
+
+ @if (model.Amount != null) + { +
+ + @CurrencyFormatter.Format(model.Amount) + +
+ } + + @if (!model.CategoryKey.IsEmpty) + { +

+ @FindCategoryName(model.CategoryKey) +

+ } + + @if (!String.IsNullOrEmpty(model.Description)) + { +

+ + @model.Description + +

+ } +
+
+
+ } +
+ }
diff --git a/src/Money.Blazor.Host/Components/OutcomeCreate.razor.cs b/src/Money.Blazor.Host/Components/OutcomeCreate.razor.cs index 6e4e928b..2c7a2474 100644 --- a/src/Money.Blazor.Host/Components/OutcomeCreate.razor.cs +++ b/src/Money.Blazor.Host/Components/OutcomeCreate.razor.cs @@ -35,10 +35,16 @@ public partial class OutcomeCreate [Inject] protected Navigator.ModalContainer ModalContainer { get; set; } + [Inject] + protected CurrencyFormatterFactory CurrencyFormatterFactory { get; set; } + + protected CurrencyFormatter CurrencyFormatter { get; private set; } + protected string Title { get; set; } protected string SaveButtonText { get; set; } protected List ErrorMessages { get; } = new List(); + protected List Templates { get; private set; } protected List Categories { get; private set; } protected List Currencies { get; private set; } @@ -114,8 +120,11 @@ public async void Show(IKey categoryKey) Ensure.NotNull(categoryKey, "categoryKey"); CategoryKey = categoryKey; + CurrencyFormatter = await CurrencyFormatterFactory.CreateAsync(); + Categories = await Queries.QueryAsync(new ListAllCategory()); Currencies = await Queries.QueryAsync(new ListAllCurrency()); + Templates = await Queries.QueryAsync(new ListAllExpenseTemplate()); Currency = await Queries.QueryAsync(new FindCurrencyDefault()); if (Currencies == null || Currencies.Count == 0 || Categories == null || Categories.Count == 0) @@ -140,7 +149,7 @@ public async void Show(decimal? amount, string currency, string description, IKe Show(categoryKey); } - public override void Show() + public override void Show() => Show(KeyFactory.Empty(typeof(Category))); protected void OnPrerequisitesConfirmed() @@ -150,5 +159,32 @@ protected void OnPrerequisitesConfirmed() else if (Categories == null || Categories.Count == 0) Navigator.OpenCategories(); } + + protected void ApplyTemplate(ExpenseTemplateModel model) + { + if (model.Amount != null) + { + Amount = model.Amount.Value; + Currency = model.Amount.Currency; + } + + if (!String.IsNullOrEmpty(model.Description)) + Description = model.Description; + + if (!model.CategoryKey.IsEmpty) + CategoryKey = model.CategoryKey; + } + + protected string FindCategoryName(IKey categoryKey) + { + var category = Categories?.FirstOrDefault(c => c.Key.Equals(categoryKey)); + return category?.Name; + } + + protected Color? FindCategoryColor(IKey categoryKey) + { + var category = Categories?.FirstOrDefault(c => c.Key.Equals(categoryKey)); + return category?.Color; + } } }