using AmpDAL.CustomCode.ApiRequestTimeline; using AmpDAL.DTO.ApiRequestTimeline; using GB5Shared.DTO.Framework.Login; using GB5Shared.GenerateAutoNumber; using Microsoft.Extensions.Logging; namespace AMPBLL.ApiRequestTimeline; public class ApiRequestTimelineBLL( IApiRequestTimelineDAL _dal, AutoNumber _autoNumber, ILogger _logger ) : IApiRequestTimelineBLL { public async Task> GetTimelineAsync(int apiRequestId, LoginDTO login, CancellationToken ct) { try { return await _dal.GetTimelineAsync(apiRequestId, login.ClientId, login, ct).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "GetTimeline failed for ApiRequestId {ApiRequestId}", apiRequestId); throw; } } public async Task AddTimelineEntryAsync(int apiRequestId, byte? fromStatus, byte toStatus, string? comments, LoginDTO login, CancellationToken ct) { try { var autoNumberDto = await _autoNumber.GetAutoNumber(1, "MAPIREQUESTTIMELINE", login).ConfigureAwait(false); var dto = new ApiRequestTimelineSaveDTO { TimelineId = autoNumberDto.StartNumber, TenantId = login.ClientId, ApiRequestId = apiRequestId, FromStatus = fromStatus, ToStatus = toStatus, ActionTakenById = login.UserId, Comments = comments, AttachmentUrl = null }; await _dal.InsertTimelineEntryAsync(dto, login, ct).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "AddTimelineEntry failed for ApiRequestId {ApiRequestId}", apiRequestId); throw; } } }