From 8279dbba2b3e89a8a8b45415214e169f2f9df22d Mon Sep 17 00:00:00 2001 From: aleksandr chegodaev Date: Sun, 16 Jun 2024 21:45:04 +0400 Subject: [PATCH] lab7 --- LawFirm/LawFirm/App.config | 11 + LawFirm/LawFirm/FormMail.Designer.cs | 62 ++++ LawFirm/LawFirm/FormMail.cs | 51 +++ LawFirm/LawFirm/FormMail.resx | 60 ++++ LawFirm/LawFirm/FormMain.Designer.cs | 328 +++++++++--------- LawFirm/LawFirm/FormMain.cs | 11 +- LawFirm/LawFirm/LawFirmView.csproj | 3 + LawFirm/LawFirm/Program.cs | 46 ++- .../BusinessLogic/ClientLogic.cs | 11 +- .../BusinessLogic/MessageInfoLogic.cs | 51 +++ .../BusinessLogic/OrderLogic.cs | 72 +++- .../LawFirmBusinessLogic.csproj | 1 + .../MailWorker/AbstractMailWorker.cs | 81 +++++ .../MailWorker/MailKitWorker.cs | 85 +++++ .../Controllers/HomeController.cs | 12 +- .../LawFirmClientApp/LawFirmClientApp.csproj | 17 + LawFirm/LawFirmClientApp/Program.cs | 2 +- .../LawFirmClientApp/Views/Home/Mails.cshtml | 53 +++ .../Views/Shared/_Layout.cshtml | 3 + .../BindingModels/MailConfigBindingModel.cs | 17 + .../BindingModels/MailSendInfoBindingModel.cs | 15 + .../BindingModels/MessageInfoBindingModel.cs | 24 ++ .../IMessageInfoLogic.cs | 17 + .../SearchModels/MessageInfoSearchModel.cs | 14 + .../StoragesContracts/IMessageInfoStorage.cs | 19 + .../ViewModels/MessageInfoViewModel.cs | 25 ++ .../Models/IMessageInfoModel.cs | 18 + .../Implements/ClientStorage.cs | 2 +- .../Implements/MessageInfoStorage.cs | 59 ++++ .../LawFirmDataBase.cs | 3 +- .../LawFirmDatabaseImplement.csproj | 2 + ... 20240616174259_InitialCreate.Designer.cs} | 43 ++- ...ate.cs => 20240616174259_InitialCreate.cs} | 29 ++ .../LawFirmDatabaseModelSnapshot.cs | 41 +++ .../LawFirmDatabaseImplement/Models/Client.cs | 4 +- .../Models/MessageInfo.cs | 54 +++ .../LawFirmFileImplement/DataFileSingleton.cs | 12 +- .../Implements/MessageInfoStorage.cs | 58 ++++ .../Models/MessageInfo.cs | 80 +++++ .../LawFirmListImplement/DataListSingleton.cs | 6 +- .../Implements/MessageInfoStorage.cs | 73 ++++ .../Models/MessageInfo.cs | 51 +++ .../Controllers/ClientController.cs | 24 +- LawFirm/LawFirmRestApi/Program.cs | 19 +- LawFirm/LawFirmRestApi/appsettings.json | 8 +- 45 files changed, 1480 insertions(+), 197 deletions(-) create mode 100644 LawFirm/LawFirm/App.config create mode 100644 LawFirm/LawFirm/FormMail.Designer.cs create mode 100644 LawFirm/LawFirm/FormMail.cs create mode 100644 LawFirm/LawFirm/FormMail.resx create mode 100644 LawFirm/LawFirmBusinessLogic/BusinessLogic/MessageInfoLogic.cs create mode 100644 LawFirm/LawFirmBusinessLogic/MailWorker/AbstractMailWorker.cs create mode 100644 LawFirm/LawFirmBusinessLogic/MailWorker/MailKitWorker.cs create mode 100644 LawFirm/LawFirmClientApp/Views/Home/Mails.cshtml create mode 100644 LawFirm/LawFirmContracts/BindingModels/MailConfigBindingModel.cs create mode 100644 LawFirm/LawFirmContracts/BindingModels/MailSendInfoBindingModel.cs create mode 100644 LawFirm/LawFirmContracts/BindingModels/MessageInfoBindingModel.cs create mode 100644 LawFirm/LawFirmContracts/BusinessLogicsContracts/IMessageInfoLogic.cs create mode 100644 LawFirm/LawFirmContracts/SearchModels/MessageInfoSearchModel.cs create mode 100644 LawFirm/LawFirmContracts/StoragesContracts/IMessageInfoStorage.cs create mode 100644 LawFirm/LawFirmContracts/ViewModels/MessageInfoViewModel.cs create mode 100644 LawFirm/LawFirmDataModels/Models/IMessageInfoModel.cs create mode 100644 LawFirm/LawFirmDatabaseImplement/Implements/MessageInfoStorage.cs rename LawFirm/LawFirmDatabaseImplement/Migrations/{20240616172608_InitialCreate.Designer.cs => 20240616174259_InitialCreate.Designer.cs} (85%) rename LawFirm/LawFirmDatabaseImplement/Migrations/{20240616172608_InitialCreate.cs => 20240616174259_InitialCreate.cs} (85%) create mode 100644 LawFirm/LawFirmDatabaseImplement/Models/MessageInfo.cs create mode 100644 LawFirm/LawFirmFileImplement/Implements/MessageInfoStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/Models/MessageInfo.cs create mode 100644 LawFirm/LawFirmListImplement/Implements/MessageInfoStorage.cs create mode 100644 LawFirm/LawFirmListImplement/Models/MessageInfo.cs diff --git a/LawFirm/LawFirm/App.config b/LawFirm/LawFirm/App.config new file mode 100644 index 0000000..26115b9 --- /dev/null +++ b/LawFirm/LawFirm/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/LawFirm/LawFirm/FormMail.Designer.cs b/LawFirm/LawFirm/FormMail.Designer.cs new file mode 100644 index 0000000..2864428 --- /dev/null +++ b/LawFirm/LawFirm/FormMail.Designer.cs @@ -0,0 +1,62 @@ +namespace LawFirmView +{ + 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() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(965, 381); + this.dataGridView.TabIndex = 0; + // + // FormMail + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(966, 423); + this.Controls.Add(this.dataGridView); + this.Name = "FormMail"; + this.Text = "FormMail"; + this.Load += new System.EventHandler(this.FormMail_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirm/FormMail.cs b/LawFirm/LawFirm/FormMail.cs new file mode 100644 index 0000000..f1c86df --- /dev/null +++ b/LawFirm/LawFirm/FormMail.cs @@ -0,0 +1,51 @@ +using LawFirmContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LawFirmView +{ + public partial class FormMail : Form + { + private readonly ILogger _logger; + private readonly IMessageInfoLogic _logic; + public FormMail(ILogger logger, IMessageInfoLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormMail_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["MessageId"].Visible = false; + dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Loading materials"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error loading materials"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/LawFirm/LawFirm/FormMail.resx b/LawFirm/LawFirm/FormMail.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirm/FormMail.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/LawFirm/LawFirm/FormMain.Designer.cs b/LawFirm/LawFirm/FormMain.Designer.cs index 202c301..4ab84fa 100644 --- a/LawFirm/LawFirm/FormMain.Designer.cs +++ b/LawFirm/LawFirm/FormMain.Designer.cs @@ -28,173 +28,182 @@ /// private void InitializeComponent() { - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - this.toolStripMenuItemCatalogs = new System.Windows.Forms.ToolStripMenuItem(); - this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.пакетыДокументовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.списокПакетовДокументовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.компонентыПоПакетамДокументовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.buttonCreateOrder = new System.Windows.Forms.Button(); - this.buttonIssuedOrder = new System.Windows.Forms.Button(); - this.buttonRef = new System.Windows.Forms.Button(); - this.menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // menuStrip1 - // - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.toolStripMenuItemCatalogs = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.пакетыДокументовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокПакетовДокументовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыПоПакетамДокументовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.buttonIssuedOrder = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.почтаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItemCatalogs, this.отчётыToolStripMenuItem, - this.запускРаботToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1047, 24); - this.menuStrip1.TabIndex = 0; - this.menuStrip1.Text = "Справочники"; - // - // toolStripMenuItemCatalogs - // - this.toolStripMenuItemCatalogs.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.запускРаботToolStripMenuItem, + this.почтаToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1047, 24); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "Справочники"; + // + // toolStripMenuItemCatalogs + // + this.toolStripMenuItemCatalogs.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, this.пакетыДокументовToolStripMenuItem, this.клиентыToolStripMenuItem, this.исполнителиToolStripMenuItem}); - this.toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs"; - this.toolStripMenuItemCatalogs.Size = new System.Drawing.Size(94, 20); - this.toolStripMenuItemCatalogs.Text = "Справочники"; - // - // компонентыToolStripMenuItem - // - this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(183, 22); - this.компонентыToolStripMenuItem.Text = "Компоненты"; - this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); - // - // пакетыДокументовToolStripMenuItem - // - this.пакетыДокументовToolStripMenuItem.Name = "пакетыДокументовToolStripMenuItem"; - this.пакетыДокументовToolStripMenuItem.Size = new System.Drawing.Size(183, 22); - this.пакетыДокументовToolStripMenuItem.Text = "Пакеты документов"; - this.пакетыДокументовToolStripMenuItem.Click += new System.EventHandler(this.пакетыДокументовToolStripMenuItem_Click); - // - // клиентыToolStripMenuItem - // - this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(183, 22); - this.клиентыToolStripMenuItem.Text = "Клиенты"; - this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); - // - // исполнителиToolStripMenuItem - // - this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(183, 22); - this.исполнителиToolStripMenuItem.Text = "Исполнители"; - this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); - // - // отчётыToolStripMenuItem - // - this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs"; + this.toolStripMenuItemCatalogs.Size = new System.Drawing.Size(94, 20); + this.toolStripMenuItemCatalogs.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(183, 22); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); + // + // пакетыДокументовToolStripMenuItem + // + this.пакетыДокументовToolStripMenuItem.Name = "пакетыДокументовToolStripMenuItem"; + this.пакетыДокументовToolStripMenuItem.Size = new System.Drawing.Size(183, 22); + this.пакетыДокументовToolStripMenuItem.Text = "Пакеты документов"; + this.пакетыДокументовToolStripMenuItem.Click += new System.EventHandler(this.пакетыДокументовToolStripMenuItem_Click); + // + // клиентыToolStripMenuItem + // + this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(183, 22); + this.клиентыToolStripMenuItem.Text = "Клиенты"; + this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); + // + // исполнителиToolStripMenuItem + // + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(183, 22); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); + // + // отчётыToolStripMenuItem + // + this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.списокПакетовДокументовToolStripMenuItem, this.компонентыПоПакетамДокументовToolStripMenuItem, this.списокЗаказовToolStripMenuItem}); - this.отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; - this.отчётыToolStripMenuItem.Size = new System.Drawing.Size(60, 20); - this.отчётыToolStripMenuItem.Text = "Отчёты"; - // - // списокПакетовДокументовToolStripMenuItem - // - this.списокПакетовДокументовToolStripMenuItem.Name = "списокПакетовДокументовToolStripMenuItem"; - this.списокПакетовДокументовToolStripMenuItem.Size = new System.Drawing.Size(278, 22); - this.списокПакетовДокументовToolStripMenuItem.Text = "Список пакетов документов"; - this.списокПакетовДокументовToolStripMenuItem.Click += new System.EventHandler(this.списокПакетовДокументовToolStripMenuItem_Click); - // - // компонентыПоПакетамДокументовToolStripMenuItem - // - this.компонентыПоПакетамДокументовToolStripMenuItem.Name = "компонентыПоПакетамДокументовToolStripMenuItem"; - this.компонентыПоПакетамДокументовToolStripMenuItem.Size = new System.Drawing.Size(278, 22); - this.компонентыПоПакетамДокументовToolStripMenuItem.Text = "Компоненты по пакетам документов"; - this.компонентыПоПакетамДокументовToolStripMenuItem.Click += new System.EventHandler(this.компонентыПоПакетамДокументовToolStripMenuItem_Click); - // - // списокЗаказовToolStripMenuItem - // - this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(278, 22); - this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; - this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); - // - // запускРаботToolStripMenuItem - // - this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; - this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(92, 20); - this.запускРаботToolStripMenuItem.Text = "Запуск работ"; - this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click); - // - // dataGridView - // - this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(0, 27); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(873, 411); - this.dataGridView.TabIndex = 1; - // - // buttonCreateOrder - // - this.buttonCreateOrder.Location = new System.Drawing.Point(879, 39); - this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(156, 26); - this.buttonCreateOrder.TabIndex = 2; - this.buttonCreateOrder.Text = "Создать заказ"; - this.buttonCreateOrder.UseVisualStyleBackColor = true; - this.buttonCreateOrder.Click += new System.EventHandler(this.buttonCreateOrder_Click); - // - // buttonIssuedOrder - // - this.buttonIssuedOrder.Location = new System.Drawing.Point(879, 71); - this.buttonIssuedOrder.Name = "buttonIssuedOrder"; - this.buttonIssuedOrder.Size = new System.Drawing.Size(156, 23); - this.buttonIssuedOrder.TabIndex = 5; - this.buttonIssuedOrder.Text = "Заказ выдан"; - this.buttonIssuedOrder.UseVisualStyleBackColor = true; - this.buttonIssuedOrder.Click += new System.EventHandler(this.buttonIssuedOrder_Click); - // - // buttonRef - // - this.buttonRef.Location = new System.Drawing.Point(879, 100); - this.buttonRef.Name = "buttonRef"; - this.buttonRef.Size = new System.Drawing.Size(156, 23); - this.buttonRef.TabIndex = 6; - this.buttonRef.Text = "Обновить список"; - this.buttonRef.UseVisualStyleBackColor = true; - this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); - // - // FormMain - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1047, 477); - this.Controls.Add(this.buttonRef); - this.Controls.Add(this.buttonIssuedOrder); - this.Controls.Add(this.buttonCreateOrder); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.menuStrip1); - this.MainMenuStrip = this.menuStrip1; - this.Name = "FormMain"; - this.Text = "FormMain"; - this.Load += new System.EventHandler(this.FormMain_Load); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + this.отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; + this.отчётыToolStripMenuItem.Size = new System.Drawing.Size(60, 20); + this.отчётыToolStripMenuItem.Text = "Отчёты"; + // + // списокПакетовДокументовToolStripMenuItem + // + this.списокПакетовДокументовToolStripMenuItem.Name = "списокПакетовДокументовToolStripMenuItem"; + this.списокПакетовДокументовToolStripMenuItem.Size = new System.Drawing.Size(278, 22); + this.списокПакетовДокументовToolStripMenuItem.Text = "Список пакетов документов"; + this.списокПакетовДокументовToolStripMenuItem.Click += new System.EventHandler(this.списокПакетовДокументовToolStripMenuItem_Click); + // + // компонентыПоПакетамДокументовToolStripMenuItem + // + this.компонентыПоПакетамДокументовToolStripMenuItem.Name = "компонентыПоПакетамДокументовToolStripMenuItem"; + this.компонентыПоПакетамДокументовToolStripMenuItem.Size = new System.Drawing.Size(278, 22); + this.компонентыПоПакетамДокументовToolStripMenuItem.Text = "Компоненты по пакетам документов"; + this.компонентыПоПакетамДокументовToolStripMenuItem.Click += new System.EventHandler(this.компонентыПоПакетамДокументовToolStripMenuItem_Click); + // + // списокЗаказовToolStripMenuItem + // + this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(278, 22); + this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; + this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); + // + // запускРаботToolStripMenuItem + // + this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(92, 20); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 27); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(873, 411); + this.dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(879, 39); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(156, 26); + this.buttonCreateOrder.TabIndex = 2; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.buttonCreateOrder_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Location = new System.Drawing.Point(879, 71); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(156, 23); + this.buttonIssuedOrder.TabIndex = 5; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.buttonIssuedOrder_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(879, 100); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(156, 23); + this.buttonRef.TabIndex = 6; + this.buttonRef.Text = "Обновить список"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // почтаToolStripMenuItem + // + this.почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; + this.почтаToolStripMenuItem.Size = new System.Drawing.Size(53, 20); + this.почтаToolStripMenuItem.Text = "Почта"; + this.почтаToolStripMenuItem.Click += new System.EventHandler(this.почтаToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1047, 477); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "FormMain"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); } @@ -215,5 +224,6 @@ private ToolStripMenuItem клиентыToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; - } + private ToolStripMenuItem почтаToolStripMenuItem; + } } \ No newline at end of file diff --git a/LawFirm/LawFirm/FormMain.cs b/LawFirm/LawFirm/FormMain.cs index 7a1a28f..eef5f4f 100644 --- a/LawFirm/LawFirm/FormMain.cs +++ b/LawFirm/LawFirm/FormMain.cs @@ -188,5 +188,14 @@ namespace LawFirmView _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } - } + + private void почтаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMail)); + if (service is FormMail form) + { + form.ShowDialog(); + } + } + } } diff --git a/LawFirm/LawFirm/LawFirmView.csproj b/LawFirm/LawFirm/LawFirmView.csproj index 80d7bc0..18bef26 100644 --- a/LawFirm/LawFirm/LawFirmView.csproj +++ b/LawFirm/LawFirm/LawFirmView.csproj @@ -26,6 +26,9 @@ + + Always + Always diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index f8e334a..530622f 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -1,6 +1,7 @@ using LawFirmBusinessLogic.BusinessLogic; using LawFirmBusinessLogic.OfficePackage.Implements; using LawFirmBusinessLogic.OfficePackage; +using LawFirmBusinessLogic.MailWorker; using LawFirmContracts.BusinessLogicsContracts; using LawFirmContracts.StoragesContracts; using LawFirmDatabaseImplement.Implements; @@ -8,6 +9,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using System; +using LawFirmBusinessLogic.MailWorker; +using LawFirmContracts.BindingModels; namespace LawFirmView { @@ -27,7 +30,38 @@ namespace LawFirmView var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); - Application.Run(_serviceProvider.GetRequiredService()); + 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, 100000); + } + catch (Exception ex) + { + var logger = _serviceProvider.GetService(); + logger?.LogError(ex, " "); + } + + Application.Run(_serviceProvider.GetRequiredService()); } private static void ConfigureServices(ServiceCollection services) { @@ -48,7 +82,10 @@ namespace LawFirmView services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddSingleton(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -63,7 +100,8 @@ namespace LawFirmView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } - - } + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + } } \ No newline at end of file diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogic/ClientLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogic/ClientLogic.cs index f33e066..d59eefa 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogic/ClientLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogic/ClientLogic.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace LawFirmBusinessLogic.BusinessLogic @@ -99,11 +100,15 @@ namespace LawFirmBusinessLogic.BusinessLogic { throw new ArgumentNullException("Нет ФИО клиента", nameof(model.ClientFIO)); } - if (string.IsNullOrEmpty(model.Email)) + if (string.IsNullOrEmpty(model.Email) || !Regex.IsMatch(model.Email, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$", RegexOptions.IgnoreCase)) { - throw new ArgumentNullException("Нет логина(почты) клиента", nameof(model.Email)); + throw new ArgumentNullException("Нет логина(почты) клиента или он введён неверно", nameof(model.Email)); } - _logger.LogInformation("Client. Id: {Id}, FIO: {fio}, email: {email}", model.Id, model.ClientFIO, model.Email); + if (string.IsNullOrEmpty(model.Password) || !Regex.IsMatch(model.Password, @"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$")) + { + throw new ArgumentNullException("Нет пароля клиента или он введён неверно", nameof(model.Password)); + } + _logger.LogInformation("Client. Id: {Id}, FIO: {fio}, email: {email}", model.Id, model.ClientFIO, model.Email); var element = _clientStorage.GetElement(new ClientSearchModel { Email = model.Email, diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogic/MessageInfoLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogic/MessageInfoLogic.cs new file mode 100644 index 0000000..f4102a7 --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogic/MessageInfoLogic.cs @@ -0,0 +1,51 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicsContracts; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; +using LawFirmContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.BusinessLogic +{ + public class MessageInfoLogic : IMessageInfoLogic + { + private readonly ILogger _logger; + + private readonly IMessageInfoStorage _messageStorage; + + public MessageInfoLogic(IMessageInfoStorage messageStorage, ILogger logger) + { + _messageStorage = messageStorage; + _logger = logger; + } + public bool Create(MessageInfoBindingModel model) + { + if (_messageStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public List? ReadList(MessageInfoSearchModel? model) + { + _logger.LogInformation("ReadList. ClientID:{ClientID}. ID:{ ID}", model?.ClientId, model?.MessageId); + + var list = model == null ? _messageStorage.GetFullList() : _messageStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + } +} diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogic/OrderLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogic/OrderLogic.cs index 7aa5f43..ff8f39b 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogic/OrderLogic.cs @@ -1,4 +1,5 @@ -using LawFirmContracts.BindingModels; +using LawFirmBusinessLogic.MailWorker; +using LawFirmContracts.BindingModels; using LawFirmContracts.BusinessLogicsContracts; using LawFirmContracts.SearchModels; using LawFirmContracts.StoragesContracts; @@ -17,13 +18,17 @@ namespace LawFirmBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IClientStorage _clientStorage; + private readonly AbstractMailWorker _mailLogic; static readonly object locker = new object(); - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IClientStorage clientStorage, AbstractMailWorker worker) { _logger = logger; _orderStorage = orderStorage; - } + _clientStorage = clientStorage; + _mailLogic = worker; + } public List? ReadList(OrderSearchModel? model) { @@ -60,12 +65,16 @@ namespace LawFirmBusinessLogic.BusinessLogic CheckModel(model); if (model.Status != OrderStatus.Неизвестен) return false; model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; + var order = _orderStorage.Insert(model); + if (order == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + var clientView = _clientStorage.GetElement(new() { Id = order!.ClientId }); + + SendEmail(clientView, order); + return true; } public bool ChangeStatus(OrderBindingModel model, OrderStatus status) @@ -85,8 +94,16 @@ namespace LawFirmBusinessLogic.BusinessLogic model.Status = status; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; if (element.ImplementerId.HasValue) model.ImplementerId = element.ImplementerId; - _orderStorage.Update(model); - return true; + element = _orderStorage.Update(model); + if(element == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + var clientView = _clientStorage.GetElement(new() { Id = element.ClientId }); + + SendEmail(clientView, element); + return true; } public bool TakeOrderInWork(OrderBindingModel model) @@ -128,5 +145,36 @@ true) } _logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id); } - } + public void SendEmail(ClientViewModel clientModel, OrderViewModel orderModel) + { + if (clientModel == null && orderModel == null) + { + return; + } + + MailSendInfoBindingModel mailModel; + + if (orderModel.Status == OrderStatus.Принят) + { + mailModel = new MailSendInfoBindingModel + { + MailAddress = clientModel.Email, + Subject = $"Order №{orderModel.Id}", + Text = $"Your order №{orderModel.Id} by {orderModel.DateCreate} on {orderModel.Sum} was accepted!" + }; + } + else + { + mailModel = new MailSendInfoBindingModel + { + MailAddress = clientModel.Email, + Subject = $"Order №{orderModel.Id}", + Text = $"Order №{orderModel.Id} status was changed to {orderModel.Status}" + }; + } + + + _mailLogic.MailSendAsync(mailModel); + } + } } diff --git a/LawFirm/LawFirmBusinessLogic/LawFirmBusinessLogic.csproj b/LawFirm/LawFirmBusinessLogic/LawFirmBusinessLogic.csproj index b30d1d3..07502e3 100644 --- a/LawFirm/LawFirmBusinessLogic/LawFirmBusinessLogic.csproj +++ b/LawFirm/LawFirmBusinessLogic/LawFirmBusinessLogic.csproj @@ -8,6 +8,7 @@ + diff --git a/LawFirm/LawFirmBusinessLogic/MailWorker/AbstractMailWorker.cs b/LawFirm/LawFirmBusinessLogic/MailWorker/AbstractMailWorker.cs new file mode 100644 index 0000000..d8bf26f --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -0,0 +1,81 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.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; + _logger.LogWarning("INIT ABSTRACT MAIL WORKER"); + } + 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("Config: {login}, {password}, {clientHost}, {clientPort}, {popHost}, {popPort} ", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort); + } + public async void MailSendAsync(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("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject); + await SendMailAsync(info); + } + public async void MailCheck() + { + if (string.IsNullOrEmpty(_mailLogin) || + string.IsNullOrEmpty(_mailPassword)) + { + return; + } + if (string.IsNullOrEmpty(_popHost) || _popPort == 0) + { + return; + } + if (_messageInfoLogic == null) + { + return; + } + var list = await ReceiveMailAsync(); + _logger.LogDebug("Check Mail: {Count} new mails", list.Count); + foreach (var mail in list) + { + _messageInfoLogic.Create(mail); + } + } + protected abstract Task SendMailAsync(MailSendInfoBindingModel info); + protected abstract Task> ReceiveMailAsync(); + + } +} diff --git a/LawFirm/LawFirmBusinessLogic/MailWorker/MailKitWorker.cs b/LawFirm/LawFirmBusinessLogic/MailWorker/MailKitWorker.cs new file mode 100644 index 0000000..cf6dc4d --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/MailWorker/MailKitWorker.cs @@ -0,0 +1,85 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicsContracts; +using MailKit.Net.Pop3; +using MailKit.Security; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mail; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.MailWorker +{ + public class MailKitWorker : AbstractMailWorker + { + public MailKitWorker(ILogger logger, IMessageInfoLogic +messageInfoLogic) : base(logger, messageInfoLogic) { } + protected override async Task SendMailAsync(MailSendInfoBindingModel + info) + { + using var objMailMessage = new MailMessage(); + using var objSmtpClient = new SmtpClient(_smtpClientHost, + _smtpClientPort); + try + { + objMailMessage.From = new MailAddress(_mailLogin); + objMailMessage.To.Add(new MailAddress(info.MailAddress)); + objMailMessage.Subject = info.Subject; + objMailMessage.Body = info.Text; + objMailMessage.SubjectEncoding = Encoding.UTF8; + objMailMessage.BodyEncoding = Encoding.UTF8; + objSmtpClient.UseDefaultCredentials = false; + objSmtpClient.EnableSsl = true; + objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; + objSmtpClient.Credentials = new NetworkCredential(_mailLogin, + _mailPassword); + await Task.Run(() => objSmtpClient.Send(objMailMessage)); + } + catch (Exception) + { + throw; + } + } + protected override async Task> + ReceiveMailAsync() + { + var list = new List(); + using var client = new Pop3Client(); + await Task.Run(() => + { + try + { + client.CheckCertificateRevocation = false; + 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) + { + list.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 list; + } + + } +} diff --git a/LawFirm/LawFirmClientApp/Controllers/HomeController.cs b/LawFirm/LawFirmClientApp/Controllers/HomeController.cs index 84943ea..48fd182 100644 --- a/LawFirm/LawFirmClientApp/Controllers/HomeController.cs +++ b/LawFirm/LawFirmClientApp/Controllers/HomeController.cs @@ -2,6 +2,7 @@ using LawFirmContracts.BindingModels; using LawFirmContracts.ViewModels; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using System.Diagnostics; namespace LawFirmClientApp.Controllers @@ -134,6 +135,15 @@ namespace LawFirmClientApp.Controllers var doc = APIClient.GetRequest($"api/main/getdocument?documentId={document}"); return count * (doc?.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/LawFirm/LawFirmClientApp/LawFirmClientApp.csproj b/LawFirm/LawFirmClientApp/LawFirmClientApp.csproj index 982e934..b11fc2c 100644 --- a/LawFirm/LawFirmClientApp/LawFirmClientApp.csproj +++ b/LawFirm/LawFirmClientApp/LawFirmClientApp.csproj @@ -6,7 +6,12 @@ enable + + + + + @@ -14,4 +19,16 @@ + + + + + + <_ContentIncludedByDefault Remove="Views\Home\Mails.cshtml" /> + + + + + + diff --git a/LawFirm/LawFirmClientApp/Program.cs b/LawFirm/LawFirmClientApp/Program.cs index 26e4c85..80e8109 100644 --- a/LawFirm/LawFirmClientApp/Program.cs +++ b/LawFirm/LawFirmClientApp/Program.cs @@ -3,7 +3,7 @@ using LawFirmClientApp; var builder = WebApplication.CreateBuilder(args); // Add services to the container. -builder.Services.AddControllersWithViews(); +builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation(); var app = builder.Build(); APIClient.Connect(builder.Configuration); diff --git a/LawFirm/LawFirmClientApp/Views/Home/Mails.cshtml b/LawFirm/LawFirmClientApp/Views/Home/Mails.cshtml new file mode 100644 index 0000000..66a85d1 --- /dev/null +++ b/LawFirm/LawFirmClientApp/Views/Home/Mails.cshtml @@ -0,0 +1,53 @@ +@using LawFirmContracts.ViewModels +@model List + +@{ + ViewData["Title"] = "Mails"; +} + +
+

Письма

+
+ + +
+ @{ + if (Model == null) + { +

Login bobr!

+ return; + } + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Дата + + Заголовок + + Текст +
+ @Html.DisplayFor(modelItem => item.DateDelivery) + + @Html.DisplayFor(modelItem => item.Subject) + + @Html.DisplayFor(modelItem => item.Body) +
+ } +
diff --git a/LawFirm/LawFirmClientApp/Views/Shared/_Layout.cshtml b/LawFirm/LawFirmClientApp/Views/Shared/_Layout.cshtml index 367efd0..5d7a49f 100644 --- a/LawFirm/LawFirmClientApp/Views/Shared/_Layout.cshtml +++ b/LawFirm/LawFirmClientApp/Views/Shared/_Layout.cshtml @@ -27,6 +27,9 @@ Личные данные +