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" + }