api คำขอโอน
This commit is contained in:
parent
f878ef239e
commit
f255b1e933
15 changed files with 13056 additions and 42 deletions
|
|
@ -7,6 +7,7 @@ using BMA.EHR.Domain.Shared;
|
|||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Controllers
|
||||
|
|
@ -43,10 +44,19 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// list รอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="type">ประเภทเครื่องราช(insignia=เครื่องราช,coin=เหรียญ)</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("{type}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetList(string type)
|
||||
{
|
||||
var data = _context.InsigniaPeriods.AsQueryable()
|
||||
var insigniaPeriods = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Where(x => x.Type == type)
|
||||
.OrderByDescending(x => x.Year)
|
||||
.ThenByDescending(x => x.StartDate)
|
||||
|
|
@ -58,17 +68,43 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
period_start = p.StartDate,
|
||||
period_end = p.EndDate,
|
||||
period_status = _repository.CalStatusByDate(p.StartDate, p.EndDate, p.Year.ToString()),
|
||||
period_year = p.Year
|
||||
period_year = p.Year,
|
||||
period_doc = p.ReliefDoc == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.ReliefDoc.Id,
|
||||
})
|
||||
.ToList();
|
||||
.ToListAsync();
|
||||
var data = new List<dynamic>();
|
||||
foreach (var insigniaPeriod in insigniaPeriods)
|
||||
{
|
||||
var _data = new
|
||||
{
|
||||
period_id = insigniaPeriod.period_id,
|
||||
period_amount = insigniaPeriod.period_amount,
|
||||
period_name = insigniaPeriod.period_name,
|
||||
period_start = insigniaPeriod.period_start,
|
||||
period_end = insigniaPeriod.period_end,
|
||||
period_status = insigniaPeriod.period_status,
|
||||
period_year = insigniaPeriod.period_year,
|
||||
period_doc = insigniaPeriod.period_doc == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(insigniaPeriod.period_doc),
|
||||
};
|
||||
data.Add(_data);
|
||||
}
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get รายละเอียดรอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="id">Id เครื่องราช</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetById(Guid id)
|
||||
{
|
||||
var data = _context.InsigniaPeriods.AsQueryable()
|
||||
var data = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Where(x => x.Id == id)
|
||||
.Select(p => new
|
||||
{
|
||||
|
|
@ -79,70 +115,152 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
period_end = p.EndDate,
|
||||
period_status = _repository.CalStatusByDate(p.StartDate, p.EndDate, p.Year.ToString()),
|
||||
period_year = p.Year,
|
||||
docs = new List<dynamic>()
|
||||
period_doc = p.ReliefDoc == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.ReliefDoc.Id,
|
||||
})
|
||||
.FirstOrDefault();
|
||||
.FirstOrDefaultAsync();
|
||||
if (data == null)
|
||||
return Error(GlobalMessages.DataNotFound, 404);
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
[HttpPost("{type}")]
|
||||
public async Task<ActionResult<ResponseObject>> Post([FromBody] InsigniaPeriodRequest req, string type)
|
||||
{
|
||||
if (req == null)
|
||||
return BadRequest();
|
||||
|
||||
var period = new InsigniaPeriod
|
||||
var _data = new
|
||||
{
|
||||
Name = req.Name,
|
||||
Year = req.Year,
|
||||
StartDate = req.StartDate,
|
||||
EndDate = req.EndDate,
|
||||
Amount = req.Amount,
|
||||
Type = type
|
||||
period_id = data.period_id,
|
||||
period_amount = data.period_amount,
|
||||
period_name = data.period_name,
|
||||
period_start = data.period_start,
|
||||
period_end = data.period_end,
|
||||
period_status = data.period_status,
|
||||
period_year = data.period_year,
|
||||
period_doc = data.period_doc == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.period_doc),
|
||||
};
|
||||
|
||||
_context.InsigniaPeriods.Add(period);
|
||||
_context.SaveChanges();
|
||||
return Success(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สร้างรอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="type">ประเภทเครื่องราช(insignia=เครื่องราช,coin=เหรียญ)</param>
|
||||
/// <param name="req.Name">ชื่อรอบ</param>
|
||||
/// <param name="req.Year">ปีที่เสนอ</param>
|
||||
/// <param name="req.StartDate">วันที่เริ่มต้น</param>
|
||||
/// <param name="req.EndDate">วันที่สิ้นสุด</param>
|
||||
/// <param name="req.Amount">จำนวนวันแจ้งเตือน</param>
|
||||
/// <param name="req.File">เอกสารประกอบ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost("{type}")]
|
||||
public async Task<ActionResult<ResponseObject>> Post([FromForm] InsigniaPeriodRequest req, string type)
|
||||
{
|
||||
var period = new InsigniaPeriod
|
||||
{
|
||||
Name = Request.Form.ContainsKey("Name") ? Request.Form["Name"] : "",
|
||||
Year = Request.Form.ContainsKey("Year") ? Int32.Parse(Request.Form["Year"]) : DateTime.Now.Year,
|
||||
StartDate = Request.Form.ContainsKey("StartDate") ? DateTime.Parse(Request.Form["StartDate"]) : DateTime.Now,
|
||||
EndDate = Request.Form.ContainsKey("EndDate") ? DateTime.Parse(Request.Form["EndDate"]) : DateTime.Now,
|
||||
Amount = Request.Form.ContainsKey("Amount") ? Request.Form["Amount"] : "",
|
||||
Type = type.Trim().ToUpper(),
|
||||
CreatedUserId = FullName ?? "",
|
||||
CreatedFullName = UserId ?? "System Administrator",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
};
|
||||
await _context.InsigniaPeriods.AddAsync(period);
|
||||
await _context.SaveChangesAsync();
|
||||
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
|
||||
{
|
||||
var file = Request.Form.Files[0];
|
||||
var fileExtension = Path.GetExtension(file.FileName);
|
||||
|
||||
var doc = await _documentService.UploadFileAsync(file, file.FileName);
|
||||
period.ReliefDoc = doc;
|
||||
}
|
||||
|
||||
// await _context.InsigniaPeriods.AddAsync(period);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ลบรอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="id">Id เครื่องราช</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpDelete("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Delete(Guid id)
|
||||
{
|
||||
var deleted = _context.InsigniaPeriods.AsQueryable()
|
||||
.FirstOrDefault(x => x.Id == id);
|
||||
var deleted = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Include(x => x.ReliefDoc)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (deleted == null)
|
||||
return NotFound();
|
||||
|
||||
_context.InsigniaPeriods.Remove(deleted);
|
||||
_context.SaveChanges();
|
||||
await _context.SaveChangesAsync();
|
||||
if (deleted.ReliefDoc != null)
|
||||
await _documentService.DeleteFileAsync(deleted.ReliefDoc.Id);
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
[HttpPut("{type}/{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Put([FromBody] InsigniaPeriodRequest req, Guid id, string type)
|
||||
/// <summary>
|
||||
/// แก้ไขรอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="id">Id เครื่องราช</param>
|
||||
/// <param name="req.Name">ชื่อรอบ</param>
|
||||
/// <param name="req.Year">ปีที่เสนอ</param>
|
||||
/// <param name="req.StartDate">วันที่เริ่มต้น</param>
|
||||
/// <param name="req.EndDate">วันที่สิ้นสุด</param>
|
||||
/// <param name="req.Amount">จำนวนวันแจ้งเตือน</param>
|
||||
/// <param name="req.File">เอกสารประกอบ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Put([FromForm] InsigniaPeriodRequest req, Guid id)
|
||||
{
|
||||
if (req == null)
|
||||
return BadRequest();
|
||||
|
||||
var uppdated = _context.InsigniaPeriods.AsQueryable()
|
||||
.FirstOrDefault(x => x.Id == id);
|
||||
var uppdated = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Include(x => x.ReliefDoc)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (uppdated == null)
|
||||
return NotFound();
|
||||
|
||||
uppdated.Name = req.Name;
|
||||
uppdated.Year = req.Year;
|
||||
uppdated.StartDate = req.StartDate;
|
||||
uppdated.EndDate = req.EndDate;
|
||||
uppdated.Amount = req.Amount;
|
||||
uppdated.Type = type;
|
||||
uppdated.Name = Request.Form.ContainsKey("Name") ? Request.Form["Name"] : "";
|
||||
uppdated.Year = Request.Form.ContainsKey("Year") ? Int32.Parse(Request.Form["Year"]) : DateTime.Now.Year;
|
||||
uppdated.StartDate = Request.Form.ContainsKey("StartDate") ? DateTime.Parse(Request.Form["StartDate"]) : DateTime.Now;
|
||||
uppdated.EndDate = Request.Form.ContainsKey("EndDate") ? DateTime.Parse(Request.Form["EndDate"]) : DateTime.Now;
|
||||
uppdated.Amount = Request.Form.ContainsKey("Amount") ? Request.Form["Amount"] : "";
|
||||
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
uppdated.LastUpdateUserId = UserId ?? "";
|
||||
uppdated.LastUpdatedAt = DateTime.Now;
|
||||
|
||||
_context.SaveChanges();
|
||||
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
|
||||
{
|
||||
if (uppdated.ReliefDoc != null)
|
||||
await _documentService.DeleteFileAsync(uppdated.ReliefDoc.Id);
|
||||
var file = Request.Form.Files[0];
|
||||
var fileExtension = Path.GetExtension(file.FileName);
|
||||
|
||||
var doc = await _documentService.UploadFileAsync(file, file.FileName);
|
||||
uppdated.ReliefDoc = doc;
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue