diff --git a/IRaCIS.Core.Application/Service/Common/EmailLogService.cs b/IRaCIS.Core.Application/Service/Common/EmailLogService.cs index 872f51684..da2efe709 100644 --- a/IRaCIS.Core.Application/Service/Common/EmailLogService.cs +++ b/IRaCIS.Core.Application/Service/Common/EmailLogService.cs @@ -34,6 +34,7 @@ namespace IRaCIS.Core.Application.Service; /// [ApiExplorerSettings(GroupName = "Common")] public class EmailLogService(IRepository _emailLogRepository, + IRepository _trialRepository, IOSSService oSSService, IRepository _emailRecipientLogRepository, IOptionsMonitor systemEmailConfig, @@ -49,8 +50,14 @@ public class EmailLogService(IRepository _emailLogRepository, [HttpPost] public async Task> GetEmailLogList(EmailLogQuery inDto) { + var emailFromEmail = await _trialRepository.Where(x=>x.Id==inDto.TrialId).Select(x=>x.EmailFromEmail).FirstOrDefaultAsync(); + if (emailFromEmail.IsNullOrEmpty()) + { + emailFromEmail = _systemEmailConfig.FromEmail; + } var emailLogQueryable = _emailLogRepository + .Where(x=>x.SenderAddress== emailFromEmail) .WhereIf(inDto.EmailStartDate.HasValue, x => x.EmailDate >= inDto.EmailStartDate.Value) .WhereIf(inDto.EmailEndDate.HasValue, x => x.EmailDate <= inDto.EmailEndDate.Value) .WhereIf(inDto.EmailStateEnum.HasValue, x => x.EmailStateEnum == inDto.EmailStateEnum.Value) @@ -77,7 +84,7 @@ public class EmailLogService(IRepository _emailLogRepository, var emailInfo=await _emailLogRepository .Where(x => x.Id == inDto.Id).Include(x=>x.EmailRecipientLogList) - .ProjectTo(_mapper.ConfigurationProvider) + .ProjectTo(_mapper.ConfigurationProvider).AsNoTracking() .FirstNotNullAsync(); if (emailInfo.UniqueId.IsNotNullOrEmpty()) @@ -123,10 +130,13 @@ public class EmailLogService(IRepository _emailLogRepository, } - await _emailLogRepository.UpdatePartialFromQueryAsync(emailInfo.Id.Value, x => new EmailLog() + var emailLog = await _emailLogRepository.FirstOrDefaultAsync(x => x.Id == emailInfo.Id.Value); + if (emailLog != null) { - Attachments = attachmentInfos - }); + emailLog.Attachments = attachmentInfos; + await _emailLogRepository.SaveChangesAsync() ; + } + emailInfo.Attachments = attachmentInfos; }