Седьмая лабораторная работа.
This commit is contained in:
parent
06308bd384
commit
c2ea9ed140
@ -6,6 +6,6 @@
|
|||||||
<add key="PopHost" value="pop.gmail.com" />
|
<add key="PopHost" value="pop.gmail.com" />
|
||||||
<add key="PopPort" value="995" />
|
<add key="PopPort" value="995" />
|
||||||
<add key="MailLogin" value="rpplab7@gmail.com" />
|
<add key="MailLogin" value="rpplab7@gmail.com" />
|
||||||
<add key="MailPassword" value="rpplab7password" />
|
<add key="MailPassword" value="edjc dmsf pqne gxwy" />
|
||||||
</appSettings>
|
</appSettings>
|
||||||
</configuration>
|
</configuration>
|
@ -57,6 +57,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Update="App.config">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<None Update="ReportOrders.rdlc">
|
<None Update="ReportOrders.rdlc">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
12
Confectionery/Confectionery/FormMain.Designer.cs
generated
12
Confectionery/Confectionery/FormMain.Designer.cs
generated
@ -43,6 +43,7 @@
|
|||||||
this.buttonCreateOrder = new System.Windows.Forms.Button();
|
this.buttonCreateOrder = new System.Windows.Forms.Button();
|
||||||
this.buttonIssuedOrder = new System.Windows.Forms.Button();
|
this.buttonIssuedOrder = new System.Windows.Forms.Button();
|
||||||
this.buttonRef = new System.Windows.Forms.Button();
|
this.buttonRef = new System.Windows.Forms.Button();
|
||||||
|
this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.menuStrip1.SuspendLayout();
|
this.menuStrip1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -53,7 +54,8 @@
|
|||||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
this.справочникиToolStripMenuItem,
|
this.справочникиToolStripMenuItem,
|
||||||
this.отчётыToolStripMenuItem,
|
this.отчётыToolStripMenuItem,
|
||||||
this.запускРаботToolStripMenuItem});
|
this.запускРаботToolStripMenuItem,
|
||||||
|
this.письмаToolStripMenuItem});
|
||||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||||
this.menuStrip1.Name = "menuStrip1";
|
this.menuStrip1.Name = "menuStrip1";
|
||||||
this.menuStrip1.Size = new System.Drawing.Size(1703, 28);
|
this.menuStrip1.Size = new System.Drawing.Size(1703, 28);
|
||||||
@ -180,6 +182,13 @@
|
|||||||
this.buttonRef.UseVisualStyleBackColor = true;
|
this.buttonRef.UseVisualStyleBackColor = true;
|
||||||
this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click);
|
this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click);
|
||||||
//
|
//
|
||||||
|
// письмаToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem";
|
||||||
|
this.письмаToolStripMenuItem.Size = new System.Drawing.Size(77, 24);
|
||||||
|
this.письмаToolStripMenuItem.Text = "Письма";
|
||||||
|
this.письмаToolStripMenuItem.Click += new System.EventHandler(this.письмаToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
// FormMain
|
// FormMain
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
@ -219,5 +228,6 @@
|
|||||||
private ToolStripMenuItem клиентыToolStripMenuItem;
|
private ToolStripMenuItem клиентыToolStripMenuItem;
|
||||||
private ToolStripMenuItem исполнителиToolStripMenuItem;
|
private ToolStripMenuItem исполнителиToolStripMenuItem;
|
||||||
private ToolStripMenuItem запускРаботToolStripMenuItem;
|
private ToolStripMenuItem запускРаботToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem письмаToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -49,6 +49,7 @@ namespace Confectionery
|
|||||||
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
dataGridView.Columns["ClientId"].Visible = false;
|
dataGridView.Columns["ClientId"].Visible = false;
|
||||||
|
dataGridView.Columns["ClientEmail"].Visible = false;
|
||||||
dataGridView.Columns["ImplementerId"].Visible = false;
|
dataGridView.Columns["ImplementerId"].Visible = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,5 +214,14 @@ namespace Confectionery
|
|||||||
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
|
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
|
||||||
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void письмаToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormMails));
|
||||||
|
if (service is FormMails form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ using ConfectioneryDataBaseImplement.Implements;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NLog.Extensions.Logging;
|
using NLog.Extensions.Logging;
|
||||||
|
using ConfectioneryBusinessLogic.MailWorker;
|
||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
|
|
||||||
namespace Confectionery
|
namespace Confectionery
|
||||||
{
|
{
|
||||||
@ -27,7 +29,30 @@ namespace Confectionery
|
|||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
ConfigureServices(services);
|
ConfigureServices(services);
|
||||||
_serviceProvider = services.BuildServiceProvider();
|
_serviceProvider = services.BuildServiceProvider();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var mailSender = _serviceProvider.GetService<AbstractMailWorker>();
|
||||||
|
mailSender?.MailConfig(new MailConfigBindingModel
|
||||||
|
{
|
||||||
|
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
|
||||||
|
MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty,
|
||||||
|
SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty,
|
||||||
|
SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]),
|
||||||
|
PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty,
|
||||||
|
PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"])
|
||||||
|
});
|
||||||
|
|
||||||
|
// ñîçäàåì òàéìåð
|
||||||
|
var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var logger = _serviceProvider.GetService<ILogger>();
|
||||||
|
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
|
||||||
|
}
|
||||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ConfigureServices(ServiceCollection services)
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
@ -42,16 +67,19 @@ namespace Confectionery
|
|||||||
services.AddTransient<IPastryStorage, PastryStorage>();
|
services.AddTransient<IPastryStorage, PastryStorage>();
|
||||||
services.AddTransient<IClientStorage, ClientStorage>();
|
services.AddTransient<IClientStorage, ClientStorage>();
|
||||||
services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||||
|
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
||||||
services.AddTransient<IIngredientLogic, IngredientLogic>();
|
services.AddTransient<IIngredientLogic, IngredientLogic>();
|
||||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
services.AddTransient<IPastryLogic, PastryLogic>();
|
services.AddTransient<IPastryLogic, PastryLogic>();
|
||||||
services.AddTransient<IReportLogic, ReportLogic>();
|
services.AddTransient<IReportLogic, ReportLogic>();
|
||||||
services.AddTransient<IClientLogic, ClientLogic>();
|
services.AddTransient<IClientLogic, ClientLogic>();
|
||||||
|
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
||||||
services.AddTransient<IWorkProcess, WorkModeling>();
|
services.AddTransient<IWorkProcess, WorkModeling>();
|
||||||
services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||||
|
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||||
services.AddTransient<FormMain>();
|
services.AddTransient<FormMain>();
|
||||||
services.AddTransient<FormIngredient>();
|
services.AddTransient<FormIngredient>();
|
||||||
services.AddTransient<FormIngredients>();
|
services.AddTransient<FormIngredients>();
|
||||||
@ -64,6 +92,9 @@ namespace Confectionery
|
|||||||
services.AddTransient<FormClients>();
|
services.AddTransient<FormClients>();
|
||||||
services.AddTransient<FormImplementers>();
|
services.AddTransient<FormImplementers>();
|
||||||
services.AddTransient<FormImplementer>();
|
services.AddTransient<FormImplementer>();
|
||||||
}
|
services.AddTransient<FormMails>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,6 +8,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ConfectioneryBusinessLogic.BusinessLogics
|
namespace ConfectioneryBusinessLogic.BusinessLogics
|
||||||
@ -16,6 +17,8 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IClientStorage _clientStorage;
|
private readonly IClientStorage _clientStorage;
|
||||||
|
private Regex validateEmailRegex = new Regex("^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$");
|
||||||
|
private Regex validatePasswordRegex = new Regex("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9]).(?=.*?[#?!@$%^&*-]).{10,50}$");
|
||||||
|
|
||||||
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
|
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
|
||||||
{
|
{
|
||||||
@ -108,6 +111,14 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException("Нет электронной почты клиента", nameof(model.Email));
|
throw new ArgumentNullException("Нет электронной почты клиента", nameof(model.Email));
|
||||||
}
|
}
|
||||||
|
if (!validateEmailRegex.IsMatch(model.Email))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Почта введена некорректно!");
|
||||||
|
}
|
||||||
|
if (!validatePasswordRegex.IsMatch(model.Password))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Пароль не удовлетворяет требованиям");
|
||||||
|
}
|
||||||
_logger.LogInformation("Client. ClientFIO:{ClientFIO}. Password:{Password}. Email:{Email}. Id:{Id}", model.ClientFIO, model.Password, model.Email, model.Id);
|
_logger.LogInformation("Client. ClientFIO:{ClientFIO}. Password:{Password}. Email:{Email}. Id:{Id}", model.ClientFIO, model.Password, model.Email, model.Id);
|
||||||
var element = _clientStorage.GetElement(new ClientSearchModel
|
var element = _clientStorage.GetElement(new ClientSearchModel
|
||||||
{
|
{
|
||||||
|
@ -16,11 +16,13 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IMessageInfoStorage _messageStorage;
|
private readonly IMessageInfoStorage _messageStorage;
|
||||||
|
private readonly IClientLogic _clientLogic;
|
||||||
|
|
||||||
public MessageInfoLogic(ILogger logger, IMessageInfoStorage logic)
|
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage logic, IClientLogic clientLogic)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_messageStorage = logic;
|
_messageStorage = logic;
|
||||||
|
_clientLogic = clientLogic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
|
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
|
||||||
@ -39,6 +41,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
|||||||
public bool Create(MessageInfoBindingModel model)
|
public bool Create(MessageInfoBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
|
model.ClientId = _clientLogic.ReadElement(new ClientSearchModel() { Email = model.SenderName })?.Id;
|
||||||
if (_messageStorage.Insert(model) == null)
|
if (_messageStorage.Insert(model) == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using ConfectioneryContracts.BindingModels;
|
using ConfectioneryBusinessLogic.MailWorker;
|
||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||||
using ConfectioneryContracts.SearchModels;
|
using ConfectioneryContracts.SearchModels;
|
||||||
using ConfectioneryContracts.StoragesContracts;
|
using ConfectioneryContracts.StoragesContracts;
|
||||||
@ -17,12 +18,14 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
private readonly AbstractMailWorker _mailWorker;
|
||||||
static readonly object _lock = new object();
|
static readonly object _lock = new object();
|
||||||
|
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
|
_mailWorker = mailWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
@ -30,11 +33,19 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
|||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
if (model.Status != OrderStatus.Неизвестен) return false;
|
if (model.Status != OrderStatus.Неизвестен) return false;
|
||||||
model.Status = OrderStatus.Принят;
|
model.Status = OrderStatus.Принят;
|
||||||
if (_orderStorage.Insert(model) == null)
|
var order = _orderStorage.Insert(model);
|
||||||
|
if (order == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
_mailWorker.MailSendAsync(new MailSendInfoBindingModel()
|
||||||
|
{
|
||||||
|
MailAddress = order.ClientEmail,
|
||||||
|
Subject = "Создан заказ №" + order.Id,
|
||||||
|
Text = $"Создан заказ №{order.Id} от {order.DateCreate} на кондитерское изделие {order.PastryName} в количестве {order.Count} шт. Сумма заказа: {order.Sum}."
|
||||||
|
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +67,14 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
|||||||
throw new InvalidOperationException("Заказ должен быть переведен в статус готовности перед выдачей!");
|
throw new InvalidOperationException("Заказ должен быть переведен в статус готовности перед выдачей!");
|
||||||
}
|
}
|
||||||
model.Status = OrderStatus.Выдан;
|
model.Status = OrderStatus.Выдан;
|
||||||
_orderStorage.Update(model);
|
var order = _orderStorage.Update(model);
|
||||||
|
_mailWorker.MailSendAsync(new MailSendInfoBindingModel()
|
||||||
|
{
|
||||||
|
MailAddress = order.ClientEmail,
|
||||||
|
Subject = $"Заказ №{order.Id}. Статус изменен на Выдан",
|
||||||
|
Text = $"Выдан заказ №{order.Id} от {order.DateCreate} на кондитерское изделие {order.PastryName} в количестве {order.Count} шт. Сумма заказа: {order.Sum}."
|
||||||
|
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +97,14 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
model.Status = OrderStatus.Готов;
|
model.Status = OrderStatus.Готов;
|
||||||
model.DateImplement = DateTime.Now;
|
model.DateImplement = DateTime.Now;
|
||||||
_orderStorage.Update(model);
|
var order = _orderStorage.Update(model);
|
||||||
|
_mailWorker.MailSendAsync(new MailSendInfoBindingModel()
|
||||||
|
{
|
||||||
|
MailAddress = order.ClientEmail,
|
||||||
|
Subject = $"Заказ №{order.Id}. Статус изменен на Готов",
|
||||||
|
Text = $"Готов заказ №{order.Id} от {order.DateCreate} на кондитерское изделие {order.PastryName} в количестве {order.Count} шт. Сумма заказа: {order.Sum}."
|
||||||
|
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +158,14 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
|||||||
throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!");
|
throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!");
|
||||||
}
|
}
|
||||||
model.Status = OrderStatus.Выполняется;
|
model.Status = OrderStatus.Выполняется;
|
||||||
_orderStorage.Update(model);
|
var order = _orderStorage.Update(model);
|
||||||
|
_mailWorker.MailSendAsync(new MailSendInfoBindingModel()
|
||||||
|
{
|
||||||
|
MailAddress = order.ClientEmail,
|
||||||
|
Subject = $"Заказ №{order.Id}. Статус изменен на Выполняется",
|
||||||
|
Text = $"Выполняется заказ №{order.Id} от {order.DateCreate} на кондитерское изделие {order.PastryName} в количестве {order.Count} шт. Сумма заказа: {order.Sum}."
|
||||||
|
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,5 +143,15 @@ namespace ConfectioneryClientApp.Controllers
|
|||||||
var prod = APIClient.GetRequest<PastryViewModel>($"api/main/getpastry?pastryId={product}");
|
var prod = APIClient.GetRequest<PastryViewModel>($"api/main/getpastry?pastryId={product}");
|
||||||
return count * (prod?.Price ?? 1);
|
return count * (prod?.Price ?? 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Mails()
|
||||||
|
{
|
||||||
|
if (APIClient.Client == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
54
Confectionery/ConfectioneryClientApp/Views/Home/Mails.cshtml
Normal file
54
Confectionery/ConfectioneryClientApp/Views/Home/Mails.cshtml
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
@using ConfectioneryContracts.ViewModels
|
||||||
|
|
||||||
|
@model List<MessageInfoViewModel>
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Mails";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<h1 class="display-4">Заказы</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
@{
|
||||||
|
if (Model == null)
|
||||||
|
{
|
||||||
|
<h3 class="display-4">Авторизируйтесь</h3>
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Дата письма
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Заголовок
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Текст
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var item in Model)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.DateDelivery)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Subject)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Body)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
}
|
||||||
|
</div>
|
@ -26,6 +26,9 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Mails">Письма</a>
|
||||||
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -22,6 +22,7 @@ namespace ConfectioneryContracts.ViewModels
|
|||||||
public int ClientId { get; set; }
|
public int ClientId { get; set; }
|
||||||
[DisplayName("ФИО клиента")]
|
[DisplayName("ФИО клиента")]
|
||||||
public string ClientFIO { get; set; } = string.Empty;
|
public string ClientFIO { get; set; } = string.Empty;
|
||||||
|
public string ClientEmail { get; set; } = string.Empty;
|
||||||
[DisplayName("Количество")]
|
[DisplayName("Количество")]
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
[DisplayName("Сумма")]
|
[DisplayName("Сумма")]
|
||||||
|
@ -96,7 +96,7 @@ namespace ConfectioneryDataBaseImplement.Implements
|
|||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new ConfectioneryDatabase();
|
using var context = new ConfectioneryDatabase();
|
||||||
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
var order = context.Orders.Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (order == null)
|
if (order == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -68,6 +68,7 @@ namespace ConfectioneryDataBaseImplement.Models
|
|||||||
PastryId = PastryId,
|
PastryId = PastryId,
|
||||||
ClientId = ClientId,
|
ClientId = ClientId,
|
||||||
ClientFIO = Client.ClientFIO,
|
ClientFIO = Client.ClientFIO,
|
||||||
|
ClientEmail = Client.Email,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
|
@ -16,4 +16,10 @@
|
|||||||
<ProjectReference Include="..\ConfectioneryDataBaseImplement\ConfectioneryDataBaseImplement.csproj" />
|
<ProjectReference Include="..\ConfectioneryDataBaseImplement\ConfectioneryDataBaseImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -13,11 +13,13 @@ namespace ConfectioneryRestApi.Controllers
|
|||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
private readonly IClientLogic _logic;
|
private readonly IClientLogic _logic;
|
||||||
|
private readonly IMessageInfoLogic _mailLogic;
|
||||||
|
|
||||||
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
|
public ClientController(IClientLogic logic, ILogger<ClientController> logger, IMessageInfoLogic mailLogic)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_logic = logic;
|
_logic = logic;
|
||||||
|
_mailLogic = mailLogic;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@ -65,5 +67,21 @@ namespace ConfectioneryRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||||
|
{
|
||||||
|
ClientId = clientId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения писем клиента");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using ConfectioneryBusinessLogic.BusinessLogics;
|
using ConfectioneryBusinessLogic.BusinessLogics;
|
||||||
|
using ConfectioneryBusinessLogic.MailWorker;
|
||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||||
using ConfectioneryContracts.StoragesContracts;
|
using ConfectioneryContracts.StoragesContracts;
|
||||||
using ConfectioneryDataBaseImplement.Implements;
|
using ConfectioneryDataBaseImplement.Implements;
|
||||||
@ -12,11 +14,16 @@ builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
|||||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
builder.Services.AddTransient<IPastryStorage, PastryStorage>();
|
builder.Services.AddTransient<IPastryStorage, PastryStorage>();
|
||||||
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||||
|
builder.Services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
||||||
|
|
||||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||||
builder.Services.AddTransient<IPastryLogic, PastryLogic>();
|
builder.Services.AddTransient<IPastryLogic, PastryLogic>();
|
||||||
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||||
|
builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
@ -26,7 +33,16 @@ builder.Services.AddSwaggerGen(c =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
var mailSender = app.Services.GetService<AbstractMailWorker>();
|
||||||
|
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.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
@ -5,5 +5,11 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"SmtpClientHost": "smtp.gmail.com",
|
||||||
|
"SmtpClientPort": "587",
|
||||||
|
"PopHost": "pop.gmail.com",
|
||||||
|
"PopPort": "995",
|
||||||
|
"MailLogin": "rpplab7@gmail.com",
|
||||||
|
"MailPassword": "edjc dmsf pqne gxwy"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user