877 lines
49 KiB
C#
877 lines
49 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.DisciplineInvestigate.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/discipline/investigate")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("ระบบวินัยเรื่องสืบสวน")]
|
|
public class DisciplineInvestigateController : BaseController
|
|
{
|
|
private readonly DisciplineDbContext _context;
|
|
private readonly MinIODisciplineService _documentService;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
public DisciplineInvestigateController(DisciplineDbContext context,
|
|
MinIODisciplineService 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;
|
|
|
|
#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>> GetDisciplineInvestigate(int page = 1, int pageSize = 25, string keyword = "")
|
|
{
|
|
var data_search = (from x in _context.DisciplineInvestigates
|
|
where x.Title.Contains(keyword)
|
|
select x).ToList();
|
|
var data = data_search
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องสืบสวน
|
|
Title = x.Title,//ชื่อเรื่อง
|
|
RespondentType = x.RespondentType,//ผู้ถูกสืบสวน
|
|
OffenseDetails = x.OffenseDetails,//ลักษณะความผิด
|
|
Status = x.Status,//สถานะหรือผลการสืบสวน
|
|
InvestigationDateStart = x.InvestigationDateStart,
|
|
InvestigationDateEnd = x.InvestigationDateEnd,
|
|
CreatedAt = x.CreatedAt,//วันที่สร้างเรื่องสืบสวน
|
|
InvestigationDetail = x.InvestigationDetail,
|
|
InvestigationStatusResult = x.InvestigationStatusResult,
|
|
})
|
|
.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("complaint/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> GetByDisciplineInvestigateComplaint(Guid id)
|
|
{
|
|
var _data = await _context.DisciplineInvestigates
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องสืบสวน
|
|
IdComplaint = x.DisciplineComplaint.Id,//id ข้อมูลเรื่องร้องเรียน
|
|
RespondentType = x.RespondentType,//ผู้ถูกสืบสวน
|
|
Persons = x.DisciplineInvestigate_ProfileComplaints.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,//ผู้ถูกสืบสวน
|
|
Result = x.ResultComplaint,//ผลการตรวจสอบ
|
|
Status = x.Status,//สถานะเรื่องสืบสวน
|
|
DisciplineInvestigateDocComplaints = x.DisciplineInvestigate_DocComplaints.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), (int)StatusCodes.Status404NotFound);
|
|
|
|
var disciplineInvestigateDocComplaints = new List<dynamic>();
|
|
foreach (var doc in _data.DisciplineInvestigateDocComplaints)
|
|
{
|
|
var _doc = new
|
|
{
|
|
doc.Id,
|
|
doc.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Id)
|
|
};
|
|
disciplineInvestigateDocComplaints.Add(_doc);
|
|
}
|
|
var data = new
|
|
{
|
|
_data.Id,
|
|
_data.IdComplaint,
|
|
_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.Result,
|
|
_data.Status,
|
|
disciplineInvestigateDocComplaints,
|
|
};
|
|
return Success(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// แก้ไขรายการวินัยเรื่องร้องเรียน
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("complaint/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> UpdateDisciplineInvestigateComplaint([FromBody] DisciplineInvestigateComplaintRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineInvestigates.Include(x => x.DisciplineInvestigate_ProfileComplaints).Where(x => x.Id == id).FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
|
|
|
|
data.Title = req.title;
|
|
data.Description = req.description;
|
|
data.OffenseDetails = req.offenseDetails.Trim().ToUpper();
|
|
data.LastUpdateFullName = FullName ?? "System Administrator";
|
|
data.LastUpdateUserId = UserId ?? "";
|
|
data.LastUpdatedAt = DateTime.Now;
|
|
_context.DisciplineInvestigate_ProfileComplaints.RemoveRange(data.DisciplineInvestigate_ProfileComplaints);
|
|
if (data.RespondentType.Trim().ToUpper() == "PERSON")
|
|
{
|
|
foreach (var item in req.persons)
|
|
{
|
|
data.DisciplineInvestigate_ProfileComplaints.Add(
|
|
new DisciplineInvestigate_ProfileComplaint
|
|
{
|
|
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>
|
|
/// 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>> GetByDisciplineInvestigate(Guid id)
|
|
{
|
|
var _data = await _context.DisciplineInvestigates
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องสืบสวน
|
|
IdComplaint = x.DisciplineComplaint.Id,//id ข้อมูลเรื่องร้องเรียน
|
|
InvestigationDetail = x.InvestigationDetail,
|
|
InvestigationDetailOther = x.InvestigationDetailOther,
|
|
InvestigationDateStart = x.InvestigationDateStart,
|
|
InvestigationDateEnd = x.InvestigationDateEnd,
|
|
InvestigationDescription = x.InvestigationDescription,
|
|
InvestigationStatusResult = x.InvestigationStatusResult,
|
|
InvestigationCauseText = x.InvestigationCauseText,
|
|
Status = x.Status,//สถานะเรื่องสืบสวน
|
|
Result = x.Result,//ผลการตรวจสอบ
|
|
Director = x.DisciplineInvestigate_Directors.Select(d => new
|
|
{
|
|
Id = d.Id,
|
|
DirectorId = d.DisciplineDirector.Id,
|
|
Prefix = d.DisciplineDirector.Prefix,
|
|
FirstName = d.DisciplineDirector.FirstName,
|
|
LastName = d.DisciplineDirector.LastName,
|
|
Position = d.DisciplineDirector.Position,
|
|
Email = d.DisciplineDirector.Email,
|
|
Duty = "",
|
|
Phone = d.DisciplineDirector.Phone,
|
|
Total = d.DisciplineDirector.DisciplineInvestigate_Directors.Count(),
|
|
}).ToList(),
|
|
RespondentType = x.RespondentType,//ผู้ถูกสืบสวน
|
|
Persons = x.DisciplineInvestigate_ProfileComplaints.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 เป็นหน่วยงาน
|
|
DisciplineInvestigateDocs = x.DisciplineInvestigate_Docs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
|
|
DisciplineInvestigateRelevantDocs = x.DisciplineInvestigateRelevant_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), (int)StatusCodes.Status404NotFound);
|
|
|
|
var disciplineInvestigateDocs = new List<dynamic>();
|
|
foreach (var doc in _data.DisciplineInvestigateDocs)
|
|
{
|
|
var _doc = new
|
|
{
|
|
doc.Id,
|
|
doc.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Id)
|
|
};
|
|
disciplineInvestigateDocs.Add(_doc);
|
|
}
|
|
|
|
var disciplineInvestigateRelevantDocs = new List<dynamic>();
|
|
foreach (var doc in _data.DisciplineInvestigateRelevantDocs)
|
|
{
|
|
var _doc = new
|
|
{
|
|
doc.Id,
|
|
doc.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Id)
|
|
};
|
|
disciplineInvestigateRelevantDocs.Add(_doc);
|
|
}
|
|
var data = new
|
|
{
|
|
_data.Id,
|
|
_data.IdComplaint,
|
|
_data.InvestigationDetail,
|
|
_data.InvestigationDetailOther,
|
|
_data.InvestigationDateStart,
|
|
_data.InvestigationDateEnd,
|
|
_data.InvestigationDescription,
|
|
_data.InvestigationStatusResult,
|
|
_data.InvestigationCauseText,
|
|
_data.Status,
|
|
_data.Result,
|
|
_data.Director,
|
|
_data.RespondentType,
|
|
_data.Persons,
|
|
_data.OrganizationId,
|
|
disciplineInvestigateDocs,
|
|
disciplineInvestigateRelevantDocs,
|
|
};
|
|
return Success(data);
|
|
}
|
|
|
|
/// <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>> UpdateDisciplineInvestigate([FromBody] DisciplineInvestigateRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Include(x => x.DisciplineInvestigate_Directors)
|
|
.ThenInclude(x => x.DisciplineDirector)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
|
|
|
|
data.InvestigationDetail = req.investigationDetail.Trim().ToUpper();
|
|
data.InvestigationDetailOther = req.investigationDetailOther;
|
|
data.InvestigationDateStart = req.investigationDateStart;
|
|
data.InvestigationDateEnd = req.investigationDateEnd;
|
|
data.InvestigationDescription = req.investigationDescription;
|
|
data.InvestigationStatusResult = req.investigationStatusResult.Trim().ToUpper();
|
|
data.InvestigationCauseText = req.investigationCauseText;
|
|
data.Result = req.result;
|
|
data.LastUpdateFullName = FullName ?? "System Administrator";
|
|
data.LastUpdateUserId = UserId ?? "";
|
|
data.LastUpdatedAt = DateTime.Now;
|
|
_context.DisciplineInvestigate_Directors.RemoveRange(data.DisciplineInvestigate_Directors);
|
|
foreach (var item in req.directors)
|
|
{
|
|
var director = await _context.DisciplineDirectors.AsQueryable()
|
|
.FirstOrDefaultAsync(x => x.Id == item);
|
|
if (director != null)
|
|
{
|
|
data.DisciplineInvestigate_Directors.Add(
|
|
new DisciplineInvestigate_Director
|
|
{
|
|
DisciplineDirector = director,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
}
|
|
);
|
|
}
|
|
}
|
|
data.Organization = req.organizationId;
|
|
data.RespondentType = req.respondentType;
|
|
_context.DisciplineInvestigate_ProfileComplaints.RemoveRange(data.DisciplineInvestigate_ProfileComplaints);
|
|
if (data.RespondentType.Trim().ToUpper() == "PERSON")
|
|
{
|
|
foreach (var item in req.persons)
|
|
{
|
|
data.DisciplineInvestigate_ProfileComplaints.Add(
|
|
new DisciplineInvestigate_ProfileComplaint
|
|
{
|
|
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>
|
|
[HttpGet("reject/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> RejectDisciplineInvestigate(Guid id)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถยุติเรื่องได้"), (int)StatusCodes.Status500InternalServerError);
|
|
if (data.InvestigationStatusResult == null || data.InvestigationStatusResult.Trim().ToUpper() != "NO_CAUSE")
|
|
return Error(new Exception("ไม่สามารถยุติเรื่องได้"), (int)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>> ApproveDisciplineInvestigate([FromBody] DisciplinePersonIdRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Include(x => x.DisciplineInvestigate_DocComplaints)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.DisciplineInvestigate_Docs)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.DisciplineInvestigateRelevant_Docs)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.DisciplineInvestigate_ProfileComplaints)
|
|
.Include(x => x.DisciplineInvestigate_Directors)
|
|
.ThenInclude(x => x.DisciplineDirector)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถส่งต่อไปสอบสวนได้"), (int)StatusCodes.Status500InternalServerError);
|
|
data.Status = "SEND_DISCIPLINARY";
|
|
|
|
var disciplineDisciplinary = new Domain.Models.Discipline.DisciplineDisciplinary
|
|
{
|
|
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.ResultComplaint,
|
|
ResultInvestigate = data.Result,
|
|
|
|
InvestigationDetail = data.InvestigationDetail,
|
|
InvestigationDetailOther = data.InvestigationDetailOther,
|
|
InvestigationDateStart = data.InvestigationDateStart,
|
|
InvestigationDateEnd = data.InvestigationDateEnd,
|
|
InvestigationDescription = data.InvestigationDescription,
|
|
InvestigationStatusResult = data.InvestigationStatusResult,
|
|
InvestigationCauseText = data.InvestigationCauseText,
|
|
|
|
Status = "NEW",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
var persons = data.DisciplineInvestigate_ProfileComplaints.Where(x => req.persons.Contains(x.Id)).ToList();
|
|
foreach (var item in persons)
|
|
{
|
|
disciplineDisciplinary.DisciplineDisciplinary_ProfileComplaintInvestigates.Add(
|
|
new DisciplineDisciplinary_ProfileComplaintInvestigate
|
|
{
|
|
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.DisciplineInvestigate_DocComplaints)
|
|
{
|
|
disciplineDisciplinary.DisciplineDisciplinary_DocComplaintInvestigates.Add(
|
|
new DisciplineDisciplinary_DocComplaintInvestigate
|
|
{
|
|
Document = item.Document,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
foreach (var item in data.DisciplineInvestigate_Docs)
|
|
{
|
|
disciplineDisciplinary.DisciplineDisciplinary_DocInvestigates.Add(
|
|
new DisciplineDisciplinary_DocInvestigate
|
|
{
|
|
Document = item.Document,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
foreach (var item in data.DisciplineInvestigateRelevant_Docs)
|
|
{
|
|
disciplineDisciplinary.DisciplineDisciplinary_DocInvestigateRelevants.Add(
|
|
new DisciplineDisciplinary_DocInvestigateRelevant
|
|
{
|
|
Document = item.Document,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
foreach (var item in data.DisciplineInvestigate_Directors)
|
|
{
|
|
disciplineDisciplinary.DisciplineDisciplinary_DirectorInvestigates.Add(
|
|
new DisciplineDisciplinary_DirectorInvestigate
|
|
{
|
|
DisciplineDirector = item.DisciplineDirector,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
|
|
data.DisciplineDisciplinarys.Add(disciplineDisciplinary);
|
|
await _context.SaveChangesAsync();
|
|
return Success(disciplineDisciplinary.Id);
|
|
|
|
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("resume/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> ResumeDisciplineInvestigate(Guid id)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "STOP")
|
|
return Error(new Exception("รายการนี้ยังไม่ถูกยุติเรื่อง"), (int)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>> UploadFileDisciplineInvestigate([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)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 disciplineInvestigate_Doc = new DisciplineInvestigate_Doc
|
|
{
|
|
DisciplineInvestigate = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineInvestigate_Docs.AddAsync(disciplineInvestigate_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>> DeleteFileDisciplineInvestigate(Guid id, Guid docId)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Include(x => x.DisciplineInvestigate_Docs)
|
|
.ThenInclude(x => x.Document)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
|
|
var dataDoc = data.DisciplineInvestigate_Docs.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineInvestigate_Docs.Remove(dataDoc);
|
|
await _context.SaveChangesAsync();
|
|
await _documentService.DeleteFileAsync(docId);
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
else
|
|
{
|
|
return Error(new Exception("ไม่พอไฟล์นี้ในระบบ"), (int)StatusCodes.Status404NotFound);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// อัพไฟล์เอกสารร้องเรียนวินัย
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("complaint/file/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> UploadFileDisciplineInvestigateComplaint([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)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 disciplineInvestigate_DocComplaint = new DisciplineInvestigate_DocComplaint
|
|
{
|
|
DisciplineInvestigate = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineInvestigate_DocComplaints.AddAsync(disciplineInvestigate_DocComplaint);
|
|
}
|
|
}
|
|
}
|
|
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("complaint/file/{id:guid}/{docId:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> DeleteFileDisciplineInvestigateComplaint(Guid id, Guid docId)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Include(x => x.DisciplineInvestigate_DocComplaints)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.DisciplineComplaint)
|
|
.ThenInclude(x => x.DisciplineComplaint_Docs)
|
|
.ThenInclude(x => x.Document)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
|
|
var dataDoc = data.DisciplineInvestigate_DocComplaints.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineInvestigate_DocComplaints.Remove(dataDoc);
|
|
await _context.SaveChangesAsync();
|
|
var dataDocComplaint = data.DisciplineComplaint.DisciplineComplaint_Docs.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDocComplaint == null)
|
|
{
|
|
await _documentService.DeleteFileAsync(docId);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
return Success();
|
|
}
|
|
else
|
|
{
|
|
return Error(new Exception("ไม่พอไฟล์นี้ในระบบ"), (int)StatusCodes.Status404NotFound);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// อัพไฟล์เอกสารเกี่ยวข้องสืบสวนวินัย
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("relevant/file/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> UploadFileDisciplineInvestigateRelevant([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)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 disciplineInvestigateRelevant_Doc = new DisciplineInvestigateRelevant_Doc
|
|
{
|
|
DisciplineInvestigate = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineInvestigateRelevant_Docs.AddAsync(disciplineInvestigateRelevant_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("relevant/file/{id:guid}/{docId:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> DeleteFileDisciplineInvestigateRelevant(Guid id, Guid docId)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Include(x => x.DisciplineInvestigateRelevant_Docs)
|
|
.ThenInclude(x => x.Document)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
|
|
var dataDoc = data.DisciplineInvestigateRelevant_Docs.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineInvestigateRelevant_Docs.Remove(dataDoc);
|
|
await _context.SaveChangesAsync();
|
|
await _documentService.DeleteFileAsync(docId);
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
else
|
|
{
|
|
return Error(new Exception("ไม่พอไฟล์นี้ในระบบ"), (int)StatusCodes.Status404NotFound);
|
|
}
|
|
}
|
|
}
|
|
}
|