diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index 066c6c9..5974d02 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -95,6 +95,7 @@ namespace SushiBar services.AddTransient(); services.AddTransient(); } + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } } \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index ed734a7..24a5720 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -106,8 +106,7 @@ namespace SushiBarBusinessLogic.BusinessLogics } model.Status = status; model.DateCreate = order.DateCreate; - if (model.DateImplement == null) - model.DateImplement = order.DateImplement; + model.DateImplement ??= order.DateImplement; if (order.ImplementerId.HasValue) model.ImplementerId = order.ImplementerId; if (model.Status == OrderStatus.Issued) @@ -118,11 +117,16 @@ namespace SushiBarBusinessLogic.BusinessLogics model.SushiId = order.SushiId; model.Sum = order.Sum; model.Count = order.Count; - if (_orderStorage.Update(model) == null) + + var result = _orderStorage.Update(model); + if (result == null) { _logger.LogWarning("Update operation failed"); return false; } + SendOrderMessage(result.ClientId, + $"Sushi Bar, Order №{result.Id}", + $"Order №{model.Id} changed status on {result.Status}"); return true; } diff --git a/SushiBar/SushiBarClientApi/Controllers/HomeController.cs b/SushiBar/SushiBarClientApi/Controllers/HomeController.cs index 6cbfef3..6063620 100644 --- a/SushiBar/SushiBarClientApi/Controllers/HomeController.cs +++ b/SushiBar/SushiBarClientApi/Controllers/HomeController.cs @@ -149,5 +149,15 @@ namespace SushiBarClientApi.Controllers var prod = APIClient.GetRequest($"api/Main/GetProduct?sushiId={sushi}"); 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/SushiBar/SushiBarClientApi/Views/Home/Mails.cshtml b/SushiBar/SushiBarClientApi/Views/Home/Mails.cshtml new file mode 100644 index 0000000..a84f13a --- /dev/null +++ b/SushiBar/SushiBarClientApi/Views/Home/Mails.cshtml @@ -0,0 +1,50 @@ +@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/SushiBar/SushiBarClientApi/Views/Home/_Layout.cshtml b/SushiBar/SushiBarClientApi/Views/Home/_Layout.cshtml index b419923..2ef3156 100644 --- a/SushiBar/SushiBarClientApi/Views/Home/_Layout.cshtml +++ b/SushiBar/SushiBarClientApi/Views/Home/_Layout.cshtml @@ -23,13 +23,16 @@ Orders + diff --git a/SushiBar/SushiBarRestApi/Controllers/ClientController.cs b/SushiBar/SushiBarRestApi/Controllers/ClientController.cs index 2925099..41dba3f 100644 --- a/SushiBar/SushiBarRestApi/Controllers/ClientController.cs +++ b/SushiBar/SushiBarRestApi/Controllers/ClientController.cs @@ -12,9 +12,14 @@ public class ClientController : Controller { private readonly ILogger _logger; private readonly IClientLogic _logic; - public ClientController(IClientLogic logic, ILogger logger) + private readonly IMessageInfoLogic _mailLogic; + + public ClientController(IClientLogic logic, + ILogger logger, + IMessageInfoLogic mailLogic) { _logger = logger; + _mailLogic = mailLogic; _logic = logic; } @@ -63,4 +68,20 @@ public class ClientController : Controller } } + [HttpGet] + public List? GetMessages(int clientId) + { + try + { + return _mailLogic.ReadList(new MessageInfoSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error"); + throw; + } + } } \ No newline at end of file diff --git a/SushiBar/SushiBarRestApi/Program.cs b/SushiBar/SushiBarRestApi/Program.cs index 362984c..fcef3aa 100644 --- a/SushiBar/SushiBarRestApi/Program.cs +++ b/SushiBar/SushiBarRestApi/Program.cs @@ -3,6 +3,8 @@ using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.StoragesContracts; using SushiBarDatabaseImplement.Implements; using Microsoft.OpenApi.Models; +using SushiBarBusinessLogic.MailWorker; +using SushiBarContracts.BindingModels; var builder = WebApplication.CreateBuilder(args); @@ -14,10 +16,14 @@ builder.Logging.AddLog4Net("log4net.config"); 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(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle @@ -26,6 +32,21 @@ builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title var app = builder.Build(); +var mailSender = app.Services.GetService(); +mailSender?.MailConfig(new MailConfigBindingModel +{ + MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value + ?? string.Empty, + MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value ?? + string.Empty, + SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value ?? + string.Empty, + SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value), + PopHost = builder.Configuration?.GetSection("PopHost")?.Value ?? + string.Empty, + PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value) +}); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment())