Jóváhagyás utáni automatikus mail + CheckListHeader ShortName és Description javítása
This commit is contained in:
@@ -114,6 +114,7 @@ namespace WorkFlowCheck.BL.Services
|
||||
{
|
||||
CheckListTemplateHeaderId = checkListHeaderDTO.CheckListTemplateHeaderDTO.Id,
|
||||
Description = checkListHeaderDTO.Description,
|
||||
ShortName = checkListHeaderDTO.ShortName,
|
||||
GuidNumber = Guid.NewGuid(),
|
||||
};
|
||||
_dbContext.CheckListHeaders.Add(checkListHeader);
|
||||
@@ -129,7 +130,7 @@ namespace WorkFlowCheck.BL.Services
|
||||
if (checkListHeader != null)
|
||||
{
|
||||
checkListHeader.Description = checkListHeaderDTO.Description;
|
||||
|
||||
checkListHeader.ShortName= checkListHeaderDTO.ShortName;
|
||||
|
||||
await _dbContext.SaveChangesAsync();
|
||||
retVal = _mapper.Map<CheckListHeaderDTO>(checkListHeader);
|
||||
@@ -239,17 +240,60 @@ namespace WorkFlowCheck.BL.Services
|
||||
var filePath = Path.Combine(pdfDirectory, fileName);
|
||||
await File.WriteAllBytesAsync(filePath, pdf);
|
||||
|
||||
await SendMailToAcceptedUser(filePath, checkListHeader, userid);
|
||||
|
||||
retVal = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
retVal = false;
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private async Task SendMailToAcceptedUser(string filePath, CheckListHeader checkListHeader, int userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = _dbContext.Users.Where(W => W.Id == userId).FirstOrDefault();
|
||||
if (user != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(user.Email))
|
||||
{
|
||||
var recepients = new List<string>()
|
||||
{
|
||||
user.Email,
|
||||
};
|
||||
|
||||
await _messageService.SendMailAsync(recepients,
|
||||
$"Értesítés folyamat jóváhagyásáról {checkListHeader.DocumentNumber}",
|
||||
GetAcceptCheckListHeaderMessageBody(checkListHeader),
|
||||
filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
private string GetAcceptCheckListHeaderMessageBody(CheckListHeader checkListHeader)
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var resourceName = "WorkFlowCheck.BL.HtmlTemplates.AcceptCheckListHeaderBody.html";
|
||||
|
||||
using var stream = assembly.GetManifestResourceStream(resourceName);
|
||||
if (stream == null)
|
||||
throw new FileNotFoundException($"Nem található a beágyazott erőforrás: {resourceName}");
|
||||
|
||||
using var reader = new StreamReader(stream);
|
||||
var html = reader.ReadToEnd();
|
||||
return html.Replace("#DocumentNumber#", checkListHeader.DocumentNumber);
|
||||
}
|
||||
public async Task<byte[]> CreateCheckListHeaderPDFAsync(int checkListHeaderId)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces
|
||||
{
|
||||
public interface IMessageService
|
||||
{
|
||||
Task<bool> SendMailAsync(List<string> recipients, string subject, string htmlBody);
|
||||
Task<bool> SendMailAsync(List<string> recipients, string subject, string htmlBody, string? attachmentFilePath = null);
|
||||
|
||||
Task<bool> SendFCMTokenAsync(string token);
|
||||
Task<string> GetLastFCMTokensAsync();
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace WorkFlowCheck.BL.Services
|
||||
_settings = configuration.GetSection("EmailSettings").Get<EmailSettings>()!;
|
||||
}
|
||||
|
||||
public async Task<bool> SendMailAsync(List<string> recipients, string subject, string htmlBody)
|
||||
public async Task<bool> SendMailAsync(List<string> recipients, string subject, string htmlBody, string? attachmentFilePath = null)
|
||||
{
|
||||
var message = new MimeMessage();
|
||||
message.From.Add(new MailboxAddress(_settings.SenderName, _settings.Username));
|
||||
@@ -40,11 +40,17 @@ namespace WorkFlowCheck.BL.Services
|
||||
|
||||
message.Subject = subject;
|
||||
|
||||
message.Body = new TextPart("html")
|
||||
var builder = new BodyBuilder
|
||||
{
|
||||
Text = htmlBody
|
||||
HtmlBody = htmlBody
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(attachmentFilePath) && File.Exists(attachmentFilePath))
|
||||
{
|
||||
builder.Attachments.Add(attachmentFilePath);
|
||||
}
|
||||
|
||||
message.Body = builder.ToMessageBody();
|
||||
using var smtp = new SmtpClient();
|
||||
await smtp.ConnectAsync(_settings.SmtpServer, _settings.SmtpPort, SecureSocketOptions.StartTls);
|
||||
await smtp.AuthenticateAsync(_settings.Username, _settings.Password);
|
||||
|
||||
Reference in New Issue
Block a user