From 2aa91cc208450148e8c8b63d7d6393facac93dab Mon Sep 17 00:00:00 2001 From: Sakurai Date: Mon, 5 May 2025 18:39:19 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=E8=B2=A9=E5=A3=B2=E5=80=8B=E6=95=B0?= =?UTF-8?q?=E3=81=AF=E8=87=AA=E5=8B=95=E8=A8=88=E7=AE=97=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StockingData/Controllers/GraphController.cs | 4 +++- .../Controllers/StockProductsController.cs | 2 +- .../Lib/Services/GraphViewTransformer.cs | 24 +++++++++++++++++++ StockingData/Views/Shared/_Layout.cshtml | 3 --- 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 StockingData/Lib/Services/GraphViewTransformer.cs diff --git a/StockingData/Controllers/GraphController.cs b/StockingData/Controllers/GraphController.cs index aafd024..717157b 100644 --- a/StockingData/Controllers/GraphController.cs +++ b/StockingData/Controllers/GraphController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using StockingData.Lib.IO.Repositories; +using StockingData.Lib.Services; using StockingData.Models; namespace StockingData.Controllers; @@ -22,13 +23,14 @@ public class GraphController : Controller } var records = await this.stockRepository.FetchStockRecordByIdAsync(product.ProductId).ConfigureAwait(false); + var transformer = new GraphViewTransformer(records); var model = new GraphViewModel() { ProductId = product.ProductId, Title = product.Title, Code = product.Code, - Stocks = records, + Stocks = transformer.Transform(), }; return View(model); diff --git a/StockingData/Controllers/StockProductsController.cs b/StockingData/Controllers/StockProductsController.cs index 23e5f7f..00bda87 100644 --- a/StockingData/Controllers/StockProductsController.cs +++ b/StockingData/Controllers/StockProductsController.cs @@ -50,6 +50,6 @@ public class StockProductsController : Controller await this.stockRepository.UpdateStockCountAsync(stockId, count).ConfigureAwait(false); } - return RedirectToAction("Register", "SaleProducts"); + return RedirectToAction("List", "Products"); } } diff --git a/StockingData/Lib/Services/GraphViewTransformer.cs b/StockingData/Lib/Services/GraphViewTransformer.cs new file mode 100644 index 0000000..cf1c977 --- /dev/null +++ b/StockingData/Lib/Services/GraphViewTransformer.cs @@ -0,0 +1,24 @@ +using StockingData.Lib.Data; + +namespace StockingData.Lib.Services; + +public class GraphViewTransformer +{ + private readonly IEnumerable records; + public GraphViewTransformer(IEnumerable records) + { + this.records = records; + } + + public IEnumerable Transform() + { + var list = new List(); + foreach (var item in this.records) + { + item.SaleCount = item.DisplayCount - item.StockCount; + list.Add(item); + } + + return list; + } +} diff --git a/StockingData/Views/Shared/_Layout.cshtml b/StockingData/Views/Shared/_Layout.cshtml index d0d14fc..91eb761 100644 --- a/StockingData/Views/Shared/_Layout.cshtml +++ b/StockingData/Views/Shared/_Layout.cshtml @@ -31,9 +31,6 @@ -