Add good list

This commit is contained in:
Sakurai Ryota 2025-02-09 11:05:45 +09:00
parent 26c5b72339
commit e4d1ba38df
10 changed files with 24 additions and 22 deletions

View File

@ -28,13 +28,12 @@ public class GoodsController : Controller
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).ConfigureAwait(false);
await this.repository.AddGoods(model.Label, model.Barcode).ConfigureAwait(false);
return RedirectToAction("Index");
}

View File

@ -28,6 +28,7 @@ public class RecordController : Controller
if (
string.IsNullOrEmpty(model.Barcode) || model.Barcode.Length > 16
|| model.Count < 0
|| model.Price < 0
)
{
return BadRequest();
@ -44,7 +45,7 @@ public class RecordController : Controller
int month = from.Month;
int day = from.Day;
var date = new DateTime(year, month, day);
await this.repository.AddRegister(good.Id, model.Count, date).ConfigureAwait(false);
await this.repository.AddRegister(good.Id, model.Count, model.Price, date).ConfigureAwait(false);
return RedirectToAction("Register");
}

View File

@ -14,7 +14,4 @@ public class GoodData
[Column(Name = "label"), StringLength(40)]
public string Label { get; set; }
[Column(Name = "price")]
public int Price { get; set; }
}

View File

@ -16,6 +16,9 @@ public class GoodRegisterData
[Column(Name = "date")]
public DateTime Date { get; set; }
[Column(Name = "price")]
public int Price { get; set; }
[Column(Name = "count")]
public int Count { get; set; }
}

View File

@ -14,6 +14,9 @@ public class RegisterData
[Column(Name = "date")]
public DateTime Date { get; set; }
[Column(Name = "price")]
public int Price { get; set; }
[Column(Name = "count")]
public int Count { get; set; }
}

View File

@ -17,15 +17,13 @@ public class MyRepository
/// </summary>
/// <param name="label"></param>
/// <param name="barcode"></param>
/// <param name="price"></param>
/// <returns>正常終了時、商品IDを返します。</returns>
public async ValueTask<int> AddGoods(string label, string barcode, int price)
public async ValueTask<int> AddGoods(string label, string barcode)
{
GoodData data = new GoodData()
{
Label = label,
Barcode = barcode,
Price = price,
};
var ret = await this.database.InsertAsync(data).ConfigureAwait(false);
@ -74,13 +72,14 @@ public class MyRepository
/// <param name="count"></param>
/// <param name="date"></param>
/// <returns></returns>
public async ValueTask AddRegister(int goodId, int count, DateTime date)
public async ValueTask AddRegister(int goodId, int count, int price, DateTime date)
{
RegisterData data = new RegisterData()
{
GoodId = goodId,
Date = date,
Count = count,
Price = price,
};
await this.database.InsertAsync(data).ConfigureAwait(false);
@ -89,7 +88,7 @@ public class MyRepository
public async ValueTask<List<GoodRegisterData>> GetGoodRegisterFromBarcode(string barcode)
{
var ret = await this.database.FetchAsync<GoodRegisterData>(
$"SELECT goods.good_id, goods.barcode, goods.label, registers.date, registers.count FROM goods, registers WHERE barcode = {barcode} AND goods.good_id = registers.good_id"
$"SELECT goods.good_id, goods.barcode, goods.label, registers.date, registers.price, registers.count FROM goods, registers WHERE barcode = {barcode} AND goods.good_id = registers.good_id"
).ConfigureAwait(false);
return ret;

View File

@ -9,7 +9,4 @@ public class AddGoodModel
[Required]
public string Label { get; set; }
[Required]
public int Price { get; set; }
}

View File

@ -7,6 +7,9 @@ public class AddUriageModel
[Required]
public string Barcode { get; set; }
[Required]
public int Price { get; set; }
[Required]
public int Count { get; set; }
}

View File

@ -22,14 +22,6 @@
<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="goodPrice">金額</label>
</div>
<div class="col-md-9">
<input type="number" min="0" required name="Price" class="form-control" id="goodPrice" />
</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>

View File

@ -12,6 +12,14 @@
<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="goodPrice">金額</label>
</div>
<div class="col-md-9">
<input type="number" min="0" required name="Price" class="form-control" id="goodPrice" />
</div>
</div>
<div class="form-group row m-2">
<div class="col-md-3">
<label class="form-label" for="goodCount">売上個数</label>