409 lines
18 KiB
C#
409 lines
18 KiB
C#
using BMA.EHR.Recurit.Exam.Service.Core;
|
|
using BMA.EHR.Recurit.Exam.Service.Models;
|
|
using BMA.EHR.Recurit.Exam.Service.Request;
|
|
using BMA.EHR.Recurit.Exam.Service.Response;
|
|
using BMA.EHR.Recurit.Exam.Service.Services;
|
|
using BMA.EHR.Recurit.Exam.Service.Request;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/cms")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("จัดการข้อมูลหน้าเว็บสมัครสอบ เพื่อนำไปใช้งานในระบบ")]
|
|
public class CMSCandidateController : BaseController
|
|
{
|
|
#region " Fields "
|
|
|
|
private readonly CMSCandidateService _cmsCandidateService;
|
|
private readonly PermissionRepository _permission;
|
|
|
|
#endregion
|
|
|
|
#region " Constructor and Destructor "
|
|
|
|
public CMSCandidateController(CMSCandidateService cmsCandidateService, PermissionRepository permission)
|
|
{
|
|
_cmsCandidateService = cmsCandidateService;
|
|
_permission = permission;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Methods "
|
|
|
|
/// <summary>
|
|
/// แสดงข้อมูลรายละเอียดหน้าเว็บสมัครสอบ
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านแสดงข้อมูลรายละเอียดหน้าเว็บสมัครสอบสำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetsAsync()
|
|
{
|
|
try
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_EXAM_WEBSITE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var items = await _cmsCandidateService.GetsAsync();
|
|
|
|
return Success(items);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// อัพเดทข้อมูล รายละเอียดหน้าเว็บ ผู้สมัคร
|
|
/// </summary>
|
|
/// <param name="detail">รายละเอียดหน้าเว็บ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอัพเดทข้อมูล รายละเอียดหน้าเว็บ ผู้สมัคร สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("detail")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> UpdateDetailAsync(RequestCMSAbout detail)
|
|
{
|
|
try
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_EXAM_WEBSITE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
await _cmsCandidateService.UpdateDetailAsync(detail);
|
|
|
|
return Success();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// อัพเดทข้อมูล ข้อมูลเกี่ยวกับเรา ผู้สมัคร
|
|
/// </summary>
|
|
/// <param name="about">ข้อมูลเกี่ยวกับเรา</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอัพเดทข้อมูล ข้อมูลเกี่ยวกับเรา ผู้สมัคร สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("about")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> UpdateAboutAsync(RequestCMSAbout about)
|
|
{
|
|
try
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_EXAM_WEBSITE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
await _cmsCandidateService.UpdateAboutAsync(about);
|
|
|
|
return Success();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// อัพเดทข้อมูล โลโก้เว็บไซย์ ผู้สมัคร
|
|
/// </summary>
|
|
/// <param name="logo">โลโก้เว็บไซย์</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอัพเดทข้อมูล โลโก้เว็บไซย์ ผู้สมัคร สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("logo"), DisableRequestSizeLimit]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> UpdateLogoAsync()
|
|
{
|
|
try
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_EXAM_WEBSITE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
|
{
|
|
return Error(GlobalMessages.NoFileToUpload);
|
|
}
|
|
|
|
var file = Request.Form.Files[0];
|
|
await _cmsCandidateService.UpdateLogoAsync(file);
|
|
|
|
return Success();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// อัพเดทข้อมูล Banner ผู้สมัคร
|
|
/// </summary>
|
|
/// <param name="banner">Banner</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอัพเดทข้อมูล Banner ผู้สมัคร สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("banner"), DisableRequestSizeLimit]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> UpdateBannerAsync()
|
|
{
|
|
try
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_EXAM_WEBSITE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
|
{
|
|
return Error(GlobalMessages.NoFileToUpload);
|
|
}
|
|
|
|
var file = Request.Form.Files[0];
|
|
await _cmsCandidateService.UpdateBannerAsync(file);
|
|
|
|
return Success();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// อัพเดทข้อมูล Agency ผู้สมัคร
|
|
/// </summary>
|
|
/// <param name="agency">Agency</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอัพเดทข้อมูล Agency ผู้สมัคร สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("agency")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> UpdateAgencyAsync(List<RequestCMSAgency> agency)
|
|
{
|
|
try
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_EXAM_WEBSITE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
await _cmsCandidateService.UpdateAgencyAsync(agency);
|
|
|
|
return Success();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// อัพเดทข้อมูล Government ผู้สมัคร
|
|
/// </summary>
|
|
/// <param name="government">Government</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอัพเดทข้อมูล Government ผู้สมัคร สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("government")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> UpdateGovernmentAsync(List<RequestCMSGovernment> government)
|
|
{
|
|
try
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_EXAM_WEBSITE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
await _cmsCandidateService.UpdateGovernmentAsync(government);
|
|
|
|
return Success();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ข้อมูล home page cms
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการข้อมูล home page cms สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("home")]
|
|
[AllowAnonymous]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<HomePageResponseItem?> GetHomePageAsync()
|
|
{
|
|
// try
|
|
// {
|
|
var item = await _cmsCandidateService.GetHomePageAsync();
|
|
|
|
return item;
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// return null;
|
|
// }
|
|
}
|
|
|
|
/// <summary>
|
|
/// ข้อมูล content home page
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการข้อมูล content home page สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("content/home")]
|
|
[AllowAnonymous]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<HomePageContentResponseItem?> GetHomePageContentAsync()
|
|
{
|
|
// try
|
|
// {
|
|
var item = await _cmsCandidateService.GetHomePageContentAsync();
|
|
|
|
return item;
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// return null;
|
|
// }
|
|
}
|
|
|
|
/// <summary>
|
|
/// ข้อมูล content about page
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการข้อมูล content about page สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("content/about")]
|
|
[AllowAnonymous]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<AboutPageContentResponseItem?> GetAboutPageContentAsync()
|
|
{
|
|
// try
|
|
// {
|
|
var item = await _cmsCandidateService.GetAboutPageContentAsync();
|
|
|
|
return item;
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// return null;
|
|
// }
|
|
}
|
|
|
|
/// <summary>
|
|
/// List ข้อมูลรอบสมัครสอบ
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการ List ข้อมูลรอบสมัครสอบ สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("qualifying")]
|
|
[AllowAnonymous]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<IEnumerable<CMSExamResponseItem?>> GetsCMSExamsAsync(int limit = 0)
|
|
{
|
|
// try
|
|
// {
|
|
var items = await _cmsCandidateService.GetsCMSExamsAsync(limit);
|
|
|
|
return items;
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// return null;
|
|
// }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get ข้อมูลรอบสมัครสอบ
|
|
/// </summary>
|
|
/// <param name="examId">รหัสรอบสมัคร</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการ Get ข้อมูลรอบสมัครสอบ สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("qualifying/{examId:length(36)}")]
|
|
[AllowAnonymous]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<CMSExamResponseItem?> GetCMSExamsAsync(string examId)
|
|
{
|
|
// try
|
|
// {
|
|
var item = await _cmsCandidateService.GetCMSExamsAsync(examId);
|
|
|
|
return item;
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// return null;
|
|
// }
|
|
}
|
|
#endregion
|
|
}
|
|
}
|