diff --git a/Bar/Bar/App.config b/Bar/Bar/App.config new file mode 100644 index 0000000..58cc66c --- /dev/null +++ b/Bar/Bar/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Bar/Bar/FormMain.Designer.cs b/Bar/Bar/FormMain.Designer.cs index c34cc30..5d963a1 100644 --- a/Bar/Bar/FormMain.Designer.cs +++ b/Bar/Bar/FormMain.Designer.cs @@ -45,6 +45,7 @@ this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.MailToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -115,7 +116,8 @@ this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ToolStripMenu, this.отчётыToolStripMenuItem, - this.запускРаботToolStripMenuItem}); + this.запускРаботToolStripMenuItem, + this.MailToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1279, 28); @@ -199,6 +201,13 @@ this.запускРаботToolStripMenuItem.Text = "Запуск работ"; this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click); // + // MailToolStripMenuItem + // + this.MailToolStripMenuItem.Name = "MailToolStripMenuItem"; + this.MailToolStripMenuItem.Size = new System.Drawing.Size(65, 24); + this.MailToolStripMenuItem.Text = "Почта"; + this.MailToolStripMenuItem.Click += new System.EventHandler(this.MailToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -241,5 +250,6 @@ private ToolStripMenuItem ClientsToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem EmployersToolStripMenuItem; + private ToolStripMenuItem MailToolStripMenuItem; } } \ No newline at end of file diff --git a/Bar/Bar/FormMain.cs b/Bar/Bar/FormMain.cs index 9024738..ad33bcd 100644 --- a/Bar/Bar/FormMain.cs +++ b/Bar/Bar/FormMain.cs @@ -39,9 +39,11 @@ namespace BarView { DataGridView.DataSource = List; DataGridView.Columns["CocktailId"].Visible = false; + DataGridView.Columns["ClientEmail"].Visible = false; DataGridView.Columns["ClientId"].Visible = false; + DataGridView.Columns["ClientEmail"].Visible = false; DataGridView.Columns["ImplementerId"].Visible = false; - DataGridView.Columns["CocktailName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["CocktailName"].Visible = false; } _logger.LogInformation("Загрузка заказов"); @@ -229,5 +231,15 @@ namespace BarView Form.ShowDialog(); } } + + private void MailToolStripMenuItem_Click(object sender, EventArgs e) + { + var Service = Program.ServiceProvider?.GetService(typeof(FormMail)); + + if (Service is FormMail Form) + { + Form.ShowDialog(); + } + } } } diff --git a/Bar/Bar/Forms/FormMail.Designer.cs b/Bar/Bar/Forms/FormMail.Designer.cs new file mode 100644 index 0000000..ed725d3 --- /dev/null +++ b/Bar/Bar/Forms/FormMail.Designer.cs @@ -0,0 +1,68 @@ +namespace BarView.Forms +{ + partial class FormMail + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + DataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DataGridView + // + DataGridView.AllowUserToAddRows = false; + DataGridView.AllowUserToDeleteRows = false; + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Dock = DockStyle.Fill; + DataGridView.Location = new Point(0, 0); + DataGridView.Margin = new Padding(3, 2, 3, 2); + DataGridView.Name = "DataGridView"; + DataGridView.ReadOnly = true; + DataGridView.RowHeadersWidth = 51; + DataGridView.RowTemplate.Height = 29; + DataGridView.Size = new Size(1084, 456); + DataGridView.TabIndex = 0; + // + // FormMail + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1084, 456); + Controls.Add(DataGridView); + Margin = new Padding(3, 2, 3, 2); + Name = "FormMail"; + Text = "Письма"; + Load += FormMail_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView DataGridView; + } +} \ No newline at end of file diff --git a/Bar/Bar/Forms/FormMail.cs b/Bar/Bar/Forms/FormMail.cs new file mode 100644 index 0000000..398f046 --- /dev/null +++ b/Bar/Bar/Forms/FormMail.cs @@ -0,0 +1,47 @@ +using BarContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; + +namespace BarView.Forms +{ + public partial class FormMail : Form + { + private readonly ILogger _logger; + private readonly IMessageInfoLogic _messageLogic; + + public FormMail(ILogger Logger, IMessageInfoLogic MessageLogic) + { + InitializeComponent(); + + _logger = Logger; + _messageLogic = MessageLogic; + } + + private void LoadData() + { + try + { + var List = _messageLogic.ReadList(null); + + if (List != null) + { + DataGridView.DataSource = List; + DataGridView.Columns["MessageId"].Visible = false; + DataGridView.Columns["ClientId"].Visible = false; + DataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + _logger.LogInformation("Загрузка почтовых собщений"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки почтовых сообщений"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormMail_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Bar/Bar/Forms/FormMail.resx b/Bar/Bar/Forms/FormMail.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Bar/Bar/Forms/FormMail.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Bar/Bar/Program.cs b/Bar/Bar/Program.cs index 80010d0..594d444 100644 --- a/Bar/Bar/Program.cs +++ b/Bar/Bar/Program.cs @@ -9,8 +9,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using BarContracts.BusinessLogicsContracts; -using BarContracts.BusinessLogicContracts; - +using BarBusinessLogic.MailWorker; +using BarContracts.BindingModels; namespace BarView { @@ -28,9 +28,33 @@ namespace BarView ConfigureServices(Services); _serviceProvider = Services.BuildServiceProvider(); + + try + { + var MailSender = _serviceProvider.GetService(); + 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, 5000); + } + catch (Exception ex) + { + var Logger = _serviceProvider.GetService(); + Logger?.LogError(ex, " "); + } + Application.Run(_serviceProvider.GetRequiredService()); } + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.CheckMailAsync(); + private static void ConfigureServices(ServiceCollection Services) { Services.AddLogging(option => @@ -42,9 +66,9 @@ namespace BarView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); - Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); @@ -53,10 +77,12 @@ namespace BarView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddSingleton(); Services.AddTransient(); Services.AddTransient(); @@ -70,6 +96,7 @@ namespace BarView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); } } -} \ No newline at end of file +} diff --git a/Bar/BarBusinessLogic/BarBusinessLogic/BarBusinessLogic.csproj b/Bar/BarBusinessLogic/BarBusinessLogic/BarBusinessLogic.csproj index fe506d4..95fc1e3 100644 --- a/Bar/BarBusinessLogic/BarBusinessLogic/BarBusinessLogic.csproj +++ b/Bar/BarBusinessLogic/BarBusinessLogic/BarBusinessLogic.csproj @@ -12,6 +12,7 @@ + diff --git a/Bar/BarBusinessLogic/BarBusinessLogic/BusinessLogics/MessageInfoLogic.cs b/Bar/BarBusinessLogic/BarBusinessLogic/BusinessLogics/MessageInfoLogic.cs new file mode 100644 index 0000000..ef3436b --- /dev/null +++ b/Bar/BarBusinessLogic/BarBusinessLogic/BusinessLogics/MessageInfoLogic.cs @@ -0,0 +1,88 @@ +using BarContracts.BindingModels; +using BarContracts.BusinessLogicContracts; +using BarContracts.SearchModels; +using BarContracts.StoragesContracts; +using BarContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace BarBusinessLogic.BusinessLogics +{ + public class MessageInfoLogic : IMessageInfoLogic + { + private readonly ILogger _logger; + + private readonly IMessageInfoStorage _messageInfoStorage; + private readonly IClientStorage _clientStorage; + + public MessageInfoLogic(ILogger Logger, IMessageInfoStorage MessageInfoStorage, IClientStorage ClientStorage) + { + _logger = Logger; + _messageInfoStorage = MessageInfoStorage; + _clientStorage = ClientStorage; + } + + public List? ReadList(MessageInfoSearchModel? Model) + { + _logger.LogDebug("ReadList. MessageId: {MessageId}, ClientId: {ClientId}", Model?.MessageId, Model?.ClientId); + + var Result = Model == null ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(Model); + + _logger.LogDebug("ReadList result. Count: {Count}", Result.Count); + return Result; + } + + public bool Create(MessageInfoBindingModel Model) + { + try { + CheckModel(Model); + + if (_messageInfoStorage.Insert(Model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + } + catch { } + return true; + + } + + private void CheckModel(MessageInfoBindingModel Model, bool WithParams = true) + { + if (Model == null) + throw new ArgumentNullException(nameof(Model)); + + if (!WithParams) + return; + + if (string.IsNullOrEmpty(Model.MessageId)) + throw new ArgumentNullException("Не указан id сообщения", nameof(Model.MessageId)); + + if (string.IsNullOrEmpty(Model.SenderName)) + throw new ArgumentNullException("Не указао почта", nameof(Model.SenderName)); + + if (string.IsNullOrEmpty(Model.Subject)) + throw new ArgumentNullException("Не указана тема", nameof(Model.Subject)); + + if (string.IsNullOrEmpty(Model.Body)) + throw new ArgumentNullException("Не указан текст сообщения", nameof(Model.Subject)); + + _logger.LogInformation("MessageInfo. MessageId: {MessageId}. SenderName: {SenderName}. Subject: {Subject}. Body: {Body}", + Model.MessageId, Model.SenderName, Model.Subject, Model.Body); + + var Element = _clientStorage.GetElement(new ClientSearchModel + { + Email = Model.SenderName + }); + + if (Element == null) + { + _logger.LogWarning("Не удалось найти клиента, отправившего письмо с адреса {Email}", Model.SenderName); + } + else + { + Model.ClientId = Element.Id; + } + } + } +} diff --git a/Bar/BarBusinessLogic/BarBusinessLogic/BusinessLogics/OrderLogic.cs b/Bar/BarBusinessLogic/BarBusinessLogic/BusinessLogics/OrderLogic.cs index 08f6c58..a922251 100644 --- a/Bar/BarBusinessLogic/BarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/Bar/BarBusinessLogic/BarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -1,4 +1,5 @@ -using BarContracts.BindingModels; +using BarBusinessLogic.MailWorker; +using BarContracts.BindingModels; using BarContracts.BusinessLogicContracts; using BarContracts.SearchModels; using BarContracts.StoragesContracts; @@ -14,23 +15,28 @@ namespace BarBusinessLogic.BusinessLogics private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger Logger, IOrderStorage OrderStorage) + private readonly AbstractMailWorker _mailLogic; + + static readonly object _locker = new object(); + + public OrderLogic(ILogger Logger, IOrderStorage OrderStorage, AbstractMailWorker MailLogic) { _logger = Logger; _orderStorage = OrderStorage; + _mailLogic = MailLogic; } public List? ReadList(OrderSearchModel? Model) { - _logger.LogInformation("ReadList. Id:{Id}", Model?.Id); - var List = Model is null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(Model); + _logger.LogInformation("ReadList. ClientId: {ClientId}. Status: {Status}. ImplementerId: {ImplementerId}. DateFrom: {DateFrom}. DateTo: {DateTo}. OrderId: {Id}", + Model?.ClientId, Model?.Status, Model?.ImplementerId, Model?.DateFrom, Model?.DateTo, Model?.Id); + var List = Model is null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(Model); if (List is null) { _logger.LogWarning("ReadList return null list"); return null; } - _logger.LogInformation("ReadList. Count: {Count}", List.Count); return List; } @@ -47,21 +53,28 @@ namespace BarBusinessLogic.BusinessLogics Model.Status = OrderStatus.Accepted; - if (_orderStorage.Insert(Model) is null) + var CreatedOrder = _orderStorage.Insert(Model); + + if (CreatedOrder == null) { _logger.LogWarning("Insert operation failed"); return false; } + Task.Run(() => _mailLogic.SendMailAsync(new MailSendInfoBindingModel + { + MailAddress = CreatedOrder.ClientEmail, + Subject = $"Изменение статуса заказа номер {CreatedOrder.Id}", + Text = $"Ваш заказ номер {CreatedOrder.Id} на коктейль {CreatedOrder.CocktailName} от {CreatedOrder.DateCreate} на сумму {CreatedOrder.Sum} принят." + })); + return true; } private bool ChangeOrderStatus(OrderBindingModel Model, OrderStatus NewStatus) { CheckModel(Model, false); - var Order = _orderStorage.GetElement(new OrderSearchModel { Id = Model.Id }); - if (Order == null) { _logger.LogWarning("Change status operation failed. Order not found"); @@ -94,12 +107,23 @@ namespace BarBusinessLogic.BusinessLogics return false; } + string DateInfo = Model.DateImplement.HasValue ? $"Дата выполнения: {Model.DateImplement}" : ""; + Task.Run(() => _mailLogic.SendMailAsync(new MailSendInfoBindingModel + { + MailAddress = Order.ClientEmail, + Subject = $"Изменение статуса заказа номер {Order.Id}", + Text = $"Ваш заказ номер {Order.Id} на ремонт {Order.CocktailName} от {Order.DateCreate} на сумму {Order.Sum}. Статус изменен на {NewStatus}. {DateInfo}" + })); + return true; } public bool TakeOrderInWork(OrderBindingModel Model) { - return ChangeOrderStatus(Model, OrderStatus.BeingProcessed); + lock (_locker) + { + return ChangeOrderStatus(Model, OrderStatus.BeingProcessed); + } } public bool FinishOrder(OrderBindingModel Model) @@ -121,7 +145,7 @@ namespace BarBusinessLogic.BusinessLogics return; if (Model.Count <= 0) - throw new ArgumentNullException("Количество напитков в заказе быть больше 0", nameof(Model.Count)); + throw new ArgumentNullException("Количество ремонтов в заказе быть больше 0", nameof(Model.Count)); if (Model.Sum <= 0) throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(Model.Sum)); diff --git a/Bar/BarBusinessLogic/BarBusinessLogic/MailWorker/AbstractMailWorker.cs b/Bar/BarBusinessLogic/BarBusinessLogic/MailWorker/AbstractMailWorker.cs new file mode 100644 index 0000000..f559664 --- /dev/null +++ b/Bar/BarBusinessLogic/BarBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -0,0 +1,84 @@ +using BarContracts.BindingModels; +using BarContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; + +namespace BarBusinessLogic.MailWorker +{ + public abstract class AbstractMailWorker + { + protected string _mailLogin = string.Empty; + + protected string _mailPassword = string.Empty; + + protected string _smtpClientHost = string.Empty; + + protected int _smtpClientPort; + + protected string _popHost = string.Empty; + + protected int _popPort; + + private readonly IMessageInfoLogic _messageInfoLogic; + + private readonly ILogger _logger; + + public AbstractMailWorker(ILogger Logger, IMessageInfoLogic MessageInfoLogic) + { + _logger = Logger; + _messageInfoLogic = MessageInfoLogic; + } + + public void MailConfig(MailConfigBindingModel Config) + { + _mailLogin = Config.MailLogin; + _mailPassword = Config.MailPassword; + _smtpClientHost = Config.SmtpClientHost; + _smtpClientPort = Config.SmtpClientPort; + _popHost = Config.PopHost; + _popPort = Config.PopPort; + + _logger.LogDebug("MailConfig: {Login}, {Password}, {ClientHost}, {ClientPort}, {PopHost}, {PopPort}", + _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort); + } + + public async void SendMailAsync(MailSendInfoBindingModel Info) + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + return; + + if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0) + return; + + if (string.IsNullOrEmpty(Info.MailAddress) || string.IsNullOrEmpty(Info.Subject) || string.IsNullOrEmpty(Info.Text)) + return; + + _logger.LogDebug("MailSendAsync: {To}, {Subject}", Info.MailAddress, Info.Subject); + + await SendMailImpl(Info); + } + + public async void CheckMailAsync() + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + return; + + if (string.IsNullOrEmpty(_popHost) || _popPort == 0) + return; + + if (_messageInfoLogic == null) + return; + + var List = await ReceiveMailImpl(); + _logger.LogDebug("CheckMailAsync: New mails: {Count}", List.Count); + + foreach (var Mail in List) + { + _messageInfoLogic.Create(Mail); + } + } + + protected abstract Task SendMailImpl(MailSendInfoBindingModel Info); + + protected abstract Task> ReceiveMailImpl(); + } +} diff --git a/Bar/BarBusinessLogic/BarBusinessLogic/MailWorker/MailKitWorker.cs b/Bar/BarBusinessLogic/BarBusinessLogic/MailWorker/MailKitWorker.cs new file mode 100644 index 0000000..059066a --- /dev/null +++ b/Bar/BarBusinessLogic/BarBusinessLogic/MailWorker/MailKitWorker.cs @@ -0,0 +1,87 @@ +using BarContracts.BindingModels; +using BarContracts.BusinessLogicContracts; +using MailKit.Net.Pop3; +using MailKit.Security; +using Microsoft.Extensions.Logging; +using System.Net; +using System.Net.Mail; +using System.Text; + +namespace BarBusinessLogic.MailWorker +{ + public class MailKitWorker : AbstractMailWorker + { + public MailKitWorker(ILogger Logger, IMessageInfoLogic MessageInfoLogic) + : base(Logger, MessageInfoLogic) { } + + protected override async Task SendMailImpl(MailSendInfoBindingModel Info) + { + using var MailMessage = new MailMessage(); + using var SmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort); + + try + { + MailMessage.From = new MailAddress(_mailLogin); + MailMessage.To.Add(new MailAddress(Info.MailAddress)); + MailMessage.Subject = Info.Subject; + MailMessage.Body = Info.Text; + MailMessage.SubjectEncoding = Encoding.UTF8; + MailMessage.BodyEncoding = Encoding.UTF8; + + SmtpClient.UseDefaultCredentials = false; + SmtpClient.EnableSsl = true; + SmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; + SmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword); + + await Task.Run(() => SmtpClient.Send(MailMessage)); + } + catch (Exception) + { + throw; + } + } + + protected override async Task> ReceiveMailImpl() + { + var Result = new List(); + + using var Client = new Pop3Client(); + + await Task.Run(() => + { + try + { + Client.Connect(_popHost, _popPort, SecureSocketOptions.SslOnConnect); + Client.Authenticate(_mailLogin, _mailPassword); + + for (int i = 0; i < Client.Count; i++) + { + var Message = Client.GetMessage(i); + + + foreach (var Mail in Message.From.Mailboxes) + { + //if (Mail.Address.Contains("o.filippova")) + Result.Add(new MessageInfoBindingModel + { + DateDelivery = Message.Date.DateTime, + MessageId = Message.MessageId, + SenderName = Mail.Address, + Subject = Message.Subject, + Body = Message.TextBody + }); + } + } + } + catch (AuthenticationException) + { } + finally + { + Client.Disconnect(true); + } + }); + + return Result; + } + } +} diff --git a/Bar/BarClientApp/BarClientApp.csproj b/Bar/BarClientApp/BarClientApp.csproj index 71564ab..75f49ac 100644 --- a/Bar/BarClientApp/BarClientApp.csproj +++ b/Bar/BarClientApp/BarClientApp.csproj @@ -12,6 +12,7 @@ + diff --git a/Bar/BarClientApp/Controllers/HomeController.cs b/Bar/BarClientApp/Controllers/HomeController.cs index 30b4559..7fce3be 100644 --- a/Bar/BarClientApp/Controllers/HomeController.cs +++ b/Bar/BarClientApp/Controllers/HomeController.cs @@ -156,5 +156,16 @@ namespace BarClientApp.Controllers CocktailViewModel? Cocktail = ApiClient.GetRequest($"api/main/getcocktail?cocktailId={cocktail}"); return count * (Cocktail?.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/Bar/BarClientApp/Views/Home/Create.cshtml b/Bar/BarClientApp/Views/Home/Create.cshtml index 9322a2e..dc39b51 100644 --- a/Bar/BarClientApp/Views/Home/Create.cshtml +++ b/Bar/BarClientApp/Views/Home/Create.cshtml @@ -7,7 +7,7 @@
-
Коктейль:
+
Ремонт:
diff --git a/Bar/BarClientApp/Views/Home/Index.cshtml b/Bar/BarClientApp/Views/Home/Index.cshtml index dbc8c77..a95d0de 100644 --- a/Bar/BarClientApp/Views/Home/Index.cshtml +++ b/Bar/BarClientApp/Views/Home/Index.cshtml @@ -23,7 +23,7 @@ Номер - Коктейль + Ремонт Дата создания diff --git a/Bar/BarClientApp/Views/Home/Mails.cshtml b/Bar/BarClientApp/Views/Home/Mails.cshtml new file mode 100644 index 0000000..a02159c --- /dev/null +++ b/Bar/BarClientApp/Views/Home/Mails.cshtml @@ -0,0 +1,51 @@ +@using BarContracts.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) +
+ } +
diff --git a/Bar/BarClientApp/Views/Shared/_Layout.cshtml b/Bar/BarClientApp/Views/Shared/_Layout.cshtml index b5451af..9833c54 100644 --- a/Bar/BarClientApp/Views/Shared/_Layout.cshtml +++ b/Bar/BarClientApp/Views/Shared/_Layout.cshtml @@ -13,7 +13,7 @@