Add good list
This commit is contained in:
parent
d19e06825d
commit
143f825448
@ -4,11 +4,11 @@ using Uriagekun.Models;
|
||||
|
||||
namespace Uriagekun.Controllers;
|
||||
|
||||
public class GoodController : Controller
|
||||
public class GoodsController : Controller
|
||||
{
|
||||
private readonly MyRepository repository;
|
||||
|
||||
public GoodController(MyRepository repository)
|
||||
public GoodsController(MyRepository repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
@ -35,7 +35,7 @@ public class GoodController : Controller
|
||||
}
|
||||
|
||||
await this.repository.AddGoods(model.Label, model.Barcode, model.Price).ConfigureAwait(false);
|
||||
return Ok();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
public async Task<IActionResult> List()
|
||||
46
Uriagekun/Controllers/RecordController.cs
Normal file
46
Uriagekun/Controllers/RecordController.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Uriagekun.Lib.IO;
|
||||
using Uriagekun.Models;
|
||||
|
||||
namespace Uriagekun.Controllers;
|
||||
|
||||
public class RecordController : Controller
|
||||
{
|
||||
private readonly MyRepository repository;
|
||||
|
||||
public RecordController(MyRepository repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Add(AddUriageModel model)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
if (
|
||||
string.IsNullOrEmpty(model.Barcode) || model.Barcode.Length > 16
|
||||
|| model.Count < 0
|
||||
)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
var good = await this.repository.GetGoodByBarcode(model.Barcode).ConfigureAwait(false);
|
||||
if (good is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
await this.repository.AddRegister(good.Id, model.Count, DateTime.Now).ConfigureAwait(false);
|
||||
|
||||
return RedirectToAction("Register");
|
||||
}
|
||||
}
|
||||
@ -53,6 +53,20 @@ public class MyRepository
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指定されたバーコードの商品を取得します。
|
||||
/// </summary>
|
||||
/// <param name="barcode"></param>
|
||||
/// <returns></returns>
|
||||
public async ValueTask<GoodData?> GetGoodByBarcode(string barcode)
|
||||
{
|
||||
var ret = await this.database.FetchAsync<GoodData>(
|
||||
$"SELECT * FROM goods WHERE barcode={barcode}"
|
||||
).ConfigureAwait(false);
|
||||
|
||||
return ret.FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指定商品の売上個数を登録します。
|
||||
/// </summary>
|
||||
|
||||
12
Uriagekun/Models/AddUriageModel.cs
Normal file
12
Uriagekun/Models/AddUriageModel.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Uriagekun.Models;
|
||||
|
||||
public class AddUriageModel
|
||||
{
|
||||
[Required]
|
||||
public string Barcode { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@ -5,7 +5,7 @@
|
||||
<div class="container-fluid row">
|
||||
<div class="col-md-6">
|
||||
<h2>商品登録</h2>
|
||||
<form method="post" asp-action="Add" asp-controller="Good">
|
||||
<form method="post" asp-action="Add" asp-controller="Goods">
|
||||
<div class="form-group row m-2">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label" for="goodLabel">商品名</label>
|
||||
29
Uriagekun/Views/Record/Register.cshtml
Normal file
29
Uriagekun/Views/Record/Register.cshtml
Normal file
@ -0,0 +1,29 @@
|
||||
@{
|
||||
ViewData["Title"] = "売上登録";
|
||||
}
|
||||
|
||||
<div class="container-fluid">
|
||||
<form method="post" asp-action="Add" asp-controller="Record">
|
||||
<div class="form-group row m-2">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label" for="goodBarcode">バーコード</label>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<input type="text" minlength="0" maxlength="16" required name="Barcode" class="form-control" id="goodBarcode" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row m-2">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label" for="goodCount">売上個数</label>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<input type="number" min="0" required name="Count" class="form-control" id="goodCount" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row m-2">
|
||||
<div class="col-md-9 offset-md-3">
|
||||
<button type="submit" class="btn btn-block btn-outline-primary">登録</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@ -23,10 +23,10 @@
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">ホーム</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Good" asp-action="Index">商品管理</a>
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Goods" asp-action="Index">商品管理</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Record" asp-action="Register">売上登録</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user