From 216944ae66967f55098eddf7c464cbd8a75061eb Mon Sep 17 00:00:00 2001 From: Sakurai Date: Sun, 9 Feb 2025 10:20:26 +0900 Subject: [PATCH] add good state --- Uriagekun/Controllers/GoodController.cs | 40 +++++++++++++++++++++++++ Uriagekun/Lib/IO/MyRepository.cs | 40 +++++++++++++++++++++++++ Uriagekun/Models/AddGoodModel.cs | 15 ++++++++++ Uriagekun/Views/Good/Index.cshtml | 40 +++++++++++++++++++++++++ Uriagekun/Views/Home/Index.cshtml | 2 +- Uriagekun/Views/Shared/_Layout.cshtml | 13 ++++---- 6 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 Uriagekun/Controllers/GoodController.cs create mode 100644 Uriagekun/Models/AddGoodModel.cs create mode 100644 Uriagekun/Views/Good/Index.cshtml diff --git a/Uriagekun/Controllers/GoodController.cs b/Uriagekun/Controllers/GoodController.cs new file mode 100644 index 0000000..ad9841f --- /dev/null +++ b/Uriagekun/Controllers/GoodController.cs @@ -0,0 +1,40 @@ +using Microsoft.AspNetCore.Mvc; +using Uriagekun.Lib.IO; +using Uriagekun.Models; + +namespace Uriagekun.Controllers; + +public class GoodController : Controller +{ + private readonly MyRepository repository; + + public GoodController(MyRepository repository) + { + this.repository = repository; + } + + public IActionResult Index() + { + return View(); + } + + public async Task Add(AddGoodModel model) + { + if (ModelState.IsValid) + { + return BadRequest(); + } + + if ( + string.IsNullOrEmpty(model.Barcode) || model.Barcode.Length > 16 + || string.IsNullOrEmpty(model.Label) || model.Label.Length > 40 + || model.Price < 0 + ) + { + return BadRequest(); + } + + await this.repository.AddGoods(model.Label, model.Barcode, model.Price); + return Ok(); + } +} diff --git a/Uriagekun/Lib/IO/MyRepository.cs b/Uriagekun/Lib/IO/MyRepository.cs index 42a7571..d8433bb 100644 --- a/Uriagekun/Lib/IO/MyRepository.cs +++ b/Uriagekun/Lib/IO/MyRepository.cs @@ -1,4 +1,5 @@ using PetaPoco; +using Uriagekun.Lib.Data; namespace Uriagekun.Lib.IO; @@ -10,4 +11,43 @@ public class MyRepository { this.database = database; } + + /// + /// 商品を登録します。 + /// + /// + /// + /// + /// 正常終了時、商品IDを返します。 + public async ValueTask AddGoods(string label, string barcode, int price) + { + GoodData data = new GoodData() + { + Label = label, + Barcode = barcode, + Price = price, + }; + + var ret = await this.database.InsertAsync(data).ConfigureAwait(false); + return (int) ret; + } + + /// + /// 指定商品の売上個数を登録します。 + /// + /// + /// + /// + /// + public async ValueTask AddRegister(int goodId, int count, DateTime date) + { + RegisterData data = new RegisterData() + { + GoodId = goodId, + Date = date, + Count = count, + }; + + await this.database.InsertAsync(data).ConfigureAwait(false); + } } diff --git a/Uriagekun/Models/AddGoodModel.cs b/Uriagekun/Models/AddGoodModel.cs new file mode 100644 index 0000000..16c3237 --- /dev/null +++ b/Uriagekun/Models/AddGoodModel.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; + +namespace Uriagekun.Models; + +public class AddGoodModel +{ + [Required] + public string Barcode { get; set; } + + [Required] + public string Label { get; set; } + + [Required] + public int Price { get; set; } +} diff --git a/Uriagekun/Views/Good/Index.cshtml b/Uriagekun/Views/Good/Index.cshtml new file mode 100644 index 0000000..7db7ea1 --- /dev/null +++ b/Uriagekun/Views/Good/Index.cshtml @@ -0,0 +1,40 @@ +@{ + ViewData["Title"] = "商品管理"; +} + +
+
+

商品登録

+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+
+
diff --git a/Uriagekun/Views/Home/Index.cshtml b/Uriagekun/Views/Home/Index.cshtml index bcfd79a..b7479e0 100644 --- a/Uriagekun/Views/Home/Index.cshtml +++ b/Uriagekun/Views/Home/Index.cshtml @@ -1,5 +1,5 @@ @{ - ViewData["Title"] = "Home Page"; + ViewData["Title"] = "ホーム"; }
diff --git a/Uriagekun/Views/Shared/_Layout.cshtml b/Uriagekun/Views/Shared/_Layout.cshtml index e7cc524..07924a9 100644 --- a/Uriagekun/Views/Shared/_Layout.cshtml +++ b/Uriagekun/Views/Shared/_Layout.cshtml @@ -1,9 +1,9 @@  - + - @ViewData["Title"] - Uriagekun + @ViewData["Title"] - 売上管理 @@ -12,7 +12,7 @@