send message
This commit is contained in:
parent
67257c30ca
commit
d43bff822f
@ -18,19 +18,17 @@ namespace HardwareShopContracts.BusinessLogicsContracts
|
||||
|
||||
private readonly IPurchaseStorage _purchaseStorage;
|
||||
|
||||
private readonly IBuildStorage _buildStorage;
|
||||
|
||||
private readonly AbstractSaveToExcel _saveToExcel;
|
||||
|
||||
private readonly AbstractSaveToWord _saveToWord;
|
||||
|
||||
private readonly AbstractSaveToPdf _saveToPdf;
|
||||
private readonly MailKitWorker _mailKitWorker;
|
||||
|
||||
public WorkerReportLogic(IPurchaseStorage purchaseStorage, MailKitWorker mailKitWorker, IBuildStorage buildStorage, AbstractSaveToPdf saveToPdf, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord)
|
||||
private readonly AbstractMailWorker _mailKitWorker;
|
||||
|
||||
public WorkerReportLogic(IPurchaseStorage purchaseStorage, AbstractMailWorker mailKitWorker, AbstractSaveToPdf saveToPdf, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord)
|
||||
{
|
||||
_purchaseStorage = purchaseStorage;
|
||||
_buildStorage = buildStorage;
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
_saveToPdf = saveToPdf;
|
||||
@ -162,14 +160,14 @@ namespace HardwareShopContracts.BusinessLogicsContracts
|
||||
DateTo = model.DateTo,
|
||||
ReportPurchases = GetPurchase(model)
|
||||
});
|
||||
// _mailKitWorker.SendMailAsync(new()
|
||||
// {
|
||||
// MailAddress = reportModel.UserEmail,
|
||||
// Subject = "Отчет по покупкам",
|
||||
// Text = $"За период с {reportModel.DateFrom.ToShortDateString()} " +
|
||||
//$"по {reportModel.DateTo.ToShortDateString()}.",
|
||||
// File = file
|
||||
// });
|
||||
_mailKitWorker.MailSendAsync(new()
|
||||
{
|
||||
MailAddress = model.UserEmail,
|
||||
Subject = "Отчет по покупкам",
|
||||
Text = $"За период с {model.DateFrom.ToShortDateString()} " +
|
||||
$"по {model.DateTo.ToShortDateString()}.",
|
||||
File = file
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -25,6 +25,8 @@ namespace HardwareShopBusinessLogic.MailWorker
|
||||
objMailMessage.Body = info.Text;
|
||||
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
||||
objMailMessage.BodyEncoding = Encoding.UTF8;
|
||||
MemoryStream ms = new(info.File);
|
||||
objMailMessage.Attachments.Add(new Attachment(ms, "report.pdf", "application/pdf"));
|
||||
|
||||
objSmtpClient.UseDefaultCredentials = false;
|
||||
objSmtpClient.EnableSsl = true;
|
||||
|
@ -7,5 +7,7 @@
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
public byte[] File { get; set; } = Array.Empty<byte>();
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@
|
||||
{
|
||||
public class ReportBindingModel
|
||||
{
|
||||
public string UserEmail { get; set; } = string.Empty;
|
||||
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateFrom { get; set; }
|
||||
|
@ -37,8 +37,8 @@ builder.Services.AddTransient<IReportStorekeeperLogic, ReportStorekeeperLogic>()
|
||||
builder.Services.AddTransient<IWorkerReportLogic, WorkerReportLogic>();
|
||||
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
|
||||
builder.Services.AddTransient<AbstractMailWorker, MailKitWorker>();
|
||||
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
|
@ -98,7 +98,7 @@
|
||||
return;
|
||||
}
|
||||
$.ajax({
|
||||
url: "/home/sendbymailepurchasereport",
|
||||
url: "/home/SendByMailPurchaseReport",
|
||||
type: "POST",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(reportModel)
|
||||
@ -129,7 +129,7 @@
|
||||
let cellsData = ["", "", "", "", ""];
|
||||
if (i === 0) {
|
||||
cellsData[0] = record.id;
|
||||
cellsData[1] = record.purchaseDate;
|
||||
cellsData[1] = getDate(record.purchaseDate);
|
||||
cellsData[2] = record.purchaseSum;
|
||||
createTableRow(cellsData);
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user