api คำขอโอน
This commit is contained in:
parent
f878ef239e
commit
f255b1e933
15 changed files with 13056 additions and 42 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Application.Requests
|
||||
{
|
||||
|
|
@ -14,6 +15,7 @@ namespace BMA.EHR.Application.Requests
|
|||
|
||||
public string Amount { get; set; }
|
||||
|
||||
public string Type { get; set; }
|
||||
// public string Type { get; set; }
|
||||
public FormFile? File { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using BMA.EHR.Domain.Models.Base;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using BMA.EHR.Domain.Models.Documents;
|
||||
|
||||
namespace BMA.EHR.Domain.Models.Insignias
|
||||
{
|
||||
|
|
@ -21,6 +22,7 @@ namespace BMA.EHR.Domain.Models.Insignias
|
|||
|
||||
[MaxLength(10)]
|
||||
public string Type { get; set; }
|
||||
public Document? ReliefDoc { get; set; }
|
||||
|
||||
public virtual List<InsigniaRequest> InsigniaRequests { get; set; }
|
||||
}
|
||||
|
|
|
|||
43
BMA.EHR.Domain/Models/Placement/PlacementReceive.cs
Normal file
43
BMA.EHR.Domain/Models/Placement/PlacementReceive.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using BMA.EHR.Domain.Models.Base;
|
||||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using BMA.EHR.Domain.Models.Organizations;
|
||||
|
||||
namespace BMA.EHR.Domain.Models.Placement
|
||||
{
|
||||
public class PlacementReceive : EntityBase
|
||||
{
|
||||
[Required, MaxLength(20), Comment("เลขประจำตัวประชาชน")]
|
||||
public string CitizenId { get; set; }
|
||||
[Required, Comment("คำนำหน้า")]
|
||||
public Prefix Prefix { get; set; }
|
||||
[Required, Comment("ชื่อ")]
|
||||
public string Firstname { get; set; }
|
||||
[Required, Comment("นามสกุล")]
|
||||
public string Lastname { get; set; }
|
||||
[MaxLength(40), Comment("วันเกิด")]
|
||||
public DateTime DateOfBirth { get; set; }
|
||||
[Comment("Id เพศ")]
|
||||
public Gender? Gender { get; set; }
|
||||
[MaxLength(100), Comment("สัญชาติ")]
|
||||
public string? Nationality { get; set; }
|
||||
[MaxLength(100), Comment("เชื้อชาติ")]
|
||||
public string? Race { get; set; }
|
||||
[Comment("Id ศาสนา")]
|
||||
public Religion? Religion { get; set; }
|
||||
[Comment("Id กลุ่มเลือด")]
|
||||
public BloodGroup? BloodGroup { get; set; }
|
||||
[Comment("Id สถานะภาพ")]
|
||||
public Relationship? Relationship { get; set; }
|
||||
[MaxLength(50), Comment("เบอร์โทร")]
|
||||
public string? TelephoneNumber { get; set; }
|
||||
[Comment("สถานะคำขอ")]
|
||||
public string Status { get; set; } = "PENDING";
|
||||
[Comment("Id ตำแหน่ง")]
|
||||
public OrganizationEntity? Organization { get; set; }
|
||||
[Comment("สถานะการใช้งาน")]
|
||||
public bool IsActive { get; set; } = true;
|
||||
public virtual List<PlacementReceiveDoc> PlacementReceiveDocs { get; set; } = new List<PlacementReceiveDoc>();
|
||||
}
|
||||
}
|
||||
15
BMA.EHR.Domain/Models/Placement/PlacementReceiveDoc.cs
Normal file
15
BMA.EHR.Domain/Models/Placement/PlacementReceiveDoc.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using BMA.EHR.Domain.Models.Base;
|
||||
using BMA.EHR.Domain.Models.Documents;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BMA.EHR.Domain.Models.Placement
|
||||
{
|
||||
public class PlacementReceiveDoc : EntityBase
|
||||
{
|
||||
[Required, Comment("อ้างอิงรหัสเอกสาร")]
|
||||
public Document Document { get; set; }
|
||||
[Required, Comment("อ้างอิงรับโอน")]
|
||||
public virtual PlacementReceive PlacementReceive { get; set; }
|
||||
}
|
||||
}
|
||||
22
BMA.EHR.Domain/Models/Placement/PlacementTransfer.cs
Normal file
22
BMA.EHR.Domain/Models/Placement/PlacementTransfer.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using BMA.EHR.Domain.Models.Base;
|
||||
using BMA.EHR.Domain.Models.HR;
|
||||
|
||||
namespace BMA.EHR.Domain.Models.Placement
|
||||
{
|
||||
public class PlacementTransfer : EntityBase
|
||||
{
|
||||
[Required, Comment("Id ผู้ขอโอน")]
|
||||
public Profile Profile { get; set; }
|
||||
[Comment("หน่วยงานที่ขอโอนไป")]
|
||||
public string? Organization { get; set; } = string.Empty;
|
||||
[Comment("เหตุผล")]
|
||||
public string? Reason { get; set; } = string.Empty;
|
||||
[Comment("สถานะคำขอ")]
|
||||
public string Status { get; set; } = "PENDING";
|
||||
[Comment("สถานะการใช้งาน")]
|
||||
public bool IsActive { get; set; } = true;
|
||||
public virtual List<PlacementTransferDoc> PlacementTransferDocs { get; set; } = new List<PlacementTransferDoc>();
|
||||
}
|
||||
}
|
||||
15
BMA.EHR.Domain/Models/Placement/PlacementTransferDoc.cs
Normal file
15
BMA.EHR.Domain/Models/Placement/PlacementTransferDoc.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using BMA.EHR.Domain.Models.Base;
|
||||
using BMA.EHR.Domain.Models.Documents;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BMA.EHR.Domain.Models.Placement
|
||||
{
|
||||
public class PlacementTransferDoc : EntityBase
|
||||
{
|
||||
[Required, Comment("อ้างอิงรหัสเอกสาร")]
|
||||
public Document Document { get; set; }
|
||||
[Required, Comment("อ้างอิงคำขอโอน")]
|
||||
public virtual PlacementTransfer PlacementTransfer { get; set; }
|
||||
}
|
||||
}
|
||||
12178
BMA.EHR.Infrastructure/Migrations/20230804053012_update insignia add doc.Designer.cs
generated
Normal file
12178
BMA.EHR.Infrastructure/Migrations/20230804053012_update insignia add doc.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace BMA.EHR.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class updateinsigniaadddoc : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "ReliefDocId",
|
||||
table: "InsigniaPeriods",
|
||||
type: "char(36)",
|
||||
nullable: true,
|
||||
collation: "ascii_general_ci");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_InsigniaPeriods_ReliefDocId",
|
||||
table: "InsigniaPeriods",
|
||||
column: "ReliefDocId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_InsigniaPeriods_Documents_ReliefDocId",
|
||||
table: "InsigniaPeriods",
|
||||
column: "ReliefDocId",
|
||||
principalTable: "Documents",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_InsigniaPeriods_Documents_ReliefDocId",
|
||||
table: "InsigniaPeriods");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_InsigniaPeriods_ReliefDocId",
|
||||
table: "InsigniaPeriods");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ReliefDocId",
|
||||
table: "InsigniaPeriods");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5145,6 +5145,9 @@ namespace BMA.EHR.Infrastructure.Migrations
|
|||
.HasMaxLength(200)
|
||||
.HasColumnType("varchar(200)");
|
||||
|
||||
b.Property<Guid?>("ReliefDocId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<DateTime>("StartDate")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
|
|
@ -5158,6 +5161,8 @@ namespace BMA.EHR.Infrastructure.Migrations
|
|||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ReliefDocId");
|
||||
|
||||
b.ToTable("InsigniaPeriods");
|
||||
});
|
||||
|
||||
|
|
@ -11313,6 +11318,15 @@ namespace BMA.EHR.Infrastructure.Migrations
|
|||
b.Navigation("ProfileTraining");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Insignias.InsigniaPeriod", b =>
|
||||
{
|
||||
b.HasOne("BMA.EHR.Domain.Models.Documents.Document", "ReliefDoc")
|
||||
.WithMany()
|
||||
.HasForeignKey("ReliefDocId");
|
||||
|
||||
b.Navigation("ReliefDoc");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BMA.EHR.Domain.Models.Insignias.InsigniaRequest", b =>
|
||||
{
|
||||
b.HasOne("BMA.EHR.Domain.Models.Organizations.OrganizationEntity", "Organization")
|
||||
|
|
|
|||
|
|
@ -250,6 +250,10 @@ namespace BMA.EHR.Infrastructure.Persistence
|
|||
public DbSet<PlacementIsProperty> PlacementIsProperties { get; set; }
|
||||
public DbSet<PlacementProfile> PlacementProfiles { get; set; }
|
||||
public DbSet<PlacementType> PlacementTypes { get; set; }
|
||||
public DbSet<PlacementTransfer> PlacementTransfers { get; set; }
|
||||
public DbSet<PlacementReceive> PlacementReceives { get; set; }
|
||||
public DbSet<PlacementTransferDoc> PlacementTransferDocs { get; set; }
|
||||
public DbSet<PlacementReceiveDoc> PlacementReceiveDocs { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -438,7 +438,7 @@ namespace BMA.EHR.OrganizationEmployee.Service.Controllers
|
|||
return Success();
|
||||
}
|
||||
|
||||
[HttpGet("position/{profileId:length(36)}")]
|
||||
[HttpGet("position/profile/{profileId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetPositionEmployeeByProfile(Guid profileId)
|
||||
{
|
||||
var profile = await _context.Profiles.FindAsync(profileId);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,271 @@
|
|||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Extensions;
|
||||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using BMA.EHR.Domain.Models.Placement;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using BMA.EHR.Placement.Service.Requests;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace BMA.EHR.Placement.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/placement/receive")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("ระบบรับโอน")]
|
||||
public class PlacementReceiveController : BaseController
|
||||
{
|
||||
private readonly PlacementRepository _repository;
|
||||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public PlacementReceiveController(PlacementRepository repository,
|
||||
ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_repository = repository;
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
#region " Properties "
|
||||
|
||||
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||
|
||||
private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
|
||||
|
||||
#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 insigniaPeriods = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Where(x => x.Type == type)
|
||||
.OrderByDescending(x => x.Year)
|
||||
.ThenByDescending(x => x.StartDate)
|
||||
.Select(p => new
|
||||
{
|
||||
period_id = p.Id,
|
||||
period_amount = p.Amount,
|
||||
period_name = p.Name,
|
||||
period_start = p.StartDate,
|
||||
period_end = p.EndDate,
|
||||
period_year = p.Year,
|
||||
period_doc = p.ReliefDoc == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.ReliefDoc.Id,
|
||||
})
|
||||
.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_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 = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Where(x => x.Id == id)
|
||||
.Select(p => new
|
||||
{
|
||||
period_id = p.Id,
|
||||
period_amount = p.Amount,
|
||||
period_name = p.Name,
|
||||
period_start = p.StartDate,
|
||||
period_end = p.EndDate,
|
||||
period_year = p.Year,
|
||||
period_doc = p.ReliefDoc == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.ReliefDoc.Id,
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
if (data == null)
|
||||
return Error(GlobalMessages.DataNotFound, 404);
|
||||
|
||||
var _data = new
|
||||
{
|
||||
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_year = data.period_year,
|
||||
period_doc = data.period_doc == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.period_doc),
|
||||
};
|
||||
|
||||
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 = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Include(x => x.ReliefDoc)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (deleted == null)
|
||||
return NotFound();
|
||||
_context.InsigniaPeriods.Remove(deleted);
|
||||
await _context.SaveChangesAsync();
|
||||
if (deleted.ReliefDoc != null)
|
||||
await _documentService.DeleteFileAsync(deleted.ReliefDoc.Id);
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <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 = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Include(x => x.ReliefDoc)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (uppdated == null)
|
||||
return NotFound();
|
||||
|
||||
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;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,268 @@
|
|||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Extensions;
|
||||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using BMA.EHR.Domain.Models.Placement;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using BMA.EHR.Placement.Service.Requests;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace BMA.EHR.Placement.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/placement/transfer")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("ระบบคำขอโอน")]
|
||||
public class PlacementTransferController : BaseController
|
||||
{
|
||||
private readonly PlacementRepository _repository;
|
||||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public PlacementTransferController(PlacementRepository repository,
|
||||
ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_repository = repository;
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
#region " Properties "
|
||||
|
||||
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||
|
||||
private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// list คำขอโอนของ User
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("user")]
|
||||
public async Task<ActionResult<ResponseObject>> GetListByProfile()
|
||||
{
|
||||
var profile = await _context.Profiles
|
||||
.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId));
|
||||
if (profile == null)
|
||||
return Error(GlobalMessages.DataNotFound, 404);
|
||||
|
||||
var placementTransfers = await _context.PlacementTransfers.AsQueryable()
|
||||
.Where(x => x.Profile == profile)
|
||||
.Select(p => new
|
||||
{
|
||||
p.Id,
|
||||
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : p.Profile.PositionEmployeePosition,
|
||||
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
|
||||
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : p.Profile.PositionEmployeeLevel,
|
||||
salary = 10000,
|
||||
p.CreatedAt,
|
||||
p.Organization,
|
||||
p.Reason,
|
||||
p.Status,
|
||||
p.IsActive,
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return Success(placementTransfers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// list คำขอโอนของ Admin
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet()]
|
||||
public async Task<ActionResult<ResponseObject>> GetListByAdmin()
|
||||
{
|
||||
|
||||
var placementTransfers = await _context.PlacementTransfers.AsQueryable()
|
||||
.Select(p => new
|
||||
{
|
||||
p.Id,
|
||||
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : p.Profile.PositionEmployeePosition,
|
||||
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
|
||||
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : p.Profile.PositionEmployeeLevel,
|
||||
salary = 10000,
|
||||
p.CreatedAt,
|
||||
p.Organization,
|
||||
p.Reason,
|
||||
p.Status,
|
||||
p.IsActive,
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return Success(placementTransfers);
|
||||
}
|
||||
|
||||
/// <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("user/{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetDetailByUser(Guid id)
|
||||
{
|
||||
var data = await _context.PlacementTransfers.AsQueryable()
|
||||
.Where(x => x.Id == id)
|
||||
.Where(x => x.Profile != null)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : p.Profile.PositionEmployeePosition,
|
||||
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
|
||||
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : p.Profile.PositionEmployeeLevel,
|
||||
organizationOrganization = p.Profile.OrganizationOrganization,
|
||||
Reason = p.Reason,
|
||||
Status = p.Status,
|
||||
Organization = p.Organization,
|
||||
CreatedAt = p.CreatedAt,
|
||||
// doc = p.ReliefDoc == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.ReliefDoc.Id,
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
if (data == null)
|
||||
return Error(GlobalMessages.DataNotFound, 404)
|
||||
|
||||
var _data = new
|
||||
{
|
||||
Id = data.Id,
|
||||
Reason = data.Reason,
|
||||
Status = data.Status,
|
||||
Organization = data.Organization,
|
||||
CreatedAt = data.CreatedAt,
|
||||
// period_doc = data.period_doc == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.period_doc),
|
||||
};
|
||||
|
||||
return Success(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สร้างคำขอโอน
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost()]
|
||||
public async Task<ActionResult<ResponseObject>> Post([FromForm] PlacementTransferRequest req)
|
||||
{
|
||||
var profile = await _context.Profiles
|
||||
.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId));
|
||||
if (profile == null)
|
||||
return Error(GlobalMessages.DataNotFound, 404);
|
||||
|
||||
var placementTransfer = new PlacementTransfer
|
||||
{
|
||||
Profile = profile,
|
||||
Organization = Request.Form.ContainsKey("Organization") ? Request.Form["Organization"] : "",
|
||||
Reason = Request.Form.ContainsKey("Reason") ? Request.Form["Reason"] : "",
|
||||
Status = "PENDING",
|
||||
CreatedUserId = FullName ?? "",
|
||||
CreatedFullName = UserId ?? "System Administrator",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
};
|
||||
await _context.PlacementTransfers.AddAsync(placementTransfer);
|
||||
await _context.SaveChangesAsync();
|
||||
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
|
||||
{
|
||||
foreach (var file in Request.Form.Files)
|
||||
{
|
||||
var fileExtension = Path.GetExtension(file.FileName);
|
||||
|
||||
var doc = await _documentService.UploadFileAsync(file, file.FileName);
|
||||
var placementTransferDoc = new PlacementTransferDoc
|
||||
{
|
||||
PlacementTransfer = placementTransfer,
|
||||
Document = doc,
|
||||
CreatedUserId = FullName ?? "",
|
||||
CreatedFullName = UserId ?? "System Administrator",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
};
|
||||
await _context.PlacementTransferDocs.AddAsync(placementTransferDoc);
|
||||
}
|
||||
}
|
||||
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>
|
||||
[HttpGet("confirm/{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Confirm(Guid id)
|
||||
{
|
||||
if (req == null)
|
||||
return BadRequest();
|
||||
|
||||
var uppdated = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Include(x => x.ReliefDoc)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (uppdated == null)
|
||||
return NotFound();
|
||||
|
||||
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;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Placement.Service.Requests
|
||||
{
|
||||
public class PlacementTransferRequest
|
||||
{
|
||||
public string Organization { get; set; }
|
||||
public string Reason { get; set; }
|
||||
public List<FormFile>? File { get; set; }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue