1633 lines
95 KiB
C#
1633 lines
95 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.DisciplineDisciplinary.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/discipline/disciplinary")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("ระบบวินัยเรื่องสอบสวน")]
|
|
public class DisciplineDisciplinaryController : BaseController
|
|
{
|
|
private readonly DisciplineDbContext _context;
|
|
private readonly MinIODisciplineService _documentService;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
public DisciplineDisciplinaryController(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>> GetDisciplineDisciplinary(int page = 1, int pageSize = 25, string keyword = "")
|
|
{
|
|
var data_search = (from x in _context.DisciplineDisciplinarys
|
|
where x.Title.Contains(keyword) ||
|
|
// x.DisciplinaryFaultLevel == null ? false : x.DisciplinaryFaultLevel.Contains(keyword) ||
|
|
// x.DisciplinaryCaseFault == null ? false : x.DisciplinaryCaseFault.Contains(keyword)
|
|
x.DisciplinaryFaultLevel.Contains(keyword) ||
|
|
x.DisciplinaryCaseFault.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,//ลักษณะความผิด
|
|
DisciplinaryFaultLevel = x.DisciplinaryFaultLevel,//ระดับโทษความผิด
|
|
DisciplinaryCaseFault = x.DisciplinaryCaseFault,//กรณีความผิด
|
|
Status = x.Status,//สถานะหรือผลการสอบสวน
|
|
CreatedAt = x.CreatedAt,//วันที่สร้างเรื่องสอบสวน
|
|
})
|
|
.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>> GetByDisciplineDisciplinaryComplaint(Guid id)
|
|
// {
|
|
// var _data = await _context.DisciplineDisciplinarys
|
|
// .Select(x => new
|
|
// {
|
|
// Id = x.Id,//id ข้อมูลเรื่องสอบสวน
|
|
// IdInvestigate = x.DisciplineInvestigate.Id,//id ข้อมูลเรื่องสืบสวน
|
|
// IdComplaint = x.DisciplineInvestigate.DisciplineComplaint.Id,//id ข้อมูลเรื่องร้องเรียน
|
|
// RespondentType = x.RespondentType,//ผู้ถูกสืบสวน
|
|
// Persons = x.DisciplineDisciplinary_ProfileComplaintInvestigates.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,
|
|
// IsSend = p.IsReport,
|
|
// }),//รายการข้อมูลบุคลผู้ถูกสืบสวน
|
|
// 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,//สถานะเรื่องสืบสวน
|
|
// DisciplineDisciplinaryDocComplaintInvestigates = x.DisciplineDisciplinary_DocComplaintInvestigates.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 disciplineDisciplinaryDocComplaintInvestigates = new List<dynamic>();
|
|
// foreach (var doc in _data.DisciplineDisciplinaryDocComplaintInvestigates)
|
|
// {
|
|
// var _doc = new
|
|
// {
|
|
// doc.Id,
|
|
// doc.FileName,
|
|
// PathName = await _documentService.ImagesPath(doc.Id)
|
|
// };
|
|
// disciplineDisciplinaryDocComplaintInvestigates.Add(_doc);
|
|
// }
|
|
// var data = new
|
|
// {
|
|
// _data.Id,
|
|
// _data.IdInvestigate,
|
|
// _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,
|
|
// disciplineDisciplinaryDocComplaintInvestigates,
|
|
// };
|
|
// 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>> UpdateDisciplineDisciplinaryComplaint([FromBody] DisciplineDisciplinaryComplaintRequest req, Guid id)
|
|
// {
|
|
// var data = await _context.DisciplineDisciplinarys.Include(x => x.DisciplineDisciplinary_ProfileComplaintInvestigates).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;
|
|
// // var hisprofile = data.DisciplineDisciplinary_ProfileComplaintInvestigates;
|
|
// // _context.DisciplineDisciplinary_ProfileComplaintInvestigates.RemoveRange(data.DisciplineDisciplinary_ProfileComplaintInvestigates);
|
|
// // if (data.RespondentType.Trim().ToUpper() == "PERSON")
|
|
// // {
|
|
// // foreach (var item in req.persons)
|
|
// // {
|
|
// // var isReport = hisprofile.Where(x => x.PersonId == item.personId).FirstOrDefault();
|
|
// // data.DisciplineDisciplinary_ProfileComplaintInvestigates.Add(
|
|
// // new DisciplineDisciplinary_ProfileComplaintInvestigate
|
|
// // {
|
|
// // 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,
|
|
// // Status = "NEW",
|
|
// // IsReport = isReport == null ? false : isReport.IsReport,
|
|
// // 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("investigate/{id:guid}")]
|
|
// public async Task<ActionResult<ResponseObject>> GetByDisciplineDisciplinaryInvestigate(Guid id)
|
|
// {
|
|
// var _data = await _context.DisciplineDisciplinarys
|
|
// .Select(x => new
|
|
// {
|
|
// Id = x.Id,//id ข้อมูลเรื่องสอบสวน
|
|
// IdInvestigate = x.DisciplineInvestigate.Id,//id ข้อมูลเรื่องสืบสวน
|
|
// IdComplaint = x.DisciplineInvestigate.DisciplineComplaint.Id,//id ข้อมูลเรื่องร้องเรียน
|
|
// InvestigationDetail = x.InvestigationDetail,
|
|
// InvestigationDetailOther = x.InvestigationDetailOther,
|
|
// InvestigationDateStart = x.InvestigationDateStart,
|
|
// InvestigationDateEnd = x.InvestigationDateEnd,
|
|
// InvestigationDescription = x.InvestigationDescription,
|
|
// InvestigationStatusResult = x.InvestigationStatusResult,
|
|
// InvestigationCauseText = x.InvestigationCauseText,
|
|
// InvestigationExtendStatus = x.InvestigationExtendStatus,
|
|
// InvestigationDaysExtend = x.InvestigationDaysExtend,
|
|
// Status = x.Status,//สถานะเรื่องสืบสวน
|
|
// Result = x.Result,//ผลการตรวจสอบ
|
|
// Director = x.DisciplineDisciplinary_DirectorInvestigates.Select(d => new
|
|
// {
|
|
// DirectorId = d.Id,
|
|
// Id = 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.DisciplineDisciplinary_DirectorInvestigates.Count(),
|
|
// }).ToList(),
|
|
// DisciplineDisciplinaryDocInvestigates = x.DisciplineDisciplinary_DocInvestigates.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
|
|
// DisciplineDisciplinaryDocInvestigateRelevants = x.DisciplineDisciplinary_DocInvestigateRelevants.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 disciplineDisciplinaryDocInvestigates = new List<dynamic>();
|
|
// foreach (var doc in _data.DisciplineDisciplinaryDocInvestigates)
|
|
// {
|
|
// var _doc = new
|
|
// {
|
|
// doc.Id,
|
|
// doc.FileName,
|
|
// PathName = await _documentService.ImagesPath(doc.Id)
|
|
// };
|
|
// disciplineDisciplinaryDocInvestigates.Add(_doc);
|
|
// }
|
|
|
|
// var disciplineDisciplinaryDocInvestigateRelevants = new List<dynamic>();
|
|
// foreach (var doc in _data.DisciplineDisciplinaryDocInvestigateRelevants)
|
|
// {
|
|
// var _doc = new
|
|
// {
|
|
// doc.Id,
|
|
// doc.FileName,
|
|
// PathName = await _documentService.ImagesPath(doc.Id)
|
|
// };
|
|
// disciplineDisciplinaryDocInvestigateRelevants.Add(_doc);
|
|
// }
|
|
// var data = new
|
|
// {
|
|
// _data.Id,
|
|
// _data.IdInvestigate,
|
|
// _data.IdComplaint,
|
|
// _data.InvestigationDetail,
|
|
// _data.InvestigationDetailOther,
|
|
// _data.InvestigationDateStart,
|
|
// _data.InvestigationDateEnd,
|
|
// _data.InvestigationDescription,
|
|
// _data.InvestigationStatusResult,
|
|
// _data.InvestigationCauseText,
|
|
// _data.InvestigationExtendStatus,
|
|
// _data.InvestigationDaysExtend,
|
|
// _data.Status,
|
|
// _data.Result,
|
|
// _data.Director,
|
|
// disciplineDisciplinaryDocInvestigates,
|
|
// disciplineDisciplinaryDocInvestigateRelevants,
|
|
// };
|
|
// 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("investigate/{id:guid}")]
|
|
// public async Task<ActionResult<ResponseObject>> UpdateDisciplineDisciplinaryInvestigate([FromBody] DisciplineDisciplinaryInvestigateRequest req, Guid id)
|
|
// {
|
|
// var data = await _context.DisciplineDisciplinarys
|
|
// .Include(x => x.DisciplineDisciplinary_DirectorInvestigates)
|
|
// .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.Trim().ToUpper();
|
|
// data.InvestigationExtendStatus = req.investigationExtendStatus;
|
|
// data.InvestigationDaysExtend = req.investigationDaysExtend;
|
|
// data.Result = req.result;
|
|
// data.LastUpdateFullName = FullName ?? "System Administrator";
|
|
// data.LastUpdateUserId = UserId ?? "";
|
|
// data.LastUpdatedAt = DateTime.Now;
|
|
// _context.DisciplineDisciplinary_DirectorInvestigates.RemoveRange(data.DisciplineDisciplinary_DirectorInvestigates);
|
|
// foreach (var item in req.directors)
|
|
// {
|
|
// var director = await _context.DisciplineDirectors.AsQueryable()
|
|
// .FirstOrDefaultAsync(x => x.Id == item);
|
|
// if (director != null)
|
|
// {
|
|
// data.DisciplineDisciplinary_DirectorInvestigates.Add(
|
|
// new DisciplineDisciplinary_DirectorInvestigate
|
|
// {
|
|
// DisciplineDirector = director,
|
|
// 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>> GetByDisciplineDisciplinary(Guid id)
|
|
{
|
|
var _data = await _context.DisciplineDisciplinarys
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องสอบสวน
|
|
IdInvestigate = x.DisciplineInvestigate.Id,//id ข้อมูลเรื่องสืบสวน
|
|
IdComplaint = x.DisciplineInvestigate.DisciplineComplaint.Id,//id ข้อมูลเรื่องร้องเรียน
|
|
DisciplinaryWitnesses = x.DisciplinaryWitnesses,
|
|
DisciplinaryRecordAccuser = x.DisciplinaryRecordAccuser,
|
|
DisciplinarySummaryEvidence = x.DisciplinarySummaryEvidence,
|
|
DisciplinaryRefLaw = x.DisciplinaryRefLaw,
|
|
DisciplinaryFaultLevel = x.DisciplinaryFaultLevel,
|
|
DisciplinaryInvestigateAt = x.DisciplinaryInvestigateAt,
|
|
DisciplinaryCaseFault = x.DisciplinaryCaseFault,
|
|
DisciplinaryDateEvident = x.DisciplinaryDateEvident,
|
|
DisciplinaryDateAllegation = x.DisciplinaryDateAllegation,
|
|
|
|
DisciplinaryDateStart = x.DisciplinaryDateStart,
|
|
DisciplinaryDateEnd = x.DisciplinaryDateEnd,
|
|
DaysExtend = x.DisciplinaryDaysExtend,
|
|
ExtendStatus = x.DisciplinaryExtendStatus,
|
|
DisciplinaryDateInvestigation = x.DisciplinaryDateInvestigation,
|
|
DisciplinaryDateResult = x.DisciplinaryDateResult,
|
|
DisciplinaryStatusResult = x.DisciplinaryStatusResult,
|
|
DisciplinaryCauseText = x.DisciplinaryCauseText,
|
|
DisciplinaryResult = x.DisciplinaryResult,
|
|
DisciplinaryExtendHistory = x.DisciplineDisciplinaryExtends.Select(e => new
|
|
{
|
|
Name = e.Name,
|
|
Num = e.Num,
|
|
DaysExtend = e.DaysExtend,
|
|
DateStart = e.DateStart,
|
|
DateEnd = e.DateEnd,
|
|
}),
|
|
Status = x.Status,
|
|
Result = x.Result,
|
|
Director = x.DisciplineDisciplinary_DirectorInvestigates.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 = d.Duty,
|
|
Phone = d.DisciplineDirector.Phone,
|
|
// Total = d.DisciplineDirector.DisciplineDisciplinary_DirectorInvestigates.Count(),
|
|
}).ToList(),
|
|
RespondentType = x.RespondentType,//ผู้ถูกสืบสวน
|
|
Persons = x.DisciplineDisciplinary_ProfileComplaintInvestigates.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,
|
|
IsSend = p.IsReport,
|
|
Status = p.Status,
|
|
StatusDiscard = p.StatusDiscard,
|
|
Report = p.DisciplineReport_Profiles.Count() > 0 ? true : false,
|
|
}),//รายการข้อมูลบุคลผู้ถูกสืบสวน
|
|
OrganizationId = x.Organization,//id หน่วยงานกรณี type เป็นหน่วยงาน
|
|
DisciplineDisciplinary_DocRelevants = x.DisciplineDisciplinary_DocRelevants.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
|
|
DisciplineDisciplinary_DocSummaryEvidences = x.DisciplineDisciplinary_DocSummaryEvidences.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
|
|
DisciplineDisciplinary_DocRecordAccusers = x.DisciplineDisciplinary_DocRecordAccusers.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
|
|
DisciplineDisciplinary_DocWitnessess = x.DisciplineDisciplinary_DocWitnessess.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
|
|
DisciplineDisciplinary_DocOthers = x.DisciplineDisciplinary_DocOthers.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 disciplineDisciplinary_DocRelevants = new List<dynamic>();
|
|
foreach (var doc in _data.DisciplineDisciplinary_DocRelevants)
|
|
{
|
|
var _doc = new
|
|
{
|
|
doc.Id,
|
|
doc.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Id)
|
|
};
|
|
disciplineDisciplinary_DocRelevants.Add(_doc);
|
|
}
|
|
var disciplineDisciplinary_DocSummaryEvidences = new List<dynamic>();
|
|
foreach (var doc in _data.DisciplineDisciplinary_DocSummaryEvidences)
|
|
{
|
|
var _doc = new
|
|
{
|
|
doc.Id,
|
|
doc.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Id)
|
|
};
|
|
disciplineDisciplinary_DocSummaryEvidences.Add(_doc);
|
|
}
|
|
var disciplineDisciplinary_DocRecordAccusers = new List<dynamic>();
|
|
foreach (var doc in _data.DisciplineDisciplinary_DocRecordAccusers)
|
|
{
|
|
var _doc = new
|
|
{
|
|
doc.Id,
|
|
doc.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Id)
|
|
};
|
|
disciplineDisciplinary_DocRecordAccusers.Add(_doc);
|
|
}
|
|
var disciplineDisciplinary_DocWitnessess = new List<dynamic>();
|
|
foreach (var doc in _data.DisciplineDisciplinary_DocWitnessess)
|
|
{
|
|
var _doc = new
|
|
{
|
|
doc.Id,
|
|
doc.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Id)
|
|
};
|
|
disciplineDisciplinary_DocWitnessess.Add(_doc);
|
|
}
|
|
var disciplineDisciplinary_DocOthers = new List<dynamic>();
|
|
foreach (var doc in _data.DisciplineDisciplinary_DocOthers)
|
|
{
|
|
var _doc = new
|
|
{
|
|
doc.Id,
|
|
doc.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Id)
|
|
};
|
|
disciplineDisciplinary_DocOthers.Add(_doc);
|
|
}
|
|
var data = new
|
|
{
|
|
_data.Id,
|
|
_data.IdInvestigate,
|
|
_data.IdComplaint,
|
|
_data.DisciplinaryWitnesses,
|
|
_data.DisciplinaryRecordAccuser,
|
|
_data.DisciplinarySummaryEvidence,
|
|
_data.DisciplinaryRefLaw,
|
|
_data.DisciplinaryFaultLevel,
|
|
_data.DisciplinaryInvestigateAt,
|
|
_data.DisciplinaryCaseFault,
|
|
_data.DisciplinaryDateEvident,
|
|
_data.DisciplinaryDateAllegation,
|
|
_data.DisciplinaryDateStart,
|
|
_data.DisciplinaryDateEnd,
|
|
_data.DaysExtend,
|
|
_data.ExtendStatus,
|
|
_data.DisciplinaryDateInvestigation,
|
|
_data.DisciplinaryDateResult,
|
|
_data.DisciplinaryStatusResult,
|
|
_data.DisciplinaryCauseText,
|
|
_data.DisciplinaryResult,
|
|
_data.DisciplinaryExtendHistory,
|
|
_data.Status,
|
|
_data.Result,
|
|
_data.Director,
|
|
_data.RespondentType,
|
|
_data.Persons,
|
|
_data.OrganizationId,
|
|
disciplineDisciplinary_DocRelevants,
|
|
disciplineDisciplinary_DocSummaryEvidences,
|
|
disciplineDisciplinary_DocRecordAccusers,
|
|
disciplineDisciplinary_DocWitnessess,
|
|
disciplineDisciplinary_DocOthers,
|
|
};
|
|
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>> UpdateDisciplineDisciplinary([FromBody] DisciplineDisciplinaryRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.Include(x => x.DisciplineDisciplinary_DirectorInvestigates)
|
|
.ThenInclude(x => x.DisciplineDirector)
|
|
.Include(x => x.DisciplineDisciplinary_ProfileComplaintInvestigates)
|
|
.Include(x => x.DisciplineDisciplinaryExtends)
|
|
.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 editExtend = false;
|
|
if (data.DisciplinaryDateEnd != req.DisciplinaryDateEnd) editExtend = true;
|
|
|
|
data.DisciplinaryWitnesses = req.DisciplinaryWitnesses;
|
|
data.DisciplinaryRecordAccuser = req.DisciplinaryRecordAccuser;
|
|
data.DisciplinarySummaryEvidence = req.DisciplinarySummaryEvidence;
|
|
data.DisciplinaryRefLaw = req.DisciplinaryRefLaw;
|
|
data.DisciplinaryFaultLevel = req.DisciplinaryFaultLevel;
|
|
data.DisciplinaryInvestigateAt = req.DisciplinaryInvestigateAt;
|
|
data.DisciplinaryCaseFault = req.DisciplinaryCaseFault;
|
|
data.DisciplinaryDateEvident = req.DisciplinaryDateEvident;
|
|
data.DisciplinaryDateAllegation = req.DisciplinaryDateAllegation;
|
|
data.DisciplinaryDateStart = req.DisciplinaryDateStart;
|
|
data.DisciplinaryDateEnd = req.DisciplinaryDateEnd;
|
|
data.DisciplinaryDaysExtend = req.DaysExtend;
|
|
data.DisciplinaryExtendStatus = req.ExtendStatus;
|
|
data.DisciplinaryDateInvestigation = req.DisciplinaryDateInvestigation;
|
|
data.DisciplinaryDateResult = req.DisciplinaryDateResult;
|
|
data.DisciplinaryStatusResult = req.DisciplinaryStatusResult;
|
|
data.DisciplinaryCauseText = req.DisciplinaryCauseText;
|
|
data.DisciplinaryResult = req.DisciplinaryResult;
|
|
data.Result = req.Result;
|
|
data.LastUpdateFullName = FullName ?? "System Administrator";
|
|
data.LastUpdateUserId = UserId ?? "";
|
|
data.LastUpdatedAt = DateTime.Now;
|
|
if (editExtend == true)
|
|
{
|
|
var sumExtend = data.DisciplineDisciplinaryExtends.Count();
|
|
data.DisciplineDisciplinaryExtends.Add(
|
|
new DisciplineDisciplinaryExtend
|
|
{
|
|
Name = sumExtend > 0 ? "ขยายครั้งที่" + sumExtend : "วันที่สอบสวน",
|
|
Num = sumExtend,
|
|
DaysExtend = data.DisciplinaryDaysExtend,
|
|
DateStart = sumExtend > 0 ? data.DisciplinaryDateEnd.Value.AddDays(data.DisciplinaryDaysExtend == null ? 0 : -(double)data.DisciplinaryDaysExtend) : data.DisciplinaryDateStart,
|
|
DateEnd = data.DisciplinaryDateEnd,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
_context.DisciplineDisciplinary_DirectorInvestigates.RemoveRange(data.DisciplineDisciplinary_DirectorInvestigates);
|
|
foreach (var item in req.directors)
|
|
{
|
|
var director = await _context.DisciplineDirectors.AsQueryable()
|
|
.FirstOrDefaultAsync(x => x.Id == item);
|
|
if (director != null)
|
|
{
|
|
data.DisciplineDisciplinary_DirectorInvestigates.Add(
|
|
new DisciplineDisciplinary_DirectorInvestigate
|
|
{
|
|
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;
|
|
var hisprofile = data.DisciplineDisciplinary_ProfileComplaintInvestigates;
|
|
_context.DisciplineDisciplinary_ProfileComplaintInvestigates.RemoveRange(data.DisciplineDisciplinary_ProfileComplaintInvestigates);
|
|
if (data.RespondentType.Trim().ToUpper() == "PERSON")
|
|
{
|
|
foreach (var item in req.persons)
|
|
{
|
|
var isReport = hisprofile.Where(x => x.PersonId == item.personId).FirstOrDefault();
|
|
data.DisciplineDisciplinary_ProfileComplaintInvestigates.Add(
|
|
new DisciplineDisciplinary_ProfileComplaintInvestigate
|
|
{
|
|
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,
|
|
Status = isReport == null ? "NEW" : isReport.Status,
|
|
StatusDiscard = isReport == null ? "NEW" : isReport.StatusDiscard,
|
|
IsReport = isReport == null ? false : isReport.IsReport,
|
|
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>> RejectDisciplineDisciplinary(Guid id)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.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.DisciplinaryStatusResult == null || data.DisciplinaryStatusResult.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>
|
|
[HttpGet("approve/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> ApproveDisciplineDisciplinary(Guid id)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.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 = "DONE";
|
|
|
|
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>> ResumeDisciplineDisciplinary(Guid id)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.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>> UploadFileDisciplineDisciplinaryInvestigate([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.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 disciplineDisciplinary_DocInvestigate = new DisciplineDisciplinary_DocInvestigate
|
|
{
|
|
DisciplineDisciplinary = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineDisciplinary_DocInvestigates.AddAsync(disciplineDisciplinary_DocInvestigate);
|
|
}
|
|
}
|
|
}
|
|
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>> DeleteFileDisciplineDisciplinaryInvestigate(Guid id, Guid docId)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.Include(x => x.DisciplineDisciplinary_DocInvestigates)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.DisciplineInvestigate)
|
|
.ThenInclude(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.DisciplineDisciplinary_DocInvestigates.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineDisciplinary_DocInvestigates.Remove(dataDoc);
|
|
await _context.SaveChangesAsync();
|
|
var dataDocComplaint = data.DisciplineInvestigate.DisciplineInvestigate_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("complaint/file/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> UploadFileDisciplineDisciplinaryComplaint([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.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 disciplineDisciplinary_DocComplaintInvestigate = new DisciplineDisciplinary_DocComplaintInvestigate
|
|
{
|
|
DisciplineDisciplinary = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineDisciplinary_DocComplaintInvestigates.AddAsync(disciplineDisciplinary_DocComplaintInvestigate);
|
|
}
|
|
}
|
|
}
|
|
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>> DeleteFileDisciplineDisciplinaryComplaint(Guid id, Guid docId)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.Include(x => x.DisciplineDisciplinary_DocComplaintInvestigates)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.DisciplineInvestigate)
|
|
.ThenInclude(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.DisciplineDisciplinary_DocComplaintInvestigates.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineDisciplinary_DocComplaintInvestigates.Remove(dataDoc);
|
|
await _context.SaveChangesAsync();
|
|
var dataDocComplaint = data.DisciplineInvestigate.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("investigate/relevant/file/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> UploadFileDisciplineDisciplinaryInvestigateRelevant([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.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 disciplineDisciplinary_DocInvestigateRelevant = new DisciplineDisciplinary_DocInvestigateRelevant
|
|
{
|
|
DisciplineDisciplinary = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineDisciplinary_DocInvestigateRelevants.AddAsync(disciplineDisciplinary_DocInvestigateRelevant);
|
|
}
|
|
}
|
|
}
|
|
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("investigate/relevant/file/{id:guid}/{docId:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> DeleteFileDisciplineDisciplinaryInvestigateRelevant(Guid id, Guid docId)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.Include(x => x.DisciplineDisciplinary_DocInvestigateRelevants)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.DisciplineInvestigate)
|
|
.ThenInclude(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.DisciplineDisciplinary_DocInvestigateRelevants.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineDisciplinary_DocInvestigateRelevants.Remove(dataDoc);
|
|
await _context.SaveChangesAsync();
|
|
var dataDocComplaint = data.DisciplineInvestigate.DisciplineInvestigateRelevant_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>> UploadFileDisciplineDisciplinaryRelevants([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.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 disciplineDisciplinary_DocRelevant = new DisciplineDisciplinary_DocRelevant
|
|
{
|
|
DisciplineDisciplinary = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineDisciplinary_DocRelevants.AddAsync(disciplineDisciplinary_DocRelevant);
|
|
}
|
|
}
|
|
}
|
|
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>> DeleteFileDisciplineDisciplinaryRelevants(Guid id, Guid docId)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.Include(x => x.DisciplineDisciplinary_DocRelevants)
|
|
.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.DisciplineDisciplinary_DocRelevants.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineDisciplinary_DocRelevants.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("summaryEvidence/file/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> UploadFileDisciplineDisciplinarySummaryEvidences([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.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 disciplineDisciplinary_DocSummaryEvidence = new DisciplineDisciplinary_DocSummaryEvidence
|
|
{
|
|
DisciplineDisciplinary = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineDisciplinary_DocSummaryEvidences.AddAsync(disciplineDisciplinary_DocSummaryEvidence);
|
|
}
|
|
}
|
|
}
|
|
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("summaryEvidence/file/{id:guid}/{docId:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> DeleteFileDisciplineDisciplinarySummaryEvidences(Guid id, Guid docId)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.Include(x => x.DisciplineDisciplinary_DocSummaryEvidences)
|
|
.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.DisciplineDisciplinary_DocSummaryEvidences.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineDisciplinary_DocSummaryEvidences.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("recordAccuser/file/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> UploadFileDisciplineDisciplinaryRecordAccusers([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.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 disciplineDisciplinary_DocRecordAccuser = new DisciplineDisciplinary_DocRecordAccuser
|
|
{
|
|
DisciplineDisciplinary = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineDisciplinary_DocRecordAccusers.AddAsync(disciplineDisciplinary_DocRecordAccuser);
|
|
}
|
|
}
|
|
}
|
|
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("recordAccuser/file/{id:guid}/{docId:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> DeleteFileDisciplineDisciplinaryRecordAccusers(Guid id, Guid docId)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.Include(x => x.DisciplineDisciplinary_DocRecordAccusers)
|
|
.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.DisciplineDisciplinary_DocRecordAccusers.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineDisciplinary_DocRecordAccusers.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("witnesses/file/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> UploadFileDisciplineDisciplinaryWitnessess([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.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 disciplineDisciplinary_DocWitnesses = new DisciplineDisciplinary_DocWitnesses
|
|
{
|
|
DisciplineDisciplinary = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineDisciplinary_DocWitnessess.AddAsync(disciplineDisciplinary_DocWitnesses);
|
|
}
|
|
}
|
|
}
|
|
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("witnesses/file/{id:guid}/{docId:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> DeleteFileDisciplineDisciplinaryWitnessess(Guid id, Guid docId)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.Include(x => x.DisciplineDisciplinary_DocWitnessess)
|
|
.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.DisciplineDisciplinary_DocWitnessess.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineDisciplinary_DocWitnessess.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("other/file/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> UploadFileDisciplineDisciplinaryOther([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.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 disciplineDisciplinary_DocOther = new DisciplineDisciplinary_DocOther
|
|
{
|
|
DisciplineDisciplinary = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineDisciplinary_DocOthers.AddAsync(disciplineDisciplinary_DocOther);
|
|
}
|
|
}
|
|
}
|
|
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("other/file/{id:guid}/{docId:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> DeleteFileDisciplineDisciplinaryOther(Guid id, Guid docId)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.Include(x => x.DisciplineDisciplinary_DocOthers)
|
|
.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.DisciplineDisciplinary_DocOthers.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineDisciplinary_DocOthers.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("suspend/{id:length(36)}/{commandTypeId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> PostToSuspend([FromBody] DisciplinePersonIdRequest req, Guid id, Guid commandTypeId)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.Include(x => x.DisciplineDisciplinary_ProfileComplaintInvestigates)
|
|
.ThenInclude(x => x.DisciplineReport_Profiles)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
|
|
var persons = data.DisciplineDisciplinary_ProfileComplaintInvestigates.Where(x => req.persons.Contains(x.Id)).ToList();
|
|
foreach (var item in persons)
|
|
{
|
|
var personIdDupicate = data.DisciplineDisciplinary_ProfileComplaintInvestigates.Where(x => x.PersonId == item.PersonId && x.Status == "NEW").FirstOrDefault();
|
|
if (personIdDupicate == null)
|
|
continue;
|
|
if (personIdDupicate.DisciplineReport_Profiles.Count() > 0)
|
|
continue;
|
|
personIdDupicate.DisciplineReport_Profiles.Add(
|
|
new DisciplineReport_Profile
|
|
{
|
|
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,
|
|
Status = "PENDING",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
item.CommandTypeId = commandTypeId;
|
|
item.Status = "REPORT";
|
|
item.LastUpdateFullName = FullName ?? "System Administrator";
|
|
item.LastUpdateUserId = UserId ?? "";
|
|
item.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
|
|
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("discard/{id:length(36)}/{commandTypeId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> PostToDiscard([FromBody] DisciplinePersonIdRequest req, Guid id, Guid commandTypeId)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.Include(x => x.DisciplineDisciplinary_ProfileComplaintInvestigates)
|
|
.ThenInclude(x => x.DisciplineReport_Profiles)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
|
|
var persons = data.DisciplineDisciplinary_ProfileComplaintInvestigates.Where(x => req.persons.Contains(x.Id)).ToList();
|
|
foreach (var item in persons)
|
|
{
|
|
var personIdDupicate = data.DisciplineDisciplinary_ProfileComplaintInvestigates.Where(x => x.PersonId == item.PersonId && x.Status == "REPORT" && x.StatusDiscard == "NEW").FirstOrDefault();
|
|
if (personIdDupicate == null)
|
|
continue;
|
|
if (personIdDupicate.DisciplineReport_Profiles.Count() > 0)
|
|
continue;
|
|
personIdDupicate.DisciplineReport_Profiles.Add(
|
|
new DisciplineReport_Profile
|
|
{
|
|
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,
|
|
Status = "PENDING",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
item.CommandTypeDiscardId = commandTypeId;
|
|
item.StatusDiscard = "REPORT";
|
|
item.LastUpdateFullName = FullName ?? "System Administrator";
|
|
item.LastUpdateUserId = UserId ?? "";
|
|
item.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
|
|
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>
|
|
[HttpPost("calendar")]
|
|
public async Task<ActionResult<ResponseObject>> GetCalendarDisciplineDisciplinary([FromBody] DisciplineCalendarRequest req)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.Where(x => x.DisciplinaryDateStart != null)
|
|
.Where(x => x.DisciplinaryDateEnd != null)
|
|
.Where(x => x.DisciplinaryDateStart.Value.Year == req.year || x.DisciplinaryDateEnd.Value.Year == req.year || x.DisciplinaryDateStart.Value.Month == req.month || x.DisciplinaryDateEnd.Value.Month == req.month)
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องสอบสวน
|
|
Title = x.Title,//ชื่อเรื่อง
|
|
DisciplinaryDateStart = x.DisciplinaryDateStart,//
|
|
DisciplinaryDateEnd = x.DisciplinaryDateEnd,//
|
|
})
|
|
.OrderBy(d => d.DisciplinaryDateStart.Value.Date)
|
|
.ToListAsync();
|
|
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("report")]
|
|
// [HttpPut("report/{commandTypeId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> PostToReport([FromBody] DisciplineProfileRequest req)
|
|
{
|
|
foreach (var item in req.Id)
|
|
{
|
|
var uppdated = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates
|
|
.FirstOrDefaultAsync(x => x.Id == item);
|
|
if (uppdated == null)
|
|
continue;
|
|
|
|
// uppdated.CommandTypeId = commandTypeId;
|
|
uppdated.IsReport = true;
|
|
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
uppdated.LastUpdateUserId = UserId ?? "";
|
|
uppdated.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
}
|
|
}
|