using FastEndpoints; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.Item; using MMBLL.MMHead; using MMDAL.DTO.MMHead; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.MMHead { public class SaveMMHead : BaseEndpoint { private readonly IMMHeadBLL _IMMHeadBLL; public SaveMMHead(IMMHeadBLL IMMHeadBLL) { _IMMHeadBLL = IMMHeadBLL; } public override void Configure() { Post("/MMHead/SaveMMHead"); AllowAnonymous(); } public record SaveMMHeadParameters( [property: FromBody] MMHeadDTO MMHeadDTO, [property: FromHeader] string Login ); protected override async Task> ExecuteAsync(SaveMMHeadParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { bool isNewDocument = parameters.MMHeadDTO.MMHeadId == 0; var result = await _IMMHeadBLL.SaveMMHead(parameters.MMHeadDTO, loginDTO!, ct); var message = isNewDocument ? $"Detail Saved Successfully With DocumentNumber : {result}" : $"Detail Updated Successfully With DocumentNumber : {result}"; return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(message, CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }