557 lines
30 KiB
C#
557 lines
30 KiB
C#
using BMA.EHR.Application.Repositories;
|
|
using BMA.EHR.Application.Repositories.MessageQueue;
|
|
using BMA.EHR.Discipline.Service.Requests;
|
|
using BMA.EHR.Domain.Common;
|
|
using BMA.EHR.Domain.Models.Discipline;
|
|
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;
|
|
|
|
namespace BMA.EHR.DisciplineComplaint.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/discipline/complaint")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("ระบบวินัยเรื่องร้องเรียน")]
|
|
public class DisciplineComplaintController : BaseController
|
|
{
|
|
private readonly DisciplineDbContext _context;
|
|
private readonly MinIODisciplineService _documentService;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly NotificationRepository _repositoryNoti;
|
|
|
|
public DisciplineComplaintController(DisciplineDbContext context,
|
|
MinIODisciplineService documentService,
|
|
NotificationRepository repositoryNoti,
|
|
IHttpContextAccessor httpContextAccessor)
|
|
{
|
|
// _repository = repository;
|
|
_context = context;
|
|
_documentService = documentService;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_repositoryNoti = repositoryNoti;
|
|
}
|
|
|
|
#region " Properties "
|
|
|
|
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
|
|
|
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// list รายการวินัยเรื่องร้องเรียน
|
|
/// </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>> GetDisciplineComplaint(int page = 1, int pageSize = 25, string keyword = "")
|
|
{
|
|
var data_search = (from x in _context.DisciplineComplaints
|
|
where x.Title.Contains(keyword) ||
|
|
x.Appellant.Contains(keyword)
|
|
select x).ToList();
|
|
var data = data_search
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องร้องเรียน
|
|
Title = x.Title,//ชื่อเรื่อง
|
|
RespondentType = x.RespondentType,
|
|
Appellant = x.Appellant,//ผู้ถูกร้องเรียน
|
|
OffenseDetails = x.OffenseDetails,//ลักษณะความผิด
|
|
CreatedAt = x.CreatedAt,//วันที่สร้างเรื่องร้องเรียน
|
|
LevelConsideration = x.LevelConsideration,//ระดับการพิจารณา
|
|
DateConsideration = x.DateConsideration,//วันที่กำหนดพิจารณา
|
|
DateReceived = x.DateReceived,//วันที่รับเรื่อง
|
|
Status = x.Status,//สถานะเรื่องร้องเรียน มีดังนี้ ใหม่ (NEW), ยุติเรื่อง (STOP), มีมูลส่งไปสืบสวนแล้ว (SEND_INVESTIGATE)
|
|
Result = x.Result,
|
|
})
|
|
.OrderByDescending(x => x.CreatedAt)
|
|
.Skip((page - 1) * pageSize)
|
|
.Take(pageSize)
|
|
.ToList();
|
|
return Success(new { data, total = data_search.Count() });
|
|
}
|
|
|
|
/// <summary>
|
|
/// get รายการวินัยเรื่องร้องเรียน
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> GetByDisciplineComplaint(Guid id)
|
|
{
|
|
var _data = await _context.DisciplineComplaints
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องร้องเรียน
|
|
RespondentType = x.RespondentType,//ผู้ถูกร้องเรียน
|
|
Persons = x.DisciplineComplaint_Profiles.Select(p => new
|
|
{
|
|
Id = p.Id,
|
|
Idcard = p.CitizenId,
|
|
Name = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
|
Prefix = p.Prefix,
|
|
FirstName = p.FirstName,
|
|
LastName = p.LastName,
|
|
Position = p.Position,
|
|
PositionLevel = p.PositionLevel,
|
|
Salary = p.Salary,
|
|
PersonId = p.PersonId,
|
|
PosNo = p.PosNo,
|
|
Organization = p.Organization,
|
|
}),//รายการข้อมูลบุคลผู้ถูกร้องเรียน
|
|
OrganizationId = x.Organization,//id หน่วยงานกรณี type เป็นหน่วยงาน
|
|
ConsideredAgency = x.ConsideredAgency,//หน่วยงานที่พิจารณา จะเปลี่ยนไปตามผู้ถูกร้องดูรายละเอียดด้านล่าง
|
|
Title = x.Title,//ชื่อเรื่อง
|
|
Description = x.Description,//รายละเอียด
|
|
DateReceived = x.DateReceived,//วันที่รับเรื่อง
|
|
LevelConsideration = x.LevelConsideration,//ระดับการพัฒนา
|
|
DateConsideration = x.DateConsideration,//วันที่กำหนดพิจารณา
|
|
OffenseDetails = x.OffenseDetails,//ลักษณะความผิด
|
|
DateNotification = x.DateNotification,//วันแจ้งเตือนล่วงหน้า
|
|
ComplaintFrom = x.ComplaintFrom,//รับเรื่องร้องเรียนจาก
|
|
Appellant = x.Appellant,//ผู้ถูกร้องเรียน
|
|
Status = x.Status,//สถานะเรื่องร้องเรียน มีดังนี้ ใหม่ (NEW), ยุติเรื่อง (STOP), มีมูลส่งไปสืบสวนแล้ว (SEND_INVESTIGATE)
|
|
Result = x.Result,
|
|
DisciplineComplaintDocs = x.DisciplineComplaint_Docs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
|
|
})
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (_data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
|
|
var disciplineComplaintDocs = new List<dynamic>();
|
|
foreach (var doc in _data.DisciplineComplaintDocs)
|
|
{
|
|
var _doc = new
|
|
{
|
|
doc.Id,
|
|
doc.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Id)
|
|
};
|
|
disciplineComplaintDocs.Add(_doc);
|
|
}
|
|
var data = new
|
|
{
|
|
_data.Id,
|
|
_data.RespondentType,
|
|
_data.Persons,
|
|
_data.OrganizationId,
|
|
_data.ConsideredAgency,
|
|
_data.Title,
|
|
_data.Description,
|
|
_data.DateReceived,
|
|
_data.LevelConsideration,
|
|
_data.DateConsideration,
|
|
_data.OffenseDetails,
|
|
_data.DateNotification,
|
|
_data.ComplaintFrom,
|
|
_data.Appellant,
|
|
_data.Status,
|
|
_data.Result,
|
|
disciplineComplaintDocs,
|
|
};
|
|
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>> CreateDisciplineComplaint([FromBody] DisciplineComplaintRequest req)
|
|
{
|
|
var disciplineComplaint = new Domain.Models.Discipline.DisciplineComplaint
|
|
{
|
|
RespondentType = req.respondentType.Trim().ToUpper(),
|
|
Organization = req.organizationId,
|
|
ConsideredAgency = req.consideredAgency,
|
|
Title = req.title,
|
|
Description = req.description,
|
|
DateReceived = req.dateReceived,
|
|
LevelConsideration = req.levelConsideration.Trim().ToUpper(),
|
|
DateConsideration = req.dateConsideration,
|
|
OffenseDetails = req.offenseDetails.Trim().ToUpper(),
|
|
DateNotification = req.dateNotification,
|
|
ComplaintFrom = req.complaintFrom,
|
|
Appellant = req.appellant,
|
|
Result = req.result,
|
|
Status = "NEW",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
foreach (var item in req.persons)
|
|
{
|
|
disciplineComplaint.DisciplineComplaint_Profiles.Add(
|
|
new DisciplineComplaint_Profile
|
|
{
|
|
PersonId = item.personId,
|
|
CitizenId = item.idcard,
|
|
Prefix = item.prefix,
|
|
FirstName = item.firstName,
|
|
LastName = item.lastName,
|
|
Organization = item.organization,
|
|
Salary = item.salary,
|
|
PosNo = item.posNo,
|
|
Position = item.position,
|
|
PositionLevel = item.positionLevel,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
await _repositoryNoti.PushNotificationAsync(
|
|
Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"),
|
|
$"มีคำขอร้องเรียนเรื่อง {req.title}",
|
|
$"มีคำขอร้องเรียนเรื่อง {req.title}",
|
|
"",
|
|
true,
|
|
true
|
|
);
|
|
await _context.DisciplineComplaints.AddAsync(disciplineComplaint);
|
|
await _context.SaveChangesAsync();
|
|
return Success(disciplineComplaint.Id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// แก้ไขรายการวินัยเรื่องร้องเรียน
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> UpdateDisciplineComplaint([FromBody] DisciplineComplaintRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineComplaints.Include(x => x.DisciplineComplaint_Profiles).Where(x => x.Id == id).FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
|
|
|
|
data.RespondentType = req.respondentType.Trim().ToUpper();
|
|
data.Organization = req.organizationId;
|
|
data.ConsideredAgency = req.consideredAgency;
|
|
data.Title = req.title;
|
|
data.Description = req.description;
|
|
data.DateReceived = req.dateReceived;
|
|
data.LevelConsideration = req.levelConsideration.Trim().ToUpper();
|
|
data.DateConsideration = req.dateConsideration;
|
|
data.OffenseDetails = req.offenseDetails.Trim().ToUpper();
|
|
data.DateNotification = req.dateNotification;
|
|
data.ComplaintFrom = req.complaintFrom;
|
|
data.Appellant = req.appellant;
|
|
data.Result = req.result;
|
|
data.LastUpdateFullName = FullName ?? "System Administrator";
|
|
data.LastUpdateUserId = UserId ?? "";
|
|
data.LastUpdatedAt = DateTime.Now;
|
|
_context.DisciplineComplaint_Profiles.RemoveRange(data.DisciplineComplaint_Profiles);
|
|
if (data.RespondentType.Trim().ToUpper() == "PERSON")
|
|
{
|
|
foreach (var item in req.persons)
|
|
{
|
|
data.DisciplineComplaint_Profiles.Add(
|
|
new DisciplineComplaint_Profile
|
|
{
|
|
CitizenId = item.idcard,
|
|
Prefix = item.prefix,
|
|
FirstName = item.firstName,
|
|
LastName = item.lastName,
|
|
Organization = item.organization,
|
|
Position = item.position,
|
|
PositionLevel = item.positionLevel,
|
|
Salary = item.salary,
|
|
PersonId = item.personId,
|
|
PosNo = item.posNo,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
}
|
|
);
|
|
}
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
return Success(data.Id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// ลบรายการวินัยเรื่องร้องเรียน
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpDelete("{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> DeleteDisciplineComplaint(Guid id)
|
|
{
|
|
var data = await _context.DisciplineComplaints
|
|
// .Include(x=>x.Document)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
_context.DisciplineComplaints.Remove(data);
|
|
// var _docId = data.Document.Id;
|
|
// await _context.SaveChangesAsync();
|
|
// await _documentService.DeleteFileAsync(_docId);
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ยุติเรื่อง
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("reject/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> RejectDisciplineComplaint(Guid id)
|
|
{
|
|
var data = await _context.DisciplineComplaints
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถยุติเรื่องได้"), StatusCodes.Status500InternalServerError);
|
|
data.Status = "STOP";
|
|
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ส่งเรื่องสอบสวน
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("approve/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> ApproveDisciplineComplaint([FromBody] DisciplinePersonIdRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineComplaints
|
|
.Include(x => x.DisciplineComplaint_Profiles)
|
|
.Include(x => x.DisciplineComplaint_Docs)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.DisciplineInvestigates)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถส่งต่อไปสืบสวนได้"), StatusCodes.Status500InternalServerError);
|
|
data.Status = "SEND_INVESTIGATE";
|
|
|
|
var disciplineInvestigate = new Domain.Models.Discipline.DisciplineInvestigate
|
|
{
|
|
RespondentType = data.RespondentType.Trim().ToUpper(),
|
|
Organization = data.Organization,
|
|
ConsideredAgency = data.ConsideredAgency,
|
|
Title = data.Title,
|
|
Description = data.Description,
|
|
DateReceived = data.DateReceived,
|
|
LevelConsideration = data.LevelConsideration.Trim().ToUpper(),
|
|
DateConsideration = data.DateConsideration,
|
|
OffenseDetails = data.OffenseDetails.Trim().ToUpper(),
|
|
DateNotification = data.DateNotification,
|
|
ComplaintFrom = data.ComplaintFrom,
|
|
Appellant = data.Appellant,
|
|
ResultComplaint = data.Result,
|
|
|
|
InvestigationStatusResult = "NOT_SPECIFIED",
|
|
InvestigationExtendStatus = false,
|
|
Status = "NEW",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
var persons = data.DisciplineComplaint_Profiles.Where(x => req.persons.Contains(x.Id)).ToList();
|
|
foreach (var item in persons)
|
|
{
|
|
disciplineInvestigate.DisciplineInvestigate_ProfileComplaints.Add(
|
|
new DisciplineInvestigate_ProfileComplaint
|
|
{
|
|
PersonId = item.PersonId,
|
|
CitizenId = item.CitizenId,
|
|
Prefix = item.Prefix,
|
|
FirstName = item.FirstName,
|
|
LastName = item.LastName,
|
|
Organization = item.Organization,
|
|
Salary = item.Salary,
|
|
PosNo = item.PosNo,
|
|
Position = item.Position,
|
|
PositionLevel = item.PositionLevel,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
foreach (var item in data.DisciplineComplaint_Docs)
|
|
{
|
|
disciplineInvestigate.DisciplineInvestigate_DocComplaints.Add(
|
|
new DisciplineInvestigate_DocComplaint
|
|
{
|
|
Document = item.Document,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
|
|
data.DisciplineInvestigates.Add(disciplineInvestigate);
|
|
await _context.SaveChangesAsync();
|
|
return Success(disciplineInvestigate.Id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// ยกเลิกการยุติเรื่อง
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("resume/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> ResumeDisciplineComplaint(Guid id)
|
|
{
|
|
var data = await _context.DisciplineComplaints
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "STOP")
|
|
return Error(new Exception("รายการนี้ยังไม่ถูกยุติเรื่อง"), StatusCodes.Status500InternalServerError);
|
|
data.Status = "NEW";
|
|
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// อัพไฟล์เอกสารร้องเรียนวินัย
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("file/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> UploadFileDisciplineComplaint([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineComplaints
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
|
|
|
|
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 _doc = await _context.Documents.AsQueryable()
|
|
.FirstOrDefaultAsync(x => x.Id == doc.Id);
|
|
if (_doc != null)
|
|
{
|
|
var disciplineComplaint_Doc = new DisciplineComplaint_Doc
|
|
{
|
|
DisciplineComplaint = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineComplaint_Docs.AddAsync(disciplineComplaint_Doc);
|
|
}
|
|
}
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ลบไฟล์เอกสารร้องเรียนวินัย
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpDelete("file/{id:guid}/{docId:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> DeleteFileDisciplineComplaint(Guid id, Guid docId)
|
|
{
|
|
var data = await _context.DisciplineComplaints
|
|
.Include(x => x.DisciplineComplaint_Docs)
|
|
.ThenInclude(x => x.Document)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
|
|
var dataDoc = data.DisciplineComplaint_Docs.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineComplaint_Docs.Remove(dataDoc);
|
|
await _context.SaveChangesAsync();
|
|
await _documentService.DeleteFileAsync(docId);
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
else
|
|
{
|
|
return Error(new Exception("ไม่พบไฟล์นี้ในระบบ"), (int)StatusCodes.Status404NotFound);
|
|
}
|
|
}
|
|
}
|
|
}
|