Add good list
This commit is contained in:
parent
143f825448
commit
849b1dbf16
31
Uriagekun/Controllers/GoodController.cs
Normal file
31
Uriagekun/Controllers/GoodController.cs
Normal file
@ -0,0 +1,31 @@
|
||||
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 async Task<IActionResult> View(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
var good = await this.repository.GetGoodRegisterFromBarcode(id);
|
||||
if (good is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return Json(good);
|
||||
}
|
||||
}
|
||||
@ -39,7 +39,12 @@ public class RecordController : Controller
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
await this.repository.AddRegister(good.Id, model.Count, DateTime.Now).ConfigureAwait(false);
|
||||
var from = DateTime.Now;
|
||||
int year = from.Year;
|
||||
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);
|
||||
|
||||
return RedirectToAction("Register");
|
||||
}
|
||||
|
||||
21
Uriagekun/Lib/Data/GoodRegisterData.cs
Normal file
21
Uriagekun/Lib/Data/GoodRegisterData.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using PetaPoco;
|
||||
|
||||
namespace Uriagekun.Lib.Data;
|
||||
|
||||
public class GoodRegisterData
|
||||
{
|
||||
[Column(Name = "good_id")]
|
||||
public int GoodId { get; set; }
|
||||
|
||||
[Column(Name = "barcode")]
|
||||
public string Barcode { get; set; }
|
||||
|
||||
[Column(Name = "label")]
|
||||
public string Label { get; set; }
|
||||
|
||||
[Column(Name = "date")]
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
[Column(Name = "count")]
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@ -85,4 +85,13 @@ public class MyRepository
|
||||
|
||||
await this.database.InsertAsync(data).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async ValueTask<List<GoodRegisterData>> GetGoodRegisterFromBarcode(string barcode)
|
||||
{
|
||||
var ret = await this.database.FetchAsync<GoodRegisterData>(
|
||||
$"SELECT good_id, barcode, label, date, count FROM goods, registers WHERE barcode = {barcode} AND goods.good_id = registers.good_id"
|
||||
).ConfigureAwait(false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user