From bb87bb3fb8fff5bfdeb8706e404cab331ed032fd Mon Sep 17 00:00:00 2001 From: malimova Date: Sat, 1 Jun 2024 22:55:07 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=20=D0=BF=D1=80=D0=BE=D1=86=D0=B5=D1=81?= =?UTF-8?q?=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 12 ++ .../Views/Home/Mails.cshtml | 51 ++++++++ .../Views/Shared/_Layout.cshtml | 3 + .../Controllers/ClientController.cs | 118 ++++++++++-------- Confectionery/ConfectioneryRestApi/Program.cs | 16 +++ 5 files changed, 149 insertions(+), 51 deletions(-) create mode 100644 Confectionery/ConfectioneryClientApp/Views/Home/Mails.cshtml diff --git a/Confectionery/ConfectioneryClientApp/Controllers/HomeController.cs b/Confectionery/ConfectioneryClientApp/Controllers/HomeController.cs index e40a17a..6dbba79 100644 --- a/Confectionery/ConfectioneryClientApp/Controllers/HomeController.cs +++ b/Confectionery/ConfectioneryClientApp/Controllers/HomeController.cs @@ -4,6 +4,7 @@ using ConfectioneryClientApp.Models; using ConfectioneryClientApp; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; +using Microsoft.Extensions.Logging; namespace ConfectioneryClientApp.Controllers { @@ -140,5 +141,16 @@ namespace ConfectioneryClientApp.Controllers var prod = APIClient.GetRequest($"api/main/getpastry?pastryId={pastry}"); 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}")); + } } } diff --git a/Confectionery/ConfectioneryClientApp/Views/Home/Mails.cshtml b/Confectionery/ConfectioneryClientApp/Views/Home/Mails.cshtml new file mode 100644 index 0000000..cfc5f7c --- /dev/null +++ b/Confectionery/ConfectioneryClientApp/Views/Home/Mails.cshtml @@ -0,0 +1,51 @@ +@using ConfectioneryContracts.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/Confectionery/ConfectioneryClientApp/Views/Shared/_Layout.cshtml b/Confectionery/ConfectioneryClientApp/Views/Shared/_Layout.cshtml index fc0c10f..c65aa11 100644 --- a/Confectionery/ConfectioneryClientApp/Views/Shared/_Layout.cshtml +++ b/Confectionery/ConfectioneryClientApp/Views/Shared/_Layout.cshtml @@ -26,6 +26,9 @@ + diff --git a/Confectionery/ConfectioneryRestApi/Controllers/ClientController.cs b/Confectionery/ConfectioneryRestApi/Controllers/ClientController.cs index ca55286..a94869b 100644 --- a/Confectionery/ConfectioneryRestApi/Controllers/ClientController.cs +++ b/Confectionery/ConfectioneryRestApi/Controllers/ClientController.cs @@ -11,59 +11,75 @@ namespace ConfectioneryRestApi.Controllers public class ClientController : Controller { private readonly ILogger _logger; - private readonly IClientLogic _logic; + private readonly IMessageInfoLogic _mailLogic; - public ClientController(IClientLogic logic, ILogger logger) - { - _logger = logger; - _logic = logic; - } + public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger logger) + { + _logger = logger; + _logic = logic; + _mailLogic = mailLogic; + } + [HttpGet] + public ClientViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ClientSearchModel + { + Email = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + [HttpPost] + public void Register(ClientBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } + [HttpPost] + public void UpdateData(ClientBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } - [HttpGet] - public ClientViewModel? Login(string login, string password) - { - try - { - return _logic.ReadElement(new ClientSearchModel - { - Email = login, - Password = password - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка входа в систему"); - throw; - } - } + [HttpGet] + public List? GetMessages(int clientId) + { + try + { + return _mailLogic.ReadList(new MessageInfoSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения писем клиента"); + throw; + } + } - [HttpPost] - public void Register(ClientBindingModel model) - { - try - { - _logic.Create(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка регистрации"); - throw; - } - } - - [HttpPost] - public void UpdateData(ClientBindingModel model) - { - try - { - _logic.Update(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка обновления данных"); - throw; - } - } - } + } } diff --git a/Confectionery/ConfectioneryRestApi/Program.cs b/Confectionery/ConfectioneryRestApi/Program.cs index d785dee..6c027dc 100644 --- a/Confectionery/ConfectioneryRestApi/Program.cs +++ b/Confectionery/ConfectioneryRestApi/Program.cs @@ -1,4 +1,5 @@ using ConfectioneryBusinessLogic; +using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.BusinessLogicsContracts; using ConfectioneryContracts.StoragesContracts; using ConfectioneryDatabaseImplement.Implements; @@ -17,6 +18,10 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at @@ -31,6 +36,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()) {