sort Discipline

This commit is contained in:
Adisak 2025-10-06 16:28:16 +07:00
parent d0599aedea
commit 12c8bc5014
11 changed files with 503 additions and 34 deletions

View file

@ -9,9 +9,10 @@ using BMA.EHR.Infrastructure.Persistence;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Swashbuckle.AspNetCore.Annotations;
using System.Linq;
using System.Security.Claims;
namespace BMA.EHR.DisciplineSuspend.Service.Controllers
@ -58,7 +59,7 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet()]
public async Task<ActionResult<ResponseObject>> GetDisciplineSuspend(DateTime? startDate, DateTime? endDate, int page = 1, int pageSize = 25, string keyword = "", string profileType = "")
public async Task<ActionResult<ResponseObject>> GetDisciplineSuspend(DateTime? startDate, DateTime? endDate, int page = 1, int pageSize = 25, string keyword = "", string profileType = "", string? sortBy = "", bool? descending = false)
{
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_DISCIPLINE_SUSPENDED");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
@ -94,7 +95,7 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers
(profileType.ToUpper() == "EMPLOYEE" && x.profileType == "EMPLOYEE")
)
select x).ToList();
var data = data_search
var query = data_search
.Select(x => new
{
Id = x.Id,
@ -145,13 +146,76 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers
DisciplinaryCaseFault = x.DisciplineDisciplinary.DisciplinaryCaseFault,//กรณีความผิด
profileType = x.profileType,
CreatedAt = x.CreatedAt,
})
.OrderByDescending(x => x.profileType)
.ThenByDescending(x => x.CreatedAt)
.ThenByDescending(x => x.CitizenId)
});
bool desc = descending ?? false;
if (!string.IsNullOrEmpty(sortBy))
{
if (sortBy == "title")
{
query = desc ? query.OrderByDescending(x => x.Title)
: query.OrderBy(x => x.Title);
}
else if (sortBy == "prefix" || sortBy == "firstName" || sortBy == "lastName")
{
query = desc ?
query
//.OrderByDescending(x => x.Prefix)
.OrderByDescending(x => x.FirstName)
.ThenByDescending(x => x.LastName) :
query
//.OrderBy(x => x.Prefix)
.OrderBy(x => x.FirstName)
.ThenBy(x => x.LastName);
}
else if (sortBy == "position")
{
query = desc ? query.OrderByDescending(x => x.Position)
: query.OrderBy(x => x.Position);
}
else if (sortBy == "positionType" || sortBy == "positionLevel")
{
query = desc ?
query
.OrderByDescending(x => x.PositionType)
.ThenByDescending(x => x.PositionLevel) :
query
.OrderBy(x => x.PositionType)
.ThenBy(x => x.PositionLevel);
}
else if (sortBy == "organization")
{
query = desc ? query.OrderByDescending(x => x.Organization)
: query.OrderBy(x => x.Organization);
}
else if (sortBy == "startDateSuspend")
{
query = desc ? query.OrderByDescending(x => x.StartDateSuspend)
: query.OrderBy(x => x.StartDateSuspend);
}
else if (sortBy == "endDateSuspend")
{
query = desc ? query.OrderByDescending(x => x.EndDateSuspend)
: query.OrderBy(x => x.EndDateSuspend);
}
else if (sortBy == "descriptionSuspend")
{
query = desc ? query.OrderByDescending(x => x.DescriptionSuspend)
: query.OrderBy(x => x.DescriptionSuspend);
}
else
{
query = query.OrderByDescending(x => x.profileType)
.ThenByDescending(x => x.CreatedAt)
.ThenByDescending(x => x.CitizenId);
}
}
var data = query
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToList();
return Success(new { data, total = data_search.Count() });
}