996 lines
55 KiB
C#
996 lines
55 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.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
using System.Linq;
|
|
using System.Net.Http.Headers;
|
|
using System.Runtime.Serialization;
|
|
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;
|
|
private readonly PermissionRepository _permission;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly UserProfileRepository _userProfileRepository;
|
|
|
|
public DisciplineComplaintController(DisciplineDbContext context,
|
|
MinIODisciplineService documentService,
|
|
NotificationRepository repositoryNoti,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
IConfiguration configuration,
|
|
UserProfileRepository userProfileRepository,
|
|
PermissionRepository permission)
|
|
{
|
|
// _repository = repository;
|
|
_context = context;
|
|
_documentService = documentService;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_repositoryNoti = repositoryNoti;
|
|
_permission = permission;
|
|
_configuration = configuration;
|
|
_userProfileRepository = userProfileRepository;
|
|
}
|
|
|
|
#region " Properties "
|
|
|
|
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
|
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
|
private string? token => _httpContextAccessor.HttpContext.Request.Headers["Authorization"];
|
|
|
|
#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 = "", string status = "")
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_DISCIPLINE_COMPLAIN");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var data_search = (from x in _context.DisciplineComplaints
|
|
where x.Title.Contains(keyword) ||
|
|
(x.Appellant == null ? false : x.Appellant.Contains(keyword))
|
|
select x).ToList();
|
|
if (status.Trim().ToUpper() != "ALL")
|
|
data_search = data_search.Where(x => x.Status.Contains(status.Trim().ToUpper())).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.DateConsideration)
|
|
.Skip((page - 1) * pageSize)
|
|
.Take(pageSize)
|
|
.ToList();
|
|
return Success(new { data, total = data_search.Count() });
|
|
}
|
|
|
|
/// <summary>
|
|
/// list รายการวินัยเรื่องร้องเรียน (ค้นหาขั้นสูง)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("advance-search")]
|
|
public async Task<ActionResult<ResponseObject>> GetAdvanceSearchDisciplineComplaint([FromBody] DisciplineComplaintAdvanceSearcRequest req)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_DISCIPLINE_COMPLAIN");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
|
|
var page = req.page <= 0 ? 1 : req.page;
|
|
var pageSize = req.pageSize <= 0 ? 25 : req.pageSize;
|
|
var keyword = string.IsNullOrEmpty(req.keyword) ? string.Empty : req.keyword;
|
|
var status = string.IsNullOrEmpty(req.status) ? string.Empty : req.status;
|
|
|
|
var data_search = (from x in _context.DisciplineComplaints
|
|
where x.Title.Contains(keyword) ||
|
|
(x.Appellant == null ? false : x.Appellant.Contains(keyword))
|
|
select x).ToList();
|
|
|
|
if (status.Trim().ToUpper() != "ALL")
|
|
data_search = data_search.Where(x => x.Status.Contains(status.Trim().ToUpper())).ToList();
|
|
|
|
if (
|
|
(req.dateReceivedStart.HasValue && req.dateReceivedEnd.HasValue) ||
|
|
(req.dateConsiderationStart.HasValue && req.dateConsiderationEnd.HasValue) ||
|
|
(!string.IsNullOrEmpty(req.respondentType)) ||
|
|
(!string.IsNullOrEmpty(req.offenseDetails)) ||
|
|
(!string.IsNullOrEmpty(req.levelConsideration))
|
|
)
|
|
{
|
|
data_search = data_search
|
|
.Where(x =>
|
|
(!req.dateReceivedStart.HasValue || !req.dateReceivedEnd.HasValue ||
|
|
(x.DateReceived.HasValue &&
|
|
x.DateReceived.Value.Date <= req.dateReceivedStart.Value.Date &&
|
|
x.DateReceived.Value.Date >= req.dateReceivedEnd.Value.Date))
|
|
&&
|
|
(!req.dateConsiderationStart.HasValue || !req.dateConsiderationEnd.HasValue ||
|
|
(x.DateConsideration.HasValue &&
|
|
x.DateConsideration.Value.Date <= req.dateConsiderationStart.Value.Date &&
|
|
x.DateConsideration.Value.Date >= req.dateConsiderationEnd.Value.Date))
|
|
&&
|
|
(string.IsNullOrEmpty(req.respondentType) || x.RespondentType == req.respondentType)
|
|
&&
|
|
(string.IsNullOrEmpty(req.offenseDetails) || x.OffenseDetails == req.offenseDetails)
|
|
&&
|
|
(string.IsNullOrEmpty(req.levelConsideration) || x.LevelConsideration == req.levelConsideration)
|
|
)
|
|
.ToList();
|
|
}
|
|
|
|
var query = 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,
|
|
});
|
|
|
|
bool desc = req.descending ?? false;
|
|
if (!string.IsNullOrEmpty(req.sortBy))
|
|
{
|
|
switch (req.sortBy)
|
|
{
|
|
case "title":
|
|
query = desc ? query.OrderByDescending(x => x.Title)
|
|
: query.OrderBy(x => x.Title);
|
|
break;
|
|
|
|
case "respondentType":
|
|
query = desc ? query.OrderByDescending(x => x.RespondentType)
|
|
: query.OrderBy(x => x.RespondentType);
|
|
break;
|
|
|
|
case "appellant":
|
|
query = desc ? query.OrderByDescending(x => x.Appellant)
|
|
: query.OrderBy(x => x.Appellant);
|
|
break;
|
|
|
|
case "offenseDetails":
|
|
query = desc ? query.OrderByDescending(x => x.OffenseDetails)
|
|
: query.OrderBy(x => x.OffenseDetails);
|
|
break;
|
|
|
|
case "createdAt":
|
|
query = desc ? query.OrderByDescending(x => x.CreatedAt)
|
|
: query.OrderBy(x => x.CreatedAt);
|
|
break;
|
|
|
|
case "levelConsideration":
|
|
query = desc ? query.OrderByDescending(x => x.LevelConsideration)
|
|
: query.OrderBy(x => x.LevelConsideration);
|
|
break;
|
|
|
|
case "dateConsideration":
|
|
query = desc ? query.OrderByDescending(x => x.DateConsideration)
|
|
: query.OrderBy(x => x.DateConsideration);
|
|
break;
|
|
|
|
case "dateReceived":
|
|
query = desc ? query.OrderByDescending(x => x.DateReceived)
|
|
: query.OrderBy(x => x.DateReceived);
|
|
break;
|
|
|
|
case "status":
|
|
query = desc ? query.OrderByDescending(x => x.Status)
|
|
: query.OrderBy(x => x.Status);
|
|
break;
|
|
|
|
case "result":
|
|
query = desc ? query.OrderByDescending(x => x.Result)
|
|
: query.OrderBy(x => x.Result);
|
|
break;
|
|
|
|
default:
|
|
query = query.OrderByDescending(x => x.DateConsideration);
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
var data = query
|
|
.Skip((page - 1) * pageSize)
|
|
.Take(pageSize)
|
|
.ToList();
|
|
|
|
return Success(new { data, total = data_search.Count() });
|
|
}
|
|
|
|
/// <summary>
|
|
/// list รายการวินัยเรื่องร้องเรียนในหน้าออกคำสั่ง
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("report")]
|
|
public async Task<ActionResult<ResponseObject>> GetDisciplineComplaintReport()
|
|
{
|
|
var data = await _context.DisciplineComplaints
|
|
// .Where(x => x.Status.Contains("SEND_INVESTIGATE"))
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องร้องเรียน
|
|
Title = x.Title,//ชื่อเรื่อง
|
|
IsComplaint = true,
|
|
IsInvestigate = x.DisciplineInvestigates.FirstOrDefault() == null ? false : true,
|
|
IsDisciplinary = x.DisciplineInvestigates.FirstOrDefault() == null || x.DisciplineInvestigates.FirstOrDefault().DisciplineDisciplinarys.FirstOrDefault() == null ? false : true,
|
|
IsResult = x.DisciplineInvestigates.FirstOrDefault() == null || x.DisciplineInvestigates.FirstOrDefault().DisciplineDisciplinarys.FirstOrDefault() == null || (x.DisciplineInvestigates.FirstOrDefault().DisciplineDisciplinarys.FirstOrDefault().Status != "DONE" && x.DisciplineInvestigates.FirstOrDefault().DisciplineDisciplinarys.FirstOrDefault().Status != "REPORT") ? false : true,
|
|
DateConsideration = x.DateConsideration,//วันที่กำหนดพิจารณา
|
|
})
|
|
.OrderByDescending(x => x.DateConsideration)
|
|
.ToListAsync();
|
|
return Success(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// get รายการวินัยเรื่องร้องเรียน
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("{page}/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> GetByDisciplineComplaint(string page, Guid id)
|
|
{
|
|
page = page.Trim().ToUpper();
|
|
string getPermission;
|
|
if (page == "MAIN")
|
|
{
|
|
getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_DISCIPLINE_COMPLAIN");
|
|
}
|
|
else if (page == "INVES")
|
|
{
|
|
getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_DISCIPLINE_INVESTIGATE");
|
|
}
|
|
else if (page == "DISCIP")
|
|
{
|
|
getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_DISCIPLINE_INTERROGATE");
|
|
}
|
|
else if (page == "RESULT")
|
|
{
|
|
getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_DISCIPLINE_RESULT");
|
|
}
|
|
else
|
|
{
|
|
getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_DISCIPLINE_COMPLAIN");
|
|
}
|
|
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var _data = await _context.DisciplineComplaints
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องร้องเรียน
|
|
RespondentType = x.RespondentType,//ผู้ถูกร้องเรียน
|
|
Persons = x.DisciplineComplaint_Profiles
|
|
.OrderByDescending(p => p.profileType)
|
|
.ThenByDescending(p => p.CreatedAt)
|
|
.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,
|
|
IsAncestorDNA = p.IsAncestorDNA,
|
|
Salary = p.Salary,
|
|
PersonId = p.PersonId,
|
|
PosNo = p.PosNo,
|
|
Organization = p.Organization,
|
|
|
|
root = p.root,
|
|
rootId = p.rootId,
|
|
rootDnaId = p.rootDnaId,
|
|
rootShortName = p.rootShortName,
|
|
child1 = p.child1,
|
|
child1Id = p.child1Id,
|
|
child1DnaId = p.child1DnaId,
|
|
child1ShortName = p.child1ShortName,
|
|
child2 = p.child2,
|
|
child2Id = p.child2Id,
|
|
child2DnaId = p.child2DnaId,
|
|
child2ShortName = p.child2ShortName,
|
|
child3 = p.child3,
|
|
child3Id = p.child3Id,
|
|
child3DnaId = p.child3DnaId,
|
|
child3ShortName = p.child3ShortName,
|
|
child4 = p.child4,
|
|
child4Id = p.child4Id,
|
|
child4DnaId = p.child4DnaId,
|
|
child4ShortName = p.child4ShortName,
|
|
posMasterNo = p.posMasterNo,
|
|
posTypeId = p.posTypeId,
|
|
posTypeName = p.posTypeName,
|
|
posLevelId = p.posLevelId,
|
|
posLevelName = p.posLevelName,
|
|
profileType = p.profileType,
|
|
CreatedAt = p.CreatedAt
|
|
}),//รายการข้อมูลบุคลผู้ถูกร้องเรียน
|
|
Organization = x.Organization,//id หน่วยงานกรณี type เป็นหน่วยงาน
|
|
ConsideredAgency = x.ConsideredAgency,//หน่วยงานที่พิจารณา จะเปลี่ยนไปตามผู้ถูกร้องดูรายละเอียดด้านล่าง
|
|
OrganizationId = x.OrganizationId,//id หน่วยงานกรณี type เป็นหน่วยงาน
|
|
ConsideredAgencyId = x.ConsideredAgencyId,//หน่วยงานที่พิจารณา จะเปลี่ยนไปตามผู้ถูกร้องดูรายละเอียดด้านล่าง
|
|
activeId = x.activeId,
|
|
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.Organization,
|
|
_data.ConsideredAgency,
|
|
_data.OrganizationId,
|
|
_data.ConsideredAgencyId,
|
|
_data.activeId,
|
|
_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 getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_DISCIPLINE_COMPLAIN");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
|
|
|
|
var profile = await _userProfileRepository.GetUserOC(userId, token.Replace("Bearer ", ""));
|
|
if (profile == null)
|
|
return Error(GlobalMessages.DataNotFound);
|
|
var disciplineComplaint = new Domain.Models.Discipline.DisciplineComplaint
|
|
{
|
|
RespondentType = req.respondentType.Trim().ToUpper(),
|
|
Organization = req.organization,
|
|
ConsideredAgency = req.consideredAgency,
|
|
OrganizationId = req.organizationId,
|
|
ConsideredAgencyId = req.consideredAgencyId,
|
|
activeId = req.activeId,
|
|
Title = req.title,
|
|
Description = req.description,
|
|
DateReceived = req.dateReceived,
|
|
RootDnaId = profile.RootDnaId,
|
|
LevelConsideration = req.levelConsideration == null ? null : req.levelConsideration.Trim().ToUpper(),
|
|
DateConsideration = req.dateConsideration,
|
|
OffenseDetails = req.offenseDetails == null ? null : 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,
|
|
|
|
root = item.root,
|
|
rootId = item.rootId,
|
|
rootDnaId = item.rootDnaId,
|
|
rootShortName = item.rootShortName,
|
|
child1 = item.child1,
|
|
child1Id = item.child1Id,
|
|
child1DnaId = item.child1DnaId,
|
|
child1ShortName = item.child1ShortName,
|
|
child2 = item.child2,
|
|
child2Id = item.child2Id,
|
|
child2DnaId = item.child2DnaId,
|
|
child2ShortName = item.child2ShortName,
|
|
child3 = item.child3,
|
|
child3Id = item.child3Id,
|
|
child3DnaId = item.child3DnaId,
|
|
child3ShortName = item.child3ShortName,
|
|
child4 = item.child4,
|
|
child4Id = item.child4Id,
|
|
child4DnaId = item.child4DnaId,
|
|
child4ShortName = item.child4ShortName,
|
|
posMasterNo = item.posMasterNo,
|
|
posTypeId = item.posTypeId,
|
|
posTypeName = item.posTypeName,
|
|
posLevelId = item.posLevelId,
|
|
posLevelName = item.posLevelName,
|
|
profileType = item.profileType,
|
|
Salary = item.salary,
|
|
PosNo = item.posNo,
|
|
Position = item.position,
|
|
// PositionLevel = item.positionLevel,
|
|
IsAncestorDNA = true,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
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 getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_DISCIPLINE_COMPLAIN");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
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.organization;
|
|
data.ConsideredAgency = req.consideredAgency;
|
|
data.OrganizationId = req.organizationId;
|
|
data.ConsideredAgencyId = req.consideredAgencyId;
|
|
data.activeId = req.activeId;
|
|
data.Title = req.title;
|
|
data.Description = req.description;
|
|
data.DateReceived = req.dateReceived;
|
|
data.LevelConsideration = req.levelConsideration == null ? null : req.levelConsideration.Trim().ToUpper();
|
|
data.DateConsideration = req.dateConsideration;
|
|
data.OffenseDetails = req.offenseDetails == null ? null : 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,
|
|
IsAncestorDNA = true,
|
|
Salary = item.salary,
|
|
PersonId = item.personId,
|
|
|
|
root = item.root,
|
|
rootId = item.rootId,
|
|
rootDnaId = item.rootDnaId,
|
|
rootShortName = item.rootShortName,
|
|
child1 = item.child1,
|
|
child1Id = item.child1Id,
|
|
child1DnaId = item.child1DnaId,
|
|
child1ShortName = item.child1ShortName,
|
|
child2 = item.child2,
|
|
child2Id = item.child2Id,
|
|
child2DnaId = item.child2DnaId,
|
|
child2ShortName = item.child2ShortName,
|
|
child3 = item.child3,
|
|
child3Id = item.child3Id,
|
|
child3DnaId = item.child3DnaId,
|
|
child3ShortName = item.child3ShortName,
|
|
child4 = item.child4,
|
|
child4Id = item.child4Id,
|
|
child4DnaId = item.child4DnaId,
|
|
child4ShortName = item.child4ShortName,
|
|
posMasterNo = item.posMasterNo,
|
|
posTypeId = item.posTypeId,
|
|
posTypeName = item.posTypeName,
|
|
posLevelId = item.posLevelId,
|
|
posLevelName = item.posLevelName,
|
|
profileType = item.profileType,
|
|
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 getPermission = await _permission.GetPermissionAPIAsync("DELETE", "SYS_DISCIPLINE_COMPLAIN");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
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 getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "SYS_DISCIPLINE_COMPLAIN");
|
|
if (getWorkflow == false)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_DISCIPLINE_COMPLAIN");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
}
|
|
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 getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_DISCIPLINE_COMPLAIN");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
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,
|
|
RootDnaId = data.RootDnaId,
|
|
ConsideredAgency = data.ConsideredAgency,
|
|
OrganizationId = data.OrganizationId,
|
|
ConsideredAgencyId = data.ConsideredAgencyId,
|
|
activeId = data.activeId,
|
|
Title = data.Title,
|
|
Description = data.Description,
|
|
DateReceived = data.DateReceived,
|
|
LevelConsideration = data.LevelConsideration == null ? null : data.LevelConsideration.Trim().ToUpper(),
|
|
DateConsideration = data.DateConsideration,
|
|
OffenseDetails = data.OffenseDetails == null ? null : 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,
|
|
|
|
root = item.root,
|
|
rootId = item.rootId,
|
|
rootDnaId = item.rootDnaId,
|
|
rootShortName = item.rootShortName,
|
|
child1 = item.child1,
|
|
child1Id = item.child1Id,
|
|
child1DnaId = item.child1DnaId,
|
|
child1ShortName = item.child1ShortName,
|
|
child2 = item.child2,
|
|
child2Id = item.child2Id,
|
|
child2DnaId = item.child2DnaId,
|
|
child2ShortName = item.child2ShortName,
|
|
child3 = item.child3,
|
|
child3Id = item.child3Id,
|
|
child3DnaId = item.child3DnaId,
|
|
child3ShortName = item.child3ShortName,
|
|
child4 = item.child4,
|
|
child4Id = item.child4Id,
|
|
child4DnaId = item.child4DnaId,
|
|
child4ShortName = item.child4ShortName,
|
|
posMasterNo = item.posMasterNo,
|
|
posTypeId = item.posTypeId,
|
|
posTypeName = item.posTypeName,
|
|
posLevelId = item.posLevelId,
|
|
posLevelName = item.posLevelName,
|
|
profileType = item.profileType,
|
|
Salary = item.Salary,
|
|
PosNo = item.PosNo,
|
|
Position = item.Position,
|
|
// PositionLevel = item.PositionLevel,
|
|
IsAncestorDNA = true,
|
|
IsDisciplinary = false,
|
|
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,
|
|
});
|
|
}
|
|
var baseAPIOrg = _configuration["API"];
|
|
var apiUrlOrg = $"{baseAPIOrg}/org/workflow/find/director";
|
|
var refId = new List<Guid>();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
|
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
|
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
|
{
|
|
refId = persons.Select(x => x.PersonId),
|
|
});
|
|
var _result = await _res.Content.ReadAsStringAsync();
|
|
var org = JsonConvert.DeserializeObject<DirectorRequest>(_result);
|
|
if (_res.IsSuccessStatusCode)
|
|
{
|
|
refId = org.result.Select(x => Guid.Parse(x.id)).ToList();
|
|
}
|
|
}
|
|
await _repositoryNoti.PushNotificationsAsync(
|
|
refId.ToArray(),
|
|
$"มีคำขอสืบสวนเรื่อง {data.Title}",
|
|
$"มีคำขอสืบสวนเรื่อง {data.Title}",
|
|
"",
|
|
"",
|
|
true,
|
|
true
|
|
);
|
|
|
|
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 getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "SYS_DISCIPLINE_COMPLAIN");
|
|
if (getWorkflow == false)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_DISCIPLINE_COMPLAIN");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
}
|
|
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 getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_DISCIPLINE_COMPLAIN");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
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 getPermission = await _permission.GetPermissionAPIAsync("DELETE", "SYS_DISCIPLINE_COMPLAIN");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|