Add good list
This commit is contained in:
parent
216944ae66
commit
d3a35a4fe2
@ -20,7 +20,7 @@ public class GoodController : Controller
|
||||
|
||||
public async Task<IActionResult> Add(AddGoodModel model)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
@ -34,7 +34,13 @@ public class GoodController : Controller
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
await this.repository.AddGoods(model.Label, model.Barcode, model.Price);
|
||||
await this.repository.AddGoods(model.Label, model.Barcode, model.Price).ConfigureAwait(false);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> List()
|
||||
{
|
||||
var ret = await this.repository.GetGoods(0, 100).ConfigureAwait(false);
|
||||
return Json(ret);
|
||||
}
|
||||
}
|
||||
|
||||
7
Uriagekun/Lib/Data/RangeData.cs
Normal file
7
Uriagekun/Lib/Data/RangeData.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Uriagekun.Lib.Data;
|
||||
|
||||
public class RangeData
|
||||
{
|
||||
public int Start { get; set; }
|
||||
public int End { get; set; }
|
||||
}
|
||||
@ -32,6 +32,27 @@ public class MyRepository
|
||||
return (int) ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DBに登録されている商品の一覧から指定範囲を取得します。
|
||||
/// </summary>
|
||||
/// <param name="offset"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
public async ValueTask<List<GoodData>> GetGoods(int offset, int count)
|
||||
{
|
||||
var range = new RangeData()
|
||||
{
|
||||
Start = offset,
|
||||
End = offset + count,
|
||||
};
|
||||
|
||||
var ret = await this.database.FetchAsync<GoodData>(
|
||||
$"SELECT * FROM goods WHERE id BETWEEN @Start And @End",
|
||||
range
|
||||
).ConfigureAwait(false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指定商品の売上個数を登録します。
|
||||
/// </summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user