using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.Declaration; using PayRollDAL.DTO.Declaration; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.Declaration { public class DeclarationDetailBulkUpdate : BaseEndpoint> { private readonly IDeclarationBLL _DeclarationBLL; public DeclarationDetailBulkUpdate(IDeclarationBLL IDeclarationBLL) { _DeclarationBLL = IDeclarationBLL; } public override void Configure() { Post("/Declaration/DeclarationDetailBulkUpdate"); AllowAnonymous(); } public record DeclarationDetailBulkUpdateParameters( [property: FromHeader] string Login, [property: FromBody] List DeclarationDetailDTO ); protected override string? GetCacheKey(DeclarationDetailBulkUpdateParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( DeclarationDetailBulkUpdateParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _DeclarationBLL.DeclarationDetailBulkUpdate(req.DeclarationDetailDTO, LoginDTO!, ct); if (result) { return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( "Details Updated Successfully", CacheKeyLevel.NOT_REQUIRED, LoginDTO ); } return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( "No Records Updated", CacheKeyLevel.NOT_REQUIRED, LoginDTO ); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, ex.Message, 500); } } } }