From 929eddd9e86c4550aad0f0f1f5ec38a94a84fcd1 Mon Sep 17 00:00:00 2001 From: James Chapman Date: Sun, 5 Nov 2023 23:10:54 +0000 Subject: [PATCH] Add ability to add transaction items using barcode scanner --- Groceries.Data/Items/Item.cs | 4 -- .../Transactions/TransactionItem.cs | 2 +- .../Transactions/EditTransactionItem.cshtml | 4 +- .../Transactions/NewTransactionItem.cshtml | 14 ++-- .../NewTransactionItem_Modal.cshtml | 4 +- .../Transactions/TransactionsController.cs | 57 ++++++++++----- .../Transactions/_TransactionItemForm.cshtml | 23 +++++- Groceries/wwwroot/js/controllers/modal.js | 4 ++ .../js/controllers/transaction-item-form.js | 71 ++++++++++++++++++- 9 files changed, 145 insertions(+), 38 deletions(-) diff --git a/Groceries.Data/Items/Item.cs b/Groceries.Data/Items/Item.cs index ed774da..5ec2e16 100644 --- a/Groceries.Data/Items/Item.cs +++ b/Groceries.Data/Items/Item.cs @@ -16,10 +16,6 @@ public class Item { } - public Item(string brand, string name) : this(default, brand, name) - { - } - public Guid Id { get; init; } public DateTime UpdatedAt { get; set; } public string Brand { get; set; } diff --git a/Groceries.Data/Transactions/TransactionItem.cs b/Groceries.Data/Transactions/TransactionItem.cs index 1aa880b..6b2bb25 100644 --- a/Groceries.Data/Transactions/TransactionItem.cs +++ b/Groceries.Data/Transactions/TransactionItem.cs @@ -22,7 +22,7 @@ public class TransactionItem public decimal Price { get; set; } public int Quantity { get; set; } - public Item? Item { get; init; } + public Item? Item { get; set; } public decimal Amount => Price * Quantity; } diff --git a/Groceries/Transactions/EditTransactionItem.cshtml b/Groceries/Transactions/EditTransactionItem.cshtml index 796c941..2c0153d 100644 --- a/Groceries/Transactions/EditTransactionItem.cshtml +++ b/Groceries/Transactions/EditTransactionItem.cshtml @@ -1,5 +1,5 @@ -@using Groceries.Data; -@using Microsoft.EntityFrameworkCore; +@using Groceries.Data +@using Microsoft.EntityFrameworkCore @model (Transaction Transaction, TransactionItem TransactionItem) @inject AppDbContext dbContext diff --git a/Groceries/Transactions/NewTransactionItem.cshtml b/Groceries/Transactions/NewTransactionItem.cshtml index 10c109b..a32457d 100644 --- a/Groceries/Transactions/NewTransactionItem.cshtml +++ b/Groceries/Transactions/NewTransactionItem.cshtml @@ -1,23 +1,25 @@ -@using Groceries.Data; -@using Microsoft.EntityFrameworkCore; +@using Groceries.Data +@using Microsoft.EntityFrameworkCore -@model Transaction +@model (Transaction Transaction, TransactionItem? TransactionItem) @inject AppDbContext dbContext @{ ViewBag.Title = "New Transaction Item"; var store = await dbContext.Stores - .Where(store => store.Id == Model.StoreId) + .Where(store => store.Id == Model.Transaction.StoreId) .Select(store => string.Concat(store.Retailer!.Name, " ", store.Name)) .SingleAsync(); }

New Transaction Item

-
@Model.CreatedAt.ToShortDateString() @Model.CreatedAt.ToShortTimeString() – @store
+
+ @Model.Transaction.CreatedAt.ToShortDateString() @Model.Transaction.CreatedAt.ToShortTimeString() – @store +
- +
diff --git a/Groceries/Transactions/NewTransactionItem_Modal.cshtml b/Groceries/Transactions/NewTransactionItem_Modal.cshtml index 79d7c77..424f0e9 100644 --- a/Groceries/Transactions/NewTransactionItem_Modal.cshtml +++ b/Groceries/Transactions/NewTransactionItem_Modal.cshtml @@ -1,13 +1,13 @@ @using Groceries.Data -@model Transaction +@model (Transaction Transaction, TransactionItem? TransactionItem) @{ Layout = "_Modal"; ViewBag.Title = "New Transaction Item"; } - +