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 @@ -