отправление на почту нужно доделать
This commit is contained in:
parent
610c76a402
commit
2b92074b02
@ -117,15 +117,17 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
|
||||
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;
|
||||
|
||||
_mailWorker.MailSendAsync(new()
|
||||
{
|
||||
MailAddress = user.Email,
|
||||
Subject = subject,
|
||||
Text = text
|
||||
Subject = "Отчет по комплектующим",
|
||||
Text = $"Отчет по полученным вами комлектующим за период с {model.DateFrom} по {model.DateTo} в формате Pdf.",
|
||||
//File = file
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
@ -42,6 +42,8 @@
|
||||
if (from.value && to.value && from.value !== '' && to.value !== '') {
|
||||
const dateFrom = new Date(from.value);
|
||||
const dateTo = new Date(to.value);
|
||||
if (dateFrom.getTime() > dateTo.getTime())
|
||||
alert("Неправильные даты")
|
||||
const reportModel = { "DateFrom": dateFrom, "DateTo": dateTo }
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
@ -56,18 +58,25 @@
|
||||
}).fail(function(xhr, textStatus, errorThrown) {
|
||||
alert(xhr.responseText);
|
||||
})
|
||||
} else { alert("empty fields") }
|
||||
} else { alert("Пустые поля") }
|
||||
})
|
||||
onmail.addEventListener("click" () =>{
|
||||
onmail.addEventListener("click", () => {
|
||||
console.log('try to send email')
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
contentType: "application/json",
|
||||
url: `/Storekeeper/ReportSendOnMail`,
|
||||
data: JSON.stringify(reportModel)
|
||||
}).fail(function(xhr, textStatus, errorThrown) {
|
||||
alert(xhr.responseText);
|
||||
})
|
||||
if (from.value && to.value && from.value !== '' && to.value !== '') {
|
||||
const dateFrom = new Date(from.value);
|
||||
const dateTo = new Date(to.value);
|
||||
if (dateFrom.getTime() > dateTo.getTime())
|
||||
alert("Неправильные даты")
|
||||
const reportModel = { "DateFrom": dateFrom, "DateTo": dateTo }
|
||||
$.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() {
|
||||
|
@ -36,6 +36,6 @@ namespace HardwareShopContracts.BusinessLogicsContracts
|
||||
/// Отправление отчета на почту
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
bool SendReportOnMail(int userId, string subject, string text);
|
||||
bool SendReportOnMail(ReportBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,8 @@ namespace HardwareShopRestApi.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
_reportStorekeeperLogic.SendReportOnMail(model.UserId, "заголовок", "текст");
|
||||
string subject =
|
||||
_reportStorekeeperLogic.SendReportOnMail(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -38,7 +38,7 @@ builder.Services.AddTransient<IWorkerReportLogic, WorkerReportLogic>();
|
||||
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
|
||||
builder.Services.AddTransient<AbstractMailWorker, MailKitWorker>();
|
||||
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
|
Loading…
Reference in New Issue
Block a user