отправление на почту нужно доделать

This commit is contained in:
dasha 2023-05-18 19:24:35 +04:00
parent 610c76a402
commit 2b92074b02
6 changed files with 29 additions and 40 deletions

View File

@ -117,15 +117,17 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
return file; return file;
} }
public bool SendReportOnMail(int userId, string subject, string text) public bool SendReportOnMail(ReportBindingModel model)
{ {
var user = _userStorage.GetElement(new() { Id = userId }); var user = _userStorage.GetElement(new() { Id = model.UserId });
if (user == null) return false; if (user == null) return false;
_mailWorker.MailSendAsync(new() _mailWorker.MailSendAsync(new()
{ {
MailAddress = user.Email, MailAddress = user.Email,
Subject = subject, Subject = "Отчет по комплектующим",
Text = text Text = $"Отчет по полученным вами комлектующим за период с {model.DateFrom} по {model.DateTo} в формате Pdf.",
//File = file
}); });
return true; return true;
} }

View File

@ -42,6 +42,8 @@
if (from.value && to.value && from.value !== '' && to.value !== '') { if (from.value && to.value && from.value !== '' && to.value !== '') {
const dateFrom = new Date(from.value); const dateFrom = new Date(from.value);
const dateTo = new Date(to.value); const dateTo = new Date(to.value);
if (dateFrom.getTime() > dateTo.getTime())
alert("Неправильные даты")
const reportModel = { "DateFrom": dateFrom, "DateTo": dateTo } const reportModel = { "DateFrom": dateFrom, "DateTo": dateTo }
$.ajax({ $.ajax({
method: "POST", method: "POST",
@ -56,18 +58,25 @@
}).fail(function(xhr, textStatus, errorThrown) { }).fail(function(xhr, textStatus, errorThrown) {
alert(xhr.responseText); alert(xhr.responseText);
}) })
} else { alert("empty fields") } } else { alert("Пустые поля") }
}) })
onmail.addEventListener("click" () =>{ onmail.addEventListener("click", () => {
console.log('try to send email') console.log('try to send email')
$.ajax({ if (from.value && to.value && from.value !== '' && to.value !== '') {
method: "POST", const dateFrom = new Date(from.value);
contentType: "application/json", const dateTo = new Date(to.value);
url: `/Storekeeper/ReportSendOnMail`, if (dateFrom.getTime() > dateTo.getTime())
data: JSON.stringify(reportModel) alert("Неправильные даты")
}).fail(function(xhr, textStatus, errorThrown) { const reportModel = { "DateFrom": dateFrom, "DateTo": dateTo }
alert(xhr.responseText); $.ajax({
}) method: "POST",
contentType: "application/json",
url: `/Storekeeper/ReportSendOnMail`,
data: JSON.stringify(reportModel)
}).fail(function(xhr, textStatus, errorThrown) {
alert(xhr.responseText);
})
} else { alert("Пустые поля") }
}) })
function reloadTable() { function reloadTable() {

View File

@ -36,6 +36,6 @@ namespace HardwareShopContracts.BusinessLogicsContracts
/// Отправление отчета на почту /// Отправление отчета на почту
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
bool SendReportOnMail(int userId, string subject, string text); bool SendReportOnMail(ReportBindingModel model);
} }
} }

View File

@ -66,7 +66,8 @@ namespace HardwareShopRestApi.Controllers
{ {
try try
{ {
_reportStorekeeperLogic.SendReportOnMail(model.UserId, "заголовок", "текст"); string subject =
_reportStorekeeperLogic.SendReportOnMail(model);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -1,23 +0,0 @@
using HardwareShopContracts.BindingModels;
using HardwareShopContracts.BusinessLogicsContracts;
using HardwareShopContracts.SearchModels;
using HardwareShopContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace HardwareShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class WorkerReport : Controller
{
private readonly ILogger _logger;
private readonly IWorkerReportLogic _workerReportLogic;
public WorkerReport(IWorkerReportLogic workerReportLogic, ILogger<UserController> logger)
{
_logger = logger;
_workerReportLogic = workerReportLogic;
}
}
}

View File

@ -38,7 +38,7 @@ builder.Services.AddTransient<IWorkerReportLogic, WorkerReportLogic>();
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>(); builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
builder.Services.AddTransient<AbstractMailWorker, MailKitWorker>(); builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
builder.Services.AddControllers(); builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle