api ตำแหน่ง draft
This commit is contained in:
parent
6b7fcaaba2
commit
6a572144ab
42 changed files with 32604 additions and 1 deletions
150
BMA.EHR.Insignia.Service/Controllers/InsigniaPeriodController.cs
Normal file
150
BMA.EHR.Insignia.Service/Controllers/InsigniaPeriodController.cs
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
using System.Security.Claims;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Requests;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Models.Insignias;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/insignia/period")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("รอบเครื่องราช")]
|
||||
public class InsigniaPeriodController : BaseController
|
||||
{
|
||||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly InsigniaPeriodsRepository _repository;
|
||||
|
||||
public InsigniaPeriodController(ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
InsigniaPeriodsRepository repository,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_repository = repository;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
#region " Properties "
|
||||
|
||||
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||
|
||||
#endregion
|
||||
|
||||
[HttpGet("{type}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetList(string type)
|
||||
{
|
||||
var data = _context.InsigniaPeriods.AsQueryable()
|
||||
.Where(x => x.Type == type)
|
||||
.OrderByDescending(x => x.Year)
|
||||
.ThenByDescending(x => x.StartDate)
|
||||
.Select(p => new
|
||||
{
|
||||
period_id = p.Id,
|
||||
period_amount = p.Amount,
|
||||
period_name = p.Name,
|
||||
period_start = p.StartDate,
|
||||
period_end = p.EndDate,
|
||||
period_status = _repository.CalStatusByDate(p.StartDate, p.EndDate, p.Year.ToString()),
|
||||
period_year = p.Year
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
[HttpGet("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetById(Guid id)
|
||||
{
|
||||
var data = _context.InsigniaPeriods.AsQueryable()
|
||||
.Where(x => x.Id == id)
|
||||
.Select(p => new
|
||||
{
|
||||
period_id = p.Id,
|
||||
period_amount = p.Amount,
|
||||
period_name = p.Name,
|
||||
period_start = p.StartDate,
|
||||
period_end = p.EndDate,
|
||||
period_status = _repository.CalStatusByDate(p.StartDate, p.EndDate, p.Year.ToString()),
|
||||
period_year = p.Year,
|
||||
docs = new List<dynamic>()
|
||||
})
|
||||
.FirstOrDefault();
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
[HttpPost("{type}")]
|
||||
public async Task<ActionResult<ResponseObject>> Post([FromBody] InsigniaPeriodRequest req, string type)
|
||||
{
|
||||
if (req == null)
|
||||
return BadRequest();
|
||||
|
||||
var period = new InsigniaPeriod
|
||||
{
|
||||
Name = req.Name,
|
||||
Year = req.Year,
|
||||
StartDate = req.StartDate,
|
||||
EndDate = req.EndDate,
|
||||
Amount = req.Amount,
|
||||
Type = type
|
||||
};
|
||||
|
||||
_context.InsigniaPeriods.Add(period);
|
||||
_context.SaveChanges();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
[HttpDelete("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Delete(Guid id)
|
||||
{
|
||||
var deleted = _context.InsigniaPeriods.AsQueryable()
|
||||
.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
if (deleted == null)
|
||||
return NotFound();
|
||||
|
||||
_context.InsigniaPeriods.Remove(deleted);
|
||||
_context.SaveChanges();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
[HttpPut("{type}/{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Put([FromBody] InsigniaPeriodRequest req, Guid id, string type)
|
||||
{
|
||||
if (req == null)
|
||||
return BadRequest();
|
||||
|
||||
var uppdated = _context.InsigniaPeriods.AsQueryable()
|
||||
.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
if (uppdated == null)
|
||||
return NotFound();
|
||||
|
||||
uppdated.Name = req.Name;
|
||||
uppdated.Year = req.Year;
|
||||
uppdated.StartDate = req.StartDate;
|
||||
uppdated.EndDate = req.EndDate;
|
||||
uppdated.Amount = req.Amount;
|
||||
uppdated.Type = type;
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
return Success();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,213 @@
|
|||
using System.Security.Claims;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Requests;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Models.Insignias;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/insignia/receive")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("เครื่องราช")]
|
||||
public class InsigniaReceiveController : BaseController
|
||||
{
|
||||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly InsigniaPeriodsRepository _repository;
|
||||
|
||||
public InsigniaReceiveController(ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
InsigniaPeriodsRepository repository,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_repository = repository;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
[HttpGet("{type}/{ocId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetInsigniaList(string type, Guid ocId)
|
||||
{
|
||||
var result = _repository.GetInsigniaRequest(type, ocId);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
// var request = _context.InsigniaRequestProfiles
|
||||
// .Include(x => x.Request)
|
||||
// .ThenInclude(x => x.Period)
|
||||
// .Include(x => x.RequestInsignia)
|
||||
// .ThenInclude(x => x.InsigniaType)
|
||||
// .Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.AcademicStanding)
|
||||
// .Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.Position)
|
||||
// .Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.Insignias)
|
||||
// .ThenInclude(x => x.Insignia)
|
||||
// .ThenInclude(x => x.InsigniaType)
|
||||
// .Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.PositionNumber)
|
||||
// .Where(x => x.Request.Period.Id == result.PeriodId)
|
||||
// .Where(x => x.Request.RequestStatus == "st5p")
|
||||
// .Where(x => x.IsApprove)
|
||||
// .Select(p => new
|
||||
// {
|
||||
// Profile = p.Profile.Id,
|
||||
// Name = $"{p.Profile.Prefix} {p.Profile.FirstName} {p.Profile.LastName}",
|
||||
// Insignia = p.RequestInsignia,
|
||||
// Type = p.RequestInsignia.InsigniaType,
|
||||
// IsApprove = p.IsApprove,
|
||||
// InsigniaId = p.RequestInsignia.Id,
|
||||
// Year = p.Request.Period.Year,
|
||||
// Special = p.Special,
|
||||
// LastInsignia = p.Profile.Insignias.AsQueryable()
|
||||
// .Include(x => x.Insignia)
|
||||
// .Where(x => x.Insignia.Id == p.RequestInsignia.Id)
|
||||
// .Where(x => x.Year == p.Request.Period.Year)
|
||||
// .FirstOrDefault()
|
||||
// })
|
||||
// .ToList()
|
||||
// .Select(r => new InsigniaReceiveResponse
|
||||
// {
|
||||
// Profile = r.Profile,
|
||||
// Name = r.Name,
|
||||
// Insignia = r.Insignia.Name,
|
||||
// TypeId = r.Type == null ? null : r.Type.Id,
|
||||
// TypeName = r.Type == null ? "" : r.Type.Description,
|
||||
// IsApprove = r.IsApprove,
|
||||
// InsigniaId = r.InsigniaId,
|
||||
// InsigniaPage = r.LastInsignia == null ? "" : r.LastInsignia.Page,
|
||||
// InsigniaNo = r.LastInsignia == null ? "" : r.LastInsignia.No,
|
||||
// InsigniaIssue = r.LastInsignia == null ? "" : r.LastInsignia.Issue,
|
||||
// InsigniaVolumeno = r.LastInsignia == null ? "" : r.LastInsignia.VolumeNo,
|
||||
// InsigniaVolume = r.LastInsignia == null ? "" : r.LastInsignia.Volume,
|
||||
// InsigniaSection = r.LastInsignia == null ? "" : r.LastInsignia.Section,
|
||||
// InsigniaDatereceive = r.LastInsignia == null ? null : r.LastInsignia.DateReceive,
|
||||
// InsigniaDateannounce = r.LastInsignia == null ? null : r.LastInsignia.DateAnnounce,
|
||||
// Special = r.Special
|
||||
// })
|
||||
// .ToList()
|
||||
// .GroupBy(r => new { r.TypeId, r.TypeName })
|
||||
// .Select(r => new
|
||||
// {
|
||||
// TypeId = r.Key.TypeId,
|
||||
// InsigniaIssue = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaIssue : "",
|
||||
// InsigniaVolumeno = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaVolumeno : null,
|
||||
// InsigniaVolume = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaVolume : "",
|
||||
// InsigniaSection = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaSection : "",
|
||||
// InsigniaDatereceive = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaDatereceive : null,
|
||||
// InsigniaDateannounce = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaDateannounce : null,
|
||||
// TypeName = r.Key.TypeName,
|
||||
// Profile = r.Select(r => new
|
||||
// {
|
||||
// Profile = r.Profile,
|
||||
// Name = r.Name,
|
||||
// Insignia = r.Insignia,
|
||||
// InsigniaId = r.InsigniaId,
|
||||
// InsigniaPage = r.InsigniaPage,
|
||||
// InsigniaNo = r.InsigniaNo,
|
||||
// //Special = bool.Parse(r.Special)
|
||||
// }).ToList(),
|
||||
// Docs = new List<dynamic>()
|
||||
// });
|
||||
|
||||
return Success();
|
||||
// return Success(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("{type}")]
|
||||
public async Task<ActionResult<ResponseObject>> SaveToProfile([FromBody] SaveToProfileRequest items, string type)
|
||||
{
|
||||
var item = new Kp7Item
|
||||
{
|
||||
InsigniaDatereceive = items.InsigniaDatereceive,
|
||||
InsigniaLevel = items.InsigniaLevel,
|
||||
InsigniaIssue = items.InsigniaIssue,
|
||||
InsigniaVolumeno = items.InsigniaVolumeno,
|
||||
InsigniaVolume = items.InsigniaVolume,
|
||||
InsigniaSection = items.InsigniaSection,
|
||||
InsigniaDateannounce = items.InsigniaDateannounce
|
||||
};
|
||||
|
||||
if (items.Profile.Count() != 0)
|
||||
{
|
||||
// foreach (var i in items.Profile)
|
||||
// {
|
||||
// var profile = _context.Profiles.AsQueryable()
|
||||
// .Include(x => x.Insignias)
|
||||
// .ThenInclude(x => x.Insignia)
|
||||
// .Where(x => x.Id == i.FkProfileId)
|
||||
// .FirstOrDefault();
|
||||
// if (profile != null)
|
||||
// {
|
||||
// var kp7 = profile.Insignias.AsQueryable()
|
||||
// .Where(x => x.Insignia.Id == i.Kp7InsigniaId)
|
||||
// .FirstOrDefault();
|
||||
|
||||
// if (kp7 != null)
|
||||
// {
|
||||
// // exit item update to database
|
||||
// kp7.DateReceive = items.InsigniaDatereceive.Value;
|
||||
// kp7.Level = items.InsigniaLevel;
|
||||
// kp7.Issue = items.InsigniaIssue;
|
||||
// kp7.VolumeNo = items.InsigniaVolumeno.Value.ToString();
|
||||
// kp7.Volume = items.InsigniaVolume;
|
||||
// kp7.Section = items.InsigniaSection;
|
||||
// kp7.DateAnnounce = items.InsigniaDateannounce.Value;
|
||||
// kp7.Page = i.InsigniaPage;
|
||||
// kp7.No = i.InsigniaNo;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // insert new item to kp7
|
||||
// var insignia_item = _context.Insignias.FirstOrDefault(x => x.Id == i.Kp7InsigniaId);
|
||||
// var result = _repository.GetInsigniaRequest(type, items.OCId);
|
||||
|
||||
// var period = _context.InsigniaPeriods.FirstOrDefault(x => x.Id == result.PeriodId);
|
||||
|
||||
// kp7 = new Models.HR.ProfileInsignia
|
||||
// {
|
||||
// Order = profile.Insignias.ToList().Count + 1,
|
||||
// Year = period.Year,
|
||||
// Insignia = insignia_item,
|
||||
// DateReceive = items.InsigniaDatereceive.Value,
|
||||
// DateStamp = DateTime.Now,
|
||||
// Level = items.InsigniaLevel,
|
||||
// Issue = items.InsigniaIssue,
|
||||
// VolumeNo = items.InsigniaVolumeno.Value.ToString(),
|
||||
// Volume = items.InsigniaVolume,
|
||||
// Section = items.InsigniaSection,
|
||||
// DateAnnounce = items.InsigniaDateannounce.Value,
|
||||
// Page = i.InsigniaPage,
|
||||
// No = i.InsigniaNo,
|
||||
// };
|
||||
// profile.Insignias.Add(kp7);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// return NotFound("Profile not found!!!");
|
||||
// }
|
||||
}
|
||||
_context.SaveChanges();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,509 @@
|
|||
using System.Security.Claims;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Requests;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Models.Insignias;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/insignia/request")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("เครื่องราช")]
|
||||
public class InsigniaRequestController : BaseController
|
||||
{
|
||||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly InsigniaPeriodsRepository _repository;
|
||||
private readonly string Royal_Type = "Royal";
|
||||
|
||||
public InsigniaRequestController(ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
InsigniaPeriodsRepository repository,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_repository = repository;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
#region " Private "
|
||||
|
||||
private static string GetRequestlStatusText(string status)
|
||||
{
|
||||
switch (status.ToLower())
|
||||
{
|
||||
case "st1": return "จัดทำรายชื่อ";
|
||||
case "st2": return "รอ ผอ. โรงเรียนรับรอง";
|
||||
case "st3": return "รอเจ้าหน้าที่เขตตรวจสอบ";
|
||||
case "st3p": return "รอนำเสนอผู้อำนวยการเขต";
|
||||
case "st4": return "รอเสนอสำนักการศึกษา";
|
||||
case "st5": return "รอเจ้าหน้าที่ สนศ. ตรวจสอบ";
|
||||
case "st5p": return "เจ้าหน้าที่ สนศ. ตรวจสอบแล้ว";
|
||||
case "pending": return "รอออกคำสั่ง";
|
||||
case "finish": return "ออกคำสั่งแล้ว";
|
||||
default: return "สถานะไม่ถูกต้อง";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " ดึงเครื่องราชฯ ล่าสุดของครู (GetInsigniaLast) "
|
||||
private InsigniaItem GetInsigniaLast(Guid? id)
|
||||
{
|
||||
var insignia = _context.Insignias.AsQueryable()
|
||||
.Where(i => id != null ? i.Id == id : i.Name.Contains("ตริตาภรณ์มงกุฎไทย")).Select(i => new InsigniaItem
|
||||
{
|
||||
Id = i.Id,
|
||||
Name = i.Name,
|
||||
ShortName = i.ShortName,
|
||||
Level = i.InsigniaType == null ? null : i.InsigniaType.Name,
|
||||
LevelId = i.InsigniaType == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : i.InsigniaType.Id
|
||||
}).FirstOrDefault();
|
||||
|
||||
return insignia;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region " จัดทำรายชื่อครูที่มีสิทธิในการยืนขอเครื่องราชฯ "
|
||||
|
||||
[HttpGet("old/{role}/{ocId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetInsignaiRequest(Guid ocId, string role)
|
||||
{
|
||||
var result = await _repository.GetInsigniaRequest(Royal_Type, ocId);
|
||||
if (result != null)
|
||||
{
|
||||
Guid period = result.PeriodId;
|
||||
string periodName = result.Name;
|
||||
string requestStatus = result.RequestStatus;
|
||||
var resend = new InsigniaResults
|
||||
{
|
||||
PeriodId = period,
|
||||
Year = result.Year,
|
||||
Name = periodName,
|
||||
RequestStatus = requestStatus,
|
||||
OrganizationName = result.OrganizationName,
|
||||
Items = new List<InsigniaRequestItem>()
|
||||
};
|
||||
var candidate = _repository.GetInsigniaCandidate(period, ocId);
|
||||
|
||||
// ตรวจสอบว่ารายการอยู่ใน table insignia_request_new
|
||||
if (requestStatus == null)
|
||||
{
|
||||
// บันทึกรายชื่อ
|
||||
_repository.InsertCandidate(period, ocId, candidate);
|
||||
}
|
||||
if (role == "officer")
|
||||
{
|
||||
resend.Items = _repository.InsigniaHasProfile(period, ocId);
|
||||
return Success(resend);
|
||||
}
|
||||
else
|
||||
{
|
||||
var passData = _context.InsigniaRequests.AsQueryable()
|
||||
.Include(x => x.OrganizationOrganization)
|
||||
.Include(x => x.RequestProfiles)
|
||||
.Where(x => x.OrganizationOrganization.Id == ocId)
|
||||
.Where(x => x.Period.Id == period)
|
||||
.Select(ir => new
|
||||
{
|
||||
requstID = ir.Id,
|
||||
requstStatus = ir.RequestStatus,
|
||||
requstStatusName = GetRequestlStatusText(ir.RequestStatus),
|
||||
fkInstituteId = -1,
|
||||
fkDivisionId = ir.OrganizationOrganization.Id,
|
||||
fkDivision = ir.OrganizationOrganization.Name,
|
||||
fkInstitute = "",
|
||||
fkPeriodId = ir.Period.Id,
|
||||
insigniaRequestHasProfile = ir.RequestProfiles.AsQueryable()
|
||||
.Include(x => x.Profile)
|
||||
.ThenInclude(x => x.Position)
|
||||
.Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.PositionNumber)
|
||||
.Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.AcademicStanding)
|
||||
.Include(x => x.RequestInsignia)
|
||||
.ThenInclude(x => x.InsigniaType)
|
||||
.Select(irp => new
|
||||
{
|
||||
request_id = irp.Request.Id,
|
||||
isApprove = irp.IsApprove,
|
||||
statusInstitute = irp.IsApprove.ToString(),
|
||||
request_date = irp.RequestDate,
|
||||
profileId = irp.Profile.Id,
|
||||
// prefix = irp.Profile.Prefix,
|
||||
firstname = irp.Profile.FirstName,
|
||||
lastname = irp.Profile.LastName,
|
||||
// posno = irp.Profile.PositionNumber.Id,
|
||||
type = irp.Profile.ProfileType,
|
||||
// position = irp.Profile.Position.Name,
|
||||
// rank = irp.Profile.AcademicStanding.Name,
|
||||
instituteName = "",
|
||||
instituteId = -1,
|
||||
// divisionName = irp.Profile.OrganizationOrganization.Name,
|
||||
// divisionId = irp.Profile.OrganizationOrganization.Id,
|
||||
lastInsigniaName = "",
|
||||
requestInsigniaLevel = irp.RequestInsignia.InsigniaType == null ? null : irp.RequestInsignia.InsigniaType.Name,
|
||||
requestInsigniaName = irp.RequestInsignia.Name,
|
||||
requestQua = irp.QualificationStatus,
|
||||
requestDoc = irp.DocumentStatus,
|
||||
requestNote = irp.Note,
|
||||
requestSalary = irp.Salary,
|
||||
})
|
||||
.Where(x => x.isApprove)
|
||||
.OrderBy(y => y.profileId)
|
||||
.ToList()
|
||||
})
|
||||
.ToList()
|
||||
.FirstOrDefault();
|
||||
|
||||
var failData = _context.InsigniaRequests.AsQueryable()
|
||||
.Include(x => x.OrganizationOrganization)
|
||||
.Include(x => x.RequestProfiles)
|
||||
.Where(x => x.OrganizationOrganization.Id == ocId)
|
||||
.Where(x => x.Period.Id == period)
|
||||
.Select(ir => new
|
||||
{
|
||||
requstID = ir.Id,
|
||||
requstStatus = ir.RequestStatus,
|
||||
requstStatusName = GetRequestlStatusText(ir.RequestStatus),
|
||||
fkInstituteId = -1,
|
||||
fkDivisionId = ir.OrganizationOrganization.Id,
|
||||
fkDivision = ir.OrganizationOrganization.Name,
|
||||
fkInstitute = "",
|
||||
fkPeriodId = ir.Period.Id,
|
||||
insigniaRequestHasProfile = ir.RequestProfiles.AsQueryable()
|
||||
.Include(x => x.Profile)
|
||||
.ThenInclude(x => x.Position)
|
||||
.Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.PositionNumber)
|
||||
.Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.AcademicStanding)
|
||||
.Include(x => x.RequestInsignia)
|
||||
.ThenInclude(x => x.InsigniaType)
|
||||
.Select(irp => new
|
||||
{
|
||||
request_id = irp.Request.Id,
|
||||
isApprove = irp.IsApprove,
|
||||
statusInstitute = irp.IsApprove.ToString(),
|
||||
request_date = irp.RequestDate,
|
||||
profileId = irp.Profile.Id,
|
||||
// prefix = irp.Profile.Prefix,
|
||||
firstname = irp.Profile.FirstName,
|
||||
lastname = irp.Profile.LastName,
|
||||
// posno = irp.Profile.PositionNumber.Id,
|
||||
type = irp.Profile.ProfileType,
|
||||
// position = irp.Profile.Position.Name,
|
||||
// rank = irp.Profile.AcademicStanding.Name,
|
||||
instituteName = "",
|
||||
instituteId = -1,
|
||||
// divisionName = irp.Profile.OrganizationOrganization.Name,
|
||||
// divisionId = irp.Profile.OrganizationOrganization.Id,
|
||||
lastInsigniaName = "",
|
||||
requestInsigniaLevel = irp.RequestInsignia.InsigniaType == null ? null : irp.RequestInsignia.InsigniaType.Name,
|
||||
requestInsigniaName = irp.RequestInsignia.Name,
|
||||
requestQua = irp.QualificationStatus,
|
||||
requestDoc = irp.DocumentStatus,
|
||||
requestNote = irp.Note,
|
||||
requestSalary = irp.Salary,
|
||||
})
|
||||
.Where(x => !x.isApprove)
|
||||
.OrderBy(y => y.profileId)
|
||||
.ToList()
|
||||
})
|
||||
.ToList()
|
||||
.FirstOrDefault();
|
||||
|
||||
var period_data = (from p in _context.InsigniaPeriods.AsQueryable()
|
||||
where p.Id == period
|
||||
select new
|
||||
{
|
||||
periodName = p.Name,
|
||||
periodYear = p.Year,
|
||||
}).FirstOrDefault();
|
||||
|
||||
return Success(new { passData = passData, failData = failData, period = period_data });
|
||||
}
|
||||
// select data to display
|
||||
}
|
||||
return Success();
|
||||
}
|
||||
|
||||
[HttpGet("{role}/{ocId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetInsignaiRequestBkk(Guid ocId, string role)
|
||||
{
|
||||
var result = await _repository.GetInsigniaRequest(Royal_Type, ocId);
|
||||
if (result != null)
|
||||
{
|
||||
Guid period = result.PeriodId;
|
||||
string periodName = result.Name;
|
||||
string requestStatus = result.RequestStatus;
|
||||
var resend = new InsigniaResults
|
||||
{
|
||||
PeriodId = period,
|
||||
Year = result.Year,
|
||||
Name = periodName,
|
||||
RequestStatus = requestStatus,
|
||||
OrganizationName = result.OrganizationName,
|
||||
Items = new List<InsigniaRequestItem>()
|
||||
};
|
||||
var candidate = _repository.GetInsigniaCandidateBKK(period, ocId);
|
||||
|
||||
// ตรวจสอบว่ารายการอยู่ใน table insignia_request_new
|
||||
if (requestStatus == null)
|
||||
{
|
||||
// บันทึกรายชื่อ
|
||||
_repository.InsertCandidate(period, ocId, candidate);
|
||||
}
|
||||
if (role == "officer")
|
||||
{
|
||||
resend.Items = _repository.InsigniaHasProfile(period, ocId);
|
||||
return Success(resend);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var passData = _context.InsigniaRequests.AsQueryable()
|
||||
.Include(x => x.OrganizationOrganization)
|
||||
.Include(x => x.RequestProfiles)
|
||||
.Where(x => x.OrganizationOrganization.Id == ocId)
|
||||
.Where(x => x.Period.Id == period)
|
||||
.Select(ir => new
|
||||
{
|
||||
requstID = ir.Id,
|
||||
requstStatus = ir.RequestStatus,
|
||||
requstStatusName = GetRequestlStatusText(ir.RequestStatus),
|
||||
fkInstituteId = -1,
|
||||
fkDivisionId = ir.OrganizationOrganization.Id,
|
||||
fkDivision = ir.OrganizationOrganization.Name,
|
||||
fkInstitute = "",
|
||||
fkPeriodId = ir.Period.Id,
|
||||
insigniaRequestHasProfile = ir.RequestProfiles.AsQueryable()
|
||||
.Include(x => x.Profile)
|
||||
.ThenInclude(x => x.Position)
|
||||
.Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.PositionNumber)
|
||||
.Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.AcademicStanding)
|
||||
.Include(x => x.RequestInsignia)
|
||||
.ThenInclude(x => x.InsigniaType)
|
||||
.Select(irp => new
|
||||
{
|
||||
request_id = irp.Request.Id,
|
||||
isApprove = irp.IsApprove,
|
||||
statusInstitute = irp.IsApprove.ToString(),
|
||||
request_date = irp.RequestDate,
|
||||
profileId = irp.Profile.Id,
|
||||
// prefix = irp.Profile.Prefix,
|
||||
firstname = irp.Profile.FirstName,
|
||||
lastname = irp.Profile.LastName,
|
||||
// posno = irp.Profile.PositionNumber.Id,
|
||||
type = irp.Profile.ProfileType,
|
||||
// position = irp.Profile.Position.Name,
|
||||
// rank = $"{irp.Profile.PositionType.Name}/{irp.Profile.PositionLevel.Name}",
|
||||
instituteName = "",
|
||||
instituteId = -1,
|
||||
// divisionName = irp.Profile.OrganizationOrganization.Name,
|
||||
// divisionId = irp.Profile.OrganizationOrganization.Id,
|
||||
lastInsigniaName = "",
|
||||
requestInsigniaLevel = irp.RequestInsignia.InsigniaType.Name,
|
||||
requestInsigniaName = irp.RequestInsignia.Name,
|
||||
requestQua = irp.QualificationStatus,
|
||||
requestDoc = irp.DocumentStatus,
|
||||
requestNote = irp.Note,
|
||||
requestSalary = irp.Salary,
|
||||
matchingConditions = JsonConvert.DeserializeObject<List<MatchingCondition>>(irp.MatchingConditions)
|
||||
})
|
||||
.Where(x => x.isApprove)
|
||||
.OrderBy(y => y.profileId)
|
||||
.ToList()
|
||||
})
|
||||
.ToList()
|
||||
.FirstOrDefault();
|
||||
|
||||
var failData = _context.InsigniaRequests.AsQueryable()
|
||||
.Include(x => x.OrganizationOrganization)
|
||||
.Include(x => x.RequestProfiles)
|
||||
.Where(x => x.OrganizationOrganization.Id == ocId)
|
||||
.Where(x => x.Period.Id == period)
|
||||
.Select(ir => new
|
||||
{
|
||||
requstID = ir.Id,
|
||||
requstStatus = ir.RequestStatus,
|
||||
requstStatusName = GetRequestlStatusText(ir.RequestStatus),
|
||||
fkInstituteId = -1,
|
||||
fkDivisionId = ir.OrganizationOrganization.Id,
|
||||
fkDivision = ir.OrganizationOrganization.Name,
|
||||
fkInstitute = "",
|
||||
fkPeriodId = ir.Period.Id,
|
||||
insigniaRequestHasProfile = ir.RequestProfiles.AsQueryable()
|
||||
.Include(x => x.Profile)
|
||||
.ThenInclude(x => x.Position)
|
||||
.Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.PositionNumber)
|
||||
.Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.AcademicStanding)
|
||||
.Include(x => x.RequestInsignia)
|
||||
.ThenInclude(x => x.InsigniaType)
|
||||
.Select(irp => new
|
||||
{
|
||||
request_id = irp.Request.Id,
|
||||
isApprove = irp.IsApprove,
|
||||
statusInstitute = irp.IsApprove.ToString(),
|
||||
request_date = irp.RequestDate,
|
||||
profileId = irp.Profile.Id,
|
||||
// prefix = irp.Profile.Prefix,
|
||||
firstname = irp.Profile.FirstName,
|
||||
lastname = irp.Profile.LastName,
|
||||
// posno = irp.Profile.PositionNumber.Id,
|
||||
type = irp.Profile.ProfileType,
|
||||
// position = irp.Profile.Position.Name,
|
||||
// rank = irp.Profile.AcademicStanding.Name,
|
||||
instituteName = "",
|
||||
instituteId = -1,
|
||||
// divisionName = irp.Profile.OrganizationOrganization.Name,
|
||||
// divisionId = irp.Profile.OrganizationOrganization.Id,
|
||||
lastInsigniaName = "",
|
||||
requestInsigniaLevel = irp.RequestInsignia.InsigniaType.Name,
|
||||
requestInsigniaName = irp.RequestInsignia.Name,
|
||||
requestQua = irp.QualificationStatus,
|
||||
requestDoc = irp.DocumentStatus,
|
||||
requestNote = irp.Note,
|
||||
requestSalary = irp.Salary,
|
||||
matchingConditions = JsonConvert.DeserializeObject<List<MatchingCondition>>(irp.MatchingConditions)
|
||||
})
|
||||
.Where(x => !x.isApprove)
|
||||
.OrderBy(y => y.profileId)
|
||||
.ToList()
|
||||
})
|
||||
.ToList()
|
||||
.FirstOrDefault();
|
||||
|
||||
var period_data = (from p in _context.InsigniaPeriods.AsQueryable()
|
||||
where p.Id == period
|
||||
select new
|
||||
{
|
||||
periodName = p.Name,
|
||||
periodYear = p.Year,
|
||||
}).FirstOrDefault();
|
||||
|
||||
return Success(new { passData = passData, failData = failData, period = period_data });
|
||||
}
|
||||
// select data to display
|
||||
}
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " บันทึกหมายเหตุ "
|
||||
|
||||
[HttpPut("note/{profileId}")]
|
||||
public async Task<ActionResult<ResponseObject>> SaveNote(Guid profileId, SaveRequsetNote items)
|
||||
{
|
||||
var id = await _repository.GetRequestId(items.PeriodId, items.OcId);
|
||||
var note = _context.InsigniaRequestProfiles.AsQueryable()
|
||||
.Where(d => d.Profile.Id == profileId && d.Request.Id == id).FirstOrDefault();
|
||||
if (note != null)
|
||||
note.Note = items.Note;
|
||||
_context.SaveChanges();
|
||||
return Success();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " บันทึกรายชื่อครูในการขอยื่นเครื่องราชฯ เเต่ยังไม่ส่งไปยัง ผอ.โรงเรียน "
|
||||
|
||||
[HttpPut("approve/{ocId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> SaveRequestList(Guid ocId, InsigniaApproveRequest items)
|
||||
{
|
||||
var result = await _repository.GetInsigniaRequest(Royal_Type, ocId);
|
||||
if (result != null)
|
||||
await _repository.SaveAprove(result.PeriodId, ocId, items);
|
||||
return Success();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " เปลี่ยน status เป็น st2 รอ ผอ.สำนักรับรอง "
|
||||
|
||||
[HttpPost("status/officer/send/{ocId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> ChangeStatusToSt2(Guid ocId, InsigniaApproveRequest items)
|
||||
{
|
||||
var result = await _repository.GetInsigniaRequest(Royal_Type, ocId);
|
||||
|
||||
if (items != null)
|
||||
{
|
||||
_repository.SaveAprove(result.PeriodId, ocId, items);
|
||||
}
|
||||
var requestId = await _repository.GetRequestId(result.PeriodId, ocId);
|
||||
var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId);
|
||||
if (requestNew != null)
|
||||
{
|
||||
requestNew.RequestStatus = "st2";
|
||||
_context.SaveChanges();
|
||||
return Success();
|
||||
}
|
||||
else
|
||||
return Error(GlobalMessages.InvalidInsigniaRequest);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " เปลี่ยน status สำหรับ ผอ.สำนัก "
|
||||
|
||||
[HttpPost("status/director/approve/{ocId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> ChangeStatusToSt5p(Guid ocId)
|
||||
{
|
||||
var result = await _repository.GetInsigniaRequest(Royal_Type, ocId);
|
||||
if (result == null)
|
||||
return Error(GlobalMessages.InvalidInsigniaRequest);
|
||||
var requestId = await _repository.GetRequestId(result.PeriodId, ocId);
|
||||
if (requestId == null)
|
||||
return Error(GlobalMessages.InvalidInsigniaRequest);
|
||||
var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId);
|
||||
if (requestNew != null)
|
||||
{
|
||||
requestNew.RequestStatus = "st5p";
|
||||
_context.SaveChanges();
|
||||
return Success();
|
||||
}
|
||||
else
|
||||
return Error(GlobalMessages.InvalidInsigniaRequest);
|
||||
}
|
||||
|
||||
[HttpPost("status/director/reject/{ocId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> ChangeStatusToSt1(Guid ocId)
|
||||
{
|
||||
var result = await _repository.GetInsigniaRequest(Royal_Type, ocId);
|
||||
if (result == null)
|
||||
return Error(GlobalMessages.InvalidInsigniaRequest);
|
||||
var requestId = await _repository.GetRequestId(result.PeriodId, ocId);
|
||||
if (requestId == null)
|
||||
return Error(GlobalMessages.InvalidInsigniaRequest);
|
||||
var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId);
|
||||
if (requestNew != null)
|
||||
{
|
||||
requestNew.RequestStatus = "st1";
|
||||
_context.SaveChanges();
|
||||
return Success();
|
||||
}
|
||||
else
|
||||
return Error(GlobalMessages.InvalidInsigniaRequest);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue