From 032824dd74e28bf0cfbb554c4bf0ca3bdff22066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=9C=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=D1=84=D0=B5=D0=B5=D0=B2?= Date: Sun, 5 May 2024 18:10:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B3=D1=80=D1=83=D1=81=D1=82=D0=BD=D1=8B?= =?UTF-8?q?=D0=B5=20=D0=B1=D0=BE=D0=B1=D1=80=D1=8B=20=D1=81=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D1=82=D1=8C=20=D0=BB=D0=B0=D0=B1=D1=83(?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 11 ++++ .../Views/Home/Mails.cshtml | 54 +++++++++++++++++++ .../Views/Shared/_Layout.cshtml | 3 ++ .../Controllers/ClientController.cs | 25 +++++++-- JewelryStore/JewelryStoreRestApi/Program.cs | 19 +++++++ .../JewelryStoreRestApi/appsettings.json | 9 +++- 6 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 JewelryStore/JewelryStoreClientApp/Views/Home/Mails.cshtml diff --git a/JewelryStore/JewelryStoreClientApp/Controllers/HomeController.cs b/JewelryStore/JewelryStoreClientApp/Controllers/HomeController.cs index 98e358b..010ccbe 100644 --- a/JewelryStore/JewelryStoreClientApp/Controllers/HomeController.cs +++ b/JewelryStore/JewelryStoreClientApp/Controllers/HomeController.cs @@ -146,5 +146,16 @@ namespace JewelryStoreClientApp.Controllers ); return count * (jew?.Price ?? 1); } + + [HttpGet] + public IActionResult Mails() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return + View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}")); + } } } \ No newline at end of file diff --git a/JewelryStore/JewelryStoreClientApp/Views/Home/Mails.cshtml b/JewelryStore/JewelryStoreClientApp/Views/Home/Mails.cshtml new file mode 100644 index 0000000..31b2dd5 --- /dev/null +++ b/JewelryStore/JewelryStoreClientApp/Views/Home/Mails.cshtml @@ -0,0 +1,54 @@ +@using JewelryStoreContracts.ViewModels +@model List + +@{ + ViewData["Title"] = "Mails"; +} + +
+

Заказы

+
+ +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Дата письма + + Заголовок + + Текст +
+ @Html.DisplayFor(modelItem => + item.DateDelivery) + + @Html.DisplayFor(modelItem => + item.Subject) + + @Html.DisplayFor(modelItem => + item.Body) +
+ } +
\ No newline at end of file diff --git a/JewelryStore/JewelryStoreClientApp/Views/Shared/_Layout.cshtml b/JewelryStore/JewelryStoreClientApp/Views/Shared/_Layout.cshtml index a675fee..080d810 100644 --- a/JewelryStore/JewelryStoreClientApp/Views/Shared/_Layout.cshtml +++ b/JewelryStore/JewelryStoreClientApp/Views/Shared/_Layout.cshtml @@ -24,6 +24,9 @@ + diff --git a/JewelryStore/JewelryStoreRestApi/Controllers/ClientController.cs b/JewelryStore/JewelryStoreRestApi/Controllers/ClientController.cs index 5aad241..a4c3e4c 100644 --- a/JewelryStore/JewelryStoreRestApi/Controllers/ClientController.cs +++ b/JewelryStore/JewelryStoreRestApi/Controllers/ClientController.cs @@ -12,12 +12,14 @@ namespace JewelryStoreRestApi.Controllers { private readonly ILogger _logger; private readonly IClientLogic _logic; + private readonly IMessageInfoLogic _mailLogic; - public ClientController(IClientLogic logic, ILogger logger) + public ClientController(IClientLogic logic, ILogger logger, IMessageInfoLogic mailLogic) { _logger = logger; _logic = logic; - } + _mailLogic = mailLogic; + } [HttpGet] public ClientViewModel? Login(string login, string password) @@ -64,5 +66,22 @@ namespace JewelryStoreRestApi.Controllers throw; } } - } + + [HttpGet] + public List? GetMessages(int clientId) + { + try + { + return _mailLogic.ReadList(new MessageInfoSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка в поличении писем клиента"); + throw; + } + } + } } diff --git a/JewelryStore/JewelryStoreRestApi/Program.cs b/JewelryStore/JewelryStoreRestApi/Program.cs index 058b8ee..44ffb80 100644 --- a/JewelryStore/JewelryStoreRestApi/Program.cs +++ b/JewelryStore/JewelryStoreRestApi/Program.cs @@ -1,4 +1,6 @@ using JewelryStoreBusinessLogic.BusinessLogics; +using JewelryStoreBusinessLogic.MailWorker; +using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.StoragesContracts; using JewelryStoreDatabaseImplement.Implements; @@ -15,12 +17,18 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); builder.Services.AddControllers(); @@ -33,6 +41,17 @@ builder.Services.AddSwaggerGen(c => var app = builder.Build(); +var mailSender = app.Services.GetService(); +mailSender?.MailConfig(new MailConfigBindingModel +{ + MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty, + MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty, + SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty, + SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()), + PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty, + PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString()) +}); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/JewelryStore/JewelryStoreRestApi/appsettings.json b/JewelryStore/JewelryStoreRestApi/appsettings.json index 10f68b8..080e3ef 100644 --- a/JewelryStore/JewelryStoreRestApi/appsettings.json +++ b/JewelryStore/JewelryStoreRestApi/appsettings.json @@ -5,5 +5,12 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "SmtpClientHost": "smtp.mail.ru", + "SmtpClientPort": "587", + "PopHost": "pop.mail.ru", + "PopPort": "995", + "MailLogin": "aboba.russian@mail.ru", + "MailPassword": "generatorPAROLYA" + }