using FastEndpoints; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.Applicant; using System.Linq; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.Applicant { public class GetSelectListApplicant : BaseEndpoint> { private readonly IApplicantBLL _ApplicantBLL; public GetSelectListApplicant(IApplicantBLL ApplicantBLL) { _ApplicantBLL = ApplicantBLL; } public override void Configure() { Post("/Applicant/GetSelectListApplicant"); AllowAnonymous(); } public record GetSelectListApplicantParameters( [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult, [property: QueryParam] int Type, [property: FromHeader] string Login, [property: FromBody] CriteriaDTO CriteriaDTO ); protected override async Task> ExecuteAsync(GetSelectListApplicantParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _ApplicantBLL.GetSelectListApplicant(req.FirstNumber, req.MaxResult, req.Type, req.CriteriaDTO, loginDTO!); var countResult = await _ApplicantBLL.GetSelectListApplicant(-1, -1, req.Type, req.CriteriaDTO, loginDTO!, true); int total = countResult.Count > 0 ? countResult[0].TotalCount : 0; var response = await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, loginDTO); response.Total = total; return response; } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }