From 545e17a2b36e7f9694e0f93e461b8d69324b21b4 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Wed, 19 Apr 2023 15:42:56 +0400 Subject: [PATCH] =?UTF-8?q?Rest,=20=D0=9A=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=20?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FurnitureAssembly/App.config | 11 +++++ .../Controllers/HomeController.cs | 12 ++++++ .../Views/Home/Mails.cshtml | 43 +++++++++++++++++++ .../Views/Shared/_Layout.cshtml | 3 ++ .../Controllers/ClientController.cs | 20 ++++++++- .../FurnitureAssemblyRestApi/Program.cs | 20 +++++++++ .../FurnitureAssemblyRestApi/appsettings.json | 9 +++- 7 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 FurnitureAssembly/FurnitureAssembly/App.config create mode 100644 FurnitureAssembly/FurnitureAssemblyClientApp/Views/Home/Mails.cshtml diff --git a/FurnitureAssembly/FurnitureAssembly/App.config b/FurnitureAssembly/FurnitureAssembly/App.config new file mode 100644 index 0000000..d46345f --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyClientApp/Controllers/HomeController.cs b/FurnitureAssembly/FurnitureAssemblyClientApp/Controllers/HomeController.cs index 0e2c37e..006e742 100644 --- a/FurnitureAssembly/FurnitureAssemblyClientApp/Controllers/HomeController.cs +++ b/FurnitureAssembly/FurnitureAssemblyClientApp/Controllers/HomeController.cs @@ -2,6 +2,7 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.ViewModels; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using System.Diagnostics; namespace FurnitureAssemblyClientApp.Controllers @@ -145,5 +146,16 @@ namespace FurnitureAssemblyClientApp.Controllers ); return count * (prod?.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/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Home/Mails.cshtml b/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Home/Mails.cshtml new file mode 100644 index 0000000..413db5e --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Home/Mails.cshtml @@ -0,0 +1,43 @@ +@using FurnitureAssemblyContracts.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/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Shared/_Layout.cshtml b/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Shared/_Layout.cshtml index 5b9b3a1..7d6fcc4 100644 --- a/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Shared/_Layout.cshtml +++ b/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Shared/_Layout.cshtml @@ -27,6 +27,9 @@ + diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ClientController.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ClientController.cs index acf7af8..c7448ef 100644 --- a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ClientController.cs +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ClientController.cs @@ -12,11 +12,13 @@ namespace FurnitureAssemblyRestApi.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] @@ -62,5 +64,21 @@ namespace FurnitureAssemblyRestApi.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/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs index 1c84a1c..09bc8c5 100644 --- a/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs @@ -1,4 +1,6 @@ using FurnitureAssemblyBusinessLogic; +using FurnitureAssemblyBusinessLogic.MailWorker; +using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContarcts; using FurnitureAssemblyContracts.StoragesContracts; using FurnitureAssemblyDatabaseImplement.Implements; @@ -17,6 +19,12 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); 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 @@ -32,6 +40,18 @@ 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/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json b/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json index 10f68b8..92f8193 100644 --- a/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json @@ -5,5 +5,12 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + + "SmtpClientHost": "smtp.gmail.com", + "SmtpClientPort": "587", + "PopHost": "pop.gmail.com", + "PopPort": "995", + "MailLogin": "MailNoNameLab@gmail.com", + "MailPassword": "cpdj ykey loip jxwj" }