diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs
index 495d709..1281df7 100644
--- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs
+++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs
@@ -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;
}
diff --git a/HardwareShop/HardwareShopClientApp/Views/Storekeeper/Report.cshtml b/HardwareShop/HardwareShopClientApp/Views/Storekeeper/Report.cshtml
index 88b75db..c59832e 100644
--- a/HardwareShop/HardwareShopClientApp/Views/Storekeeper/Report.cshtml
+++ b/HardwareShop/HardwareShopClientApp/Views/Storekeeper/Report.cshtml
@@ -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() {
diff --git a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IReportStorekeeperLogic.cs b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IReportStorekeeperLogic.cs
index bfdcec1..277b128 100644
--- a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IReportStorekeeperLogic.cs
+++ b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IReportStorekeeperLogic.cs
@@ -36,6 +36,6 @@ namespace HardwareShopContracts.BusinessLogicsContracts
/// Отправление отчета на почту
///
///
- bool SendReportOnMail(int userId, string subject, string text);
+ bool SendReportOnMail(ReportBindingModel model);
}
}
diff --git a/HardwareShop/HardwareShopRestApi/Controllers/ReportController.cs b/HardwareShop/HardwareShopRestApi/Controllers/ReportController.cs
index 01a7051..e0f97a4 100644
--- a/HardwareShop/HardwareShopRestApi/Controllers/ReportController.cs
+++ b/HardwareShop/HardwareShopRestApi/Controllers/ReportController.cs
@@ -66,7 +66,8 @@ namespace HardwareShopRestApi.Controllers
{
try
{
- _reportStorekeeperLogic.SendReportOnMail(model.UserId, "заголовок", "текст");
+ string subject =
+ _reportStorekeeperLogic.SendReportOnMail(model);
}
catch (Exception ex)
{
diff --git a/HardwareShop/HardwareShopRestApi/Controllers/WorkerReport.cs b/HardwareShop/HardwareShopRestApi/Controllers/WorkerReport.cs
deleted file mode 100644
index dbbf344..0000000
--- a/HardwareShop/HardwareShopRestApi/Controllers/WorkerReport.cs
+++ /dev/null
@@ -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 logger)
- {
- _logger = logger;
- _workerReportLogic = workerReportLogic;
- }
- }
-}
\ No newline at end of file
diff --git a/HardwareShop/HardwareShopRestApi/Program.cs b/HardwareShop/HardwareShopRestApi/Program.cs
index 181d0ca..6a1f113 100644
--- a/HardwareShop/HardwareShopRestApi/Program.cs
+++ b/HardwareShop/HardwareShopRestApi/Program.cs
@@ -38,7 +38,7 @@ builder.Services.AddTransient();
builder.Services.AddTransient();
builder.Services.AddTransient();
-builder.Services.AddTransient();
+builder.Services.AddSingleton();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle