вроде готово

This commit is contained in:
ker73rus 2023-06-14 02:17:04 +04:00
parent 60b6950156
commit 4deff59b2b
43 changed files with 1261 additions and 169 deletions

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="SmtpClientHost" value="smtp.gmail.com" />
<add key="SmtpClientPort" value="587" />
<add key="PopHost" value="pop.gmail.com" />
<add key="PopPort" value="995" />
<add key="MailLogin" value="nothellfirescream@gmail.com" />
<add key="MailPassword" value="luqw smah ospl znhv" />
</appSettings>
</configuration>

View File

@ -28,207 +28,204 @@
/// </summary>
private void InitializeComponent()
{
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.FacilitiessToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SecuresToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ClientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ImplementersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SecuresReportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SecureFacilitiessReportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.OrdersReportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.StartWorkingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
menuStrip = new MenuStrip();
справочникиToolStripMenuItem = new ToolStripMenuItem();
FacilitiessToolStripMenuItem = new ToolStripMenuItem();
SecuresToolStripMenuItem = new ToolStripMenuItem();
ClientsToolStripMenuItem = new ToolStripMenuItem();
ImplementersToolStripMenuItem = new ToolStripMenuItem();
отчётыToolStripMenuItem = new ToolStripMenuItem();
SecuresReportToolStripMenuItem = new ToolStripMenuItem();
SecureFacilitiessReportToolStripMenuItem = new ToolStripMenuItem();
OrdersReportToolStripMenuItem = new ToolStripMenuItem();
StartWorkingToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
сообщенияToolStripMenuItem = new ToolStripMenuItem();
menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// menuStrip
//
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.справочникиToolStripMenuItem,
this.отчётыToolStripMenuItem,
this.StartWorkingToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2);
this.menuStrip.Size = new System.Drawing.Size(1149, 24);
this.menuStrip.TabIndex = 0;
this.menuStrip.Text = "Справочники";
menuStrip.ImageScalingSize = new Size(20, 20);
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, StartWorkingToolStripMenuItem, сообщенияToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Padding = new Padding(5, 2, 0, 2);
menuStrip.Size = new Size(1149, 24);
menuStrip.TabIndex = 0;
menuStrip.Text = "Справочники";
//
// справочникиToolStripMenuItem
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.FacilitiessToolStripMenuItem,
this.SecuresToolStripMenuItem,
this.ClientsToolStripMenuItem,
this.ImplementersToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.справочникиToolStripMenuItem.Text = "Справочники";
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { FacilitiessToolStripMenuItem, SecuresToolStripMenuItem, ClientsToolStripMenuItem, ImplementersToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(94, 20);
справочникиToolStripMenuItem.Text = "Справочники";
//
// FacilitiessToolStripMenuItem
//
this.FacilitiessToolStripMenuItem.Name = "FacilitiessToolStripMenuItem";
this.FacilitiessToolStripMenuItem.Size = new System.Drawing.Size(200, 22);
this.FacilitiessToolStripMenuItem.Text = "Оборудование";
this.FacilitiessToolStripMenuItem.Click += new System.EventHandler(this.FacilitiessToolStripMenuItem_Click);
FacilitiessToolStripMenuItem.Name = "FacilitiessToolStripMenuItem";
FacilitiessToolStripMenuItem.Size = new Size(200, 22);
FacilitiessToolStripMenuItem.Text = "Оборудование";
FacilitiessToolStripMenuItem.Click += FacilitiessToolStripMenuItem_Click;
//
// SecuresToolStripMenuItem
//
this.SecuresToolStripMenuItem.Name = "SecuresToolStripMenuItem";
this.SecuresToolStripMenuItem.Size = new System.Drawing.Size(200, 22);
this.SecuresToolStripMenuItem.Text = "Система безопасности";
this.SecuresToolStripMenuItem.Click += new System.EventHandler(this.SecuresToolStripMenuItem_Click);
SecuresToolStripMenuItem.Name = "SecuresToolStripMenuItem";
SecuresToolStripMenuItem.Size = new Size(200, 22);
SecuresToolStripMenuItem.Text = "Система безопасности";
SecuresToolStripMenuItem.Click += SecuresToolStripMenuItem_Click;
//
// ClientsToolStripMenuItem
//
this.ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem";
this.ClientsToolStripMenuItem.Size = new System.Drawing.Size(200, 22);
this.ClientsToolStripMenuItem.Text = "Клиенты";
this.ClientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem";
ClientsToolStripMenuItem.Size = new Size(200, 22);
ClientsToolStripMenuItem.Text = "Клиенты";
ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click;
//
// ImplementersToolStripMenuItem
//
this.ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem";
this.ImplementersToolStripMenuItem.Size = new System.Drawing.Size(200, 22);
this.ImplementersToolStripMenuItem.Text = "Исполнители";
this.ImplementersToolStripMenuItem.Click += new System.EventHandler(this.ImplementersToolStripMenuItem_Click);
ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem";
ImplementersToolStripMenuItem.Size = new Size(200, 22);
ImplementersToolStripMenuItem.Text = "Исполнители";
ImplementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click;
//
// отчётыToolStripMenuItem
//
this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SecuresReportToolStripMenuItem,
this.SecureFacilitiessReportToolStripMenuItem,
this.OrdersReportToolStripMenuItem});
this.отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
this.отчётыToolStripMenuItem.Size = new System.Drawing.Size(60, 20);
this.отчётыToolStripMenuItem.Text = "Отчёты";
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SecuresReportToolStripMenuItem, SecureFacilitiessReportToolStripMenuItem, OrdersReportToolStripMenuItem });
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
отчётыToolStripMenuItem.Size = new Size(60, 20);
отчётыToolStripMenuItem.Text = "Отчёты";
//
// SecuresReportToolStripMenuItem
//
this.SecuresReportToolStripMenuItem.Name = "SecuresReportToolStripMenuItem";
this.SecuresReportToolStripMenuItem.Size = new System.Drawing.Size(236, 22);
this.SecuresReportToolStripMenuItem.Text = "Список систем безопасности";
this.SecuresReportToolStripMenuItem.Click += new System.EventHandler(this.SecuresReportToolStripMenuItem_Click);
SecuresReportToolStripMenuItem.Name = "SecuresReportToolStripMenuItem";
SecuresReportToolStripMenuItem.Size = new Size(236, 22);
SecuresReportToolStripMenuItem.Text = "Список систем безопасности";
SecuresReportToolStripMenuItem.Click += SecuresReportToolStripMenuItem_Click;
//
// SecureFacilitiessReportToolStripMenuItem
//
this.SecureFacilitiessReportToolStripMenuItem.Name = "SecureFacilitiessReportToolStripMenuItem";
this.SecureFacilitiessReportToolStripMenuItem.Size = new System.Drawing.Size(236, 22);
this.SecureFacilitiessReportToolStripMenuItem.Text = "Оборудование по СБ";
this.SecureFacilitiessReportToolStripMenuItem.Click += new System.EventHandler(this.SecureFacilitiessReportToolStripMenuItem_Click);
SecureFacilitiessReportToolStripMenuItem.Name = "SecureFacilitiessReportToolStripMenuItem";
SecureFacilitiessReportToolStripMenuItem.Size = new Size(236, 22);
SecureFacilitiessReportToolStripMenuItem.Text = "Оборудование по СБ";
SecureFacilitiessReportToolStripMenuItem.Click += SecureFacilitiessReportToolStripMenuItem_Click;
//
// OrdersReportToolStripMenuItem
//
this.OrdersReportToolStripMenuItem.Name = "OrdersReportToolStripMenuItem";
this.OrdersReportToolStripMenuItem.Size = new System.Drawing.Size(236, 22);
this.OrdersReportToolStripMenuItem.Text = "Список заказов";
this.OrdersReportToolStripMenuItem.Click += new System.EventHandler(this.OrdersReportToolStripMenuItem_Click);
OrdersReportToolStripMenuItem.Name = "OrdersReportToolStripMenuItem";
OrdersReportToolStripMenuItem.Size = new Size(236, 22);
OrdersReportToolStripMenuItem.Text = "Список заказов";
OrdersReportToolStripMenuItem.Click += OrdersReportToolStripMenuItem_Click;
//
// StartWorkingToolStripMenuItem
//
this.StartWorkingToolStripMenuItem.Name = "StartWorkingToolStripMenuItem";
this.StartWorkingToolStripMenuItem.Size = new System.Drawing.Size(92, 20);
this.StartWorkingToolStripMenuItem.Text = "Запуск работ";
this.StartWorkingToolStripMenuItem.Click += new System.EventHandler(this.StartWorkingToolStripMenuItem_Click);
StartWorkingToolStripMenuItem.Name = "StartWorkingToolStripMenuItem";
StartWorkingToolStripMenuItem.Size = new Size(92, 20);
StartWorkingToolStripMenuItem.Text = "Запуск работ";
StartWorkingToolStripMenuItem.Click += StartWorkingToolStripMenuItem_Click;
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 26);
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(957, 305);
this.dataGridView.TabIndex = 1;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 26);
dataGridView.Margin = new Padding(3, 2, 3, 2);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(957, 305);
dataGridView.TabIndex = 1;
//
// buttonCreateOrder
//
this.buttonCreateOrder.Location = new System.Drawing.Point(975, 34);
this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(170, 22);
this.buttonCreateOrder.TabIndex = 2;
this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreateOrder.UseVisualStyleBackColor = true;
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
buttonCreateOrder.Location = new Point(975, 34);
buttonCreateOrder.Margin = new Padding(3, 2, 3, 2);
buttonCreateOrder.Name = "buttonCreateOrder";
buttonCreateOrder.Size = new Size(170, 22);
buttonCreateOrder.TabIndex = 2;
buttonCreateOrder.Text = "Создать заказ";
buttonCreateOrder.UseVisualStyleBackColor = true;
buttonCreateOrder.Click += ButtonCreateOrder_Click;
//
// buttonTakeOrderInWork
//
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(975, 60);
this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(170, 22);
this.buttonTakeOrderInWork.TabIndex = 3;
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
buttonTakeOrderInWork.Location = new Point(975, 60);
buttonTakeOrderInWork.Margin = new Padding(3, 2, 3, 2);
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
buttonTakeOrderInWork.Size = new Size(170, 22);
buttonTakeOrderInWork.TabIndex = 3;
buttonTakeOrderInWork.Text = "Отдать на выполнение";
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
//
// buttonOrderReady
//
this.buttonOrderReady.Location = new System.Drawing.Point(975, 86);
this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonOrderReady.Name = "buttonOrderReady";
this.buttonOrderReady.Size = new System.Drawing.Size(170, 22);
this.buttonOrderReady.TabIndex = 4;
this.buttonOrderReady.Text = "Заказ готов";
this.buttonOrderReady.UseVisualStyleBackColor = true;
this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
buttonOrderReady.Location = new Point(975, 86);
buttonOrderReady.Margin = new Padding(3, 2, 3, 2);
buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(170, 22);
buttonOrderReady.TabIndex = 4;
buttonOrderReady.Text = "Заказ готов";
buttonOrderReady.UseVisualStyleBackColor = true;
buttonOrderReady.Click += ButtonOrderReady_Click;
//
// buttonIssuedOrder
//
this.buttonIssuedOrder.Location = new System.Drawing.Point(975, 112);
this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
this.buttonIssuedOrder.Size = new System.Drawing.Size(170, 22);
this.buttonIssuedOrder.TabIndex = 5;
this.buttonIssuedOrder.Text = "Заказ выдан";
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
buttonIssuedOrder.Location = new Point(975, 112);
buttonIssuedOrder.Margin = new Padding(3, 2, 3, 2);
buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(170, 22);
buttonIssuedOrder.TabIndex = 5;
buttonIssuedOrder.Text = "Заказ выдан";
buttonIssuedOrder.UseVisualStyleBackColor = true;
buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(975, 138);
this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(170, 22);
this.buttonRef.TabIndex = 6;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
buttonRef.Location = new Point(975, 138);
buttonRef.Margin = new Padding(3, 2, 3, 2);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(170, 22);
buttonRef.TabIndex = 6;
buttonRef.Text = "Обновить";
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
// сообщенияToolStripMenuItem
//
сообщенияToolStripMenuItem.Name = "сообщенияToolStripMenuItem";
сообщенияToolStripMenuItem.Size = new Size(85, 20);
сообщенияToolStripMenuItem.Text = "Сообщения";
сообщенияToolStripMenuItem.Click += сообщенияToolStripMenuItem_Click;
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1149, 338);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonIssuedOrder);
this.Controls.Add(this.buttonOrderReady);
this.Controls.Add(this.buttonTakeOrderInWork);
this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip;
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormMain";
this.Text = "Магазин систем безопасности";
this.Load += new System.EventHandler(this.FormMain_Load);
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1149, 338);
Controls.Add(buttonRef);
Controls.Add(buttonIssuedOrder);
Controls.Add(buttonOrderReady);
Controls.Add(buttonTakeOrderInWork);
Controls.Add(buttonCreateOrder);
Controls.Add(dataGridView);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Margin = new Padding(3, 2, 3, 2);
Name = "FormMain";
Text = "Магазин систем безопасности";
Load += FormMain_Load;
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
@ -250,5 +247,6 @@
private ToolStripMenuItem ClientsToolStripMenuItem;
private ToolStripMenuItem ImplementersToolStripMenuItem;
private ToolStripMenuItem StartWorkingToolStripMenuItem;
private ToolStripMenuItem сообщенияToolStripMenuItem;
}
}

View File

@ -2,6 +2,7 @@
using SecureShopContracts.BindingModels;
using SecureShopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using SecureShopView;
namespace SecureShopView
{
@ -214,5 +215,14 @@ namespace SecureShopView
_workProcessLogic.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(FormMessages));
if (service is FormMessages form)
{
form.ShowDialog();
}
}
}
}

View File

@ -0,0 +1,61 @@
namespace SecureShopView
{
partial class FormMessages
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
dataGridView = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 12);
dataGridView.Name = "dataGridView";
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(776, 426);
dataGridView.TabIndex = 0;
//
// FormMessages
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(dataGridView);
Name = "FormMessages";
Text = "Сообщения";
Load += FormMessages_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,53 @@
using SecureShopContracts.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 SecureShopView
{
public partial class FormMessages : Form
{
private readonly ILogger _logger;
private readonly IMessageInfoLogic _logic;
public FormMessages(ILogger<FormSecures> logger, IMessageInfoLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormMessages_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.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
}
_logger.LogInformation("Загрузка сообщений");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки сообщений");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,4 +1,4 @@
using SecureShopBusinessLogic.BusinessLogics;
using SecureShopBusinessLogic.BusinessLogics;
using SecureShopContracts.BusinessLogicsContracts;
using SecureShopContracts.StoragesContracts;
using Microsoft.Extensions.DependencyInjection;
@ -7,7 +7,9 @@ using NLog.Extensions.Logging;
using SecureShopBusinessLogic.OfficePackage;
using SecureShopBusinessLogic.OfficePackage.Implements;
using SecureShopDatabaseImplement.Implements;
using SecureShopView;
using SecureShopBusinessLogic.MailWorker;
using SecureShopContracts.BindingModels;
namespace SecureShopView
{
@ -27,6 +29,25 @@ namespace SecureShopView
var services = new ServiceCollection();
ConfigureServices(services);
_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>());
}
private static void ConfigureServices(ServiceCollection services)
@ -40,11 +61,16 @@ namespace SecureShopView
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<ISecureStorage, SecureStorage>();
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
services.AddTransient<IFacilitiesLogic, FacilitiesLogic>();
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ISecureLogic, SecureLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<FormMessages>();
services.AddTransient<FormMain>();
services.AddTransient<IImplementerStorage, ImplementerStorage>();
services.AddTransient<IReportLogic, ReportLogic>();
@ -64,6 +90,6 @@ namespace SecureShopView
services.AddTransient<FormSecures>();
services.AddTransient<FormClients>();
}
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
}
}

View File

@ -9,13 +9,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.0" />
<PackageReference Include="ReportViewerCore.WinForms" Version="15.1.17" />
</ItemGroup>
@ -32,5 +32,10 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Update="App.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -4,6 +4,7 @@ using SecureShopContracts.SearchModels;
using SecureShopContracts.StoragesContracts;
using SecureShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
namespace SecureShopBusinessLogic.BusinessLogics
{
@ -96,8 +97,17 @@ namespace SecureShopBusinessLogic.BusinessLogics
{
throw new ArgumentNullException("Нет имени клиента", nameof(model.ClientFIO));
}
_logger.LogInformation("Client. ClientFIO:{ClientFIO}. Id: {Id}", model.ClientFIO, model.Id);
var element = _clientStorage.GetElement(new ClientSearchModel
if (!Regex.IsMatch(model.Email, @"^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
@"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$", RegexOptions.IgnoreCase))
{
throw new ArgumentException("Некорректная почта, сынок", nameof(model.Email));
}
if (!Regex.IsMatch(model.Password, @"^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$", RegexOptions.IgnoreCase) || model.Password.Length < 10 || model.Password.Length > 50)
{
throw new ArgumentException("Думай лучше. Плохой пароль", nameof(model.Password));
}
_logger.LogInformation("Client. ClientFIO:{ClientFIO}. Id: {Id}", model.ClientFIO, model.Id);
var element = _clientStorage.GetElement(new ClientSearchModel
{
Email = model.Email
});

View File

@ -3,6 +3,7 @@ using SecureShopContracts.BusinessLogicsContracts;
using SecureShopContracts.SearchModels;
using SecureShopContracts.StoragesContracts;
using SecureShopContracts.ViewModels;
using SecureShopBusinessLogic.MailWorker;
using SecureShopDataModels.Enums;
using Microsoft.Extensions.Logging;
@ -12,11 +13,15 @@ namespace SecureShopBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
private readonly AbstractMailWorker _abstractMailWorker;
private readonly IClientStorage _clientStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, AbstractMailWorker abstractMailWorker, IClientStorage clientStorage)
{
_logger = logger;
_orderStorage = orderStorage;
_abstractMailWorker = abstractMailWorker;
_clientStorage = clientStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
@ -66,11 +71,19 @@ namespace SecureShopBusinessLogic.BusinessLogics
return false;
}
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
var order = _orderStorage.Insert(model);
if (order == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
var client = _clientStorage.GetElement(new() { Id = order.ClientId });
if (client == null)
{
_logger.LogWarning("Client not found");
return false;
}
SendMail(client.Email, $"Новый заказ создан. Номер заказа - {order.Id}", $"Заказ №{order.Id} от {order.DateCreate} на сумму {order.Sum:C2} принят.");
return true;
}
@ -104,11 +117,19 @@ namespace SecureShopBusinessLogic.BusinessLogics
model.DateImplement = viewModel.DateImplement;
}
CheckModel(model);
if (_orderStorage.Update(model) == null)
var order = _orderStorage.Update(model);
if (order == null)
{
_logger.LogWarning("Change status operation failed");
return false;
}
var client = _clientStorage.GetElement(new() { Id = order.ClientId });
if (client == null)
{
_logger.LogWarning("Client not found");
return false;
}
SendMail(client.Email, $"Заказ №{order.Id}", $"Заказ №{order.Id} изменил статус на {order.Status}.");
return true;
}
@ -128,6 +149,15 @@ namespace SecureShopBusinessLogic.BusinessLogics
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public void SendMail(string email, string title, string body)
{
_abstractMailWorker.MailSendAsync(new()
{
MailAddress = email,
Subject = title,
Text = body
});
}
public bool TakeOrderInWork(OrderBindingModel model)
{

View File

@ -0,0 +1,95 @@
using SecureShopContracts.BindingModels;
using SecureShopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace SecureShopBusinessLogic.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;
private readonly IClientLogic _clientLogic;
public AbstractMailWorker(ILogger<AbstractMailWorker> logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic)
{
_logger = logger;
_messageInfoLogic = messageInfoLogic;
_clientLogic = clientLogic;
}
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)
{
mail.ClientId = _clientLogic.ReadElement(new() { Email = mail.SenderName })?.Id;
_messageInfoLogic.Create(mail);
}
}
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
protected abstract Task<List<MessageInfoBindingModel>> ReceiveMailAsync();
}
}

View File

@ -0,0 +1,78 @@
using SecureShopContracts.BindingModels;
using SecureShopContracts.BusinessLogicsContracts;
using MailKit.Net.Pop3;
using MailKit.Security;
using Microsoft.Extensions.Logging;
using System.Net;
using System.Net.Mail;
using System.Text;
namespace SecureShopBusinessLogic.MailWorker
{
public class MailKitWorker : AbstractMailWorker
{
public MailKitWorker(ILogger<MailKitWorker> logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) : base(logger, messageInfoLogic, clientLogic) { }
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<List<MessageInfoBindingModel>> ReceiveMailAsync()
{
var list = new List<MessageInfoBindingModel>();
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)
{
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;
}
}
}

View File

@ -8,7 +8,8 @@
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="MailKit" Version="4.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
</ItemGroup>

View File

@ -6,7 +6,7 @@ using System.Diagnostics;
namespace SecureShopClientApp.Controllers
{
public class HomeController : Controller
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
@ -143,5 +143,14 @@ namespace SecureShopClientApp.Controllers
var iceCr = APIClient.GetRequest<SecureViewModel>($"api/main/getsecure?secureId={secure}");
return count * (iceCr?.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}"));
}
}
}

View File

@ -0,0 +1,54 @@
@using SecureShopContracts.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>

View File

@ -25,6 +25,9 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
</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">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
</li>

View File

@ -0,0 +1,17 @@
namespace SecureShopContracts.BindingModels
{
public class MailConfigBindingModel
{
public string MailLogin { get; set; } = string.Empty;
public string MailPassword { get; set; } = string.Empty;
public string SmtpClientHost { get; set; } = string.Empty;
public int SmtpClientPort { get; set; }
public string PopHost { get; set; } = string.Empty;
public int PopPort { get; set; }
}
}

View File

@ -0,0 +1,11 @@
namespace SecureShopContracts.BindingModels
{
public class MailSendInfoBindingModel
{
public string MailAddress { get; set; } = string.Empty;
public string Subject { get; set; } = string.Empty;
public string Text { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,19 @@
using SecureShopDataModels.Models;
namespace SecureShopContracts.BindingModels
{
public class MessageInfoBindingModel : IMessageInfoModel
{
public string MessageId { get; set; } = string.Empty;
public int? ClientId { get; set; }
public string SenderName { get; set; } = string.Empty;
public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
public DateTime DateDelivery { get; set; }
}
}

View File

@ -0,0 +1,44 @@
using Microsoft.Extensions.Logging;
using SecureShopContracts.BindingModels;
using SecureShopContracts.BusinessLogicsContracts;
using SecureShopContracts.SearchModels;
using SecureShopContracts.StoragesContracts;
using SecureShopContracts.ViewModels;
namespace SecureShopBusinessLogic.BusinessLogics
{
public class MessageInfoLogic : IMessageInfoLogic
{
private readonly ILogger _logger;
private readonly IMessageInfoStorage _messageInfoStorage;
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageInfoStorage)
{
_logger = logger;
_messageInfoStorage = messageInfoStorage;
}
public bool Create(MessageInfoBindingModel model)
{
if (_messageInfoStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
{
_logger.LogInformation("ReadList. MessageId:{MessageId}", model?.MessageId);
var list = model == null ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list.OrderByDescending(x => x.DateDelivery).ToList();
}
}
}

View File

@ -0,0 +1,13 @@
using SecureShopContracts.BindingModels;
using SecureShopContracts.SearchModels;
using SecureShopContracts.ViewModels;
namespace SecureShopContracts.BusinessLogicsContracts
{
public interface IMessageInfoLogic
{
List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
bool Create(MessageInfoBindingModel model);
}
}

View File

@ -0,0 +1,9 @@
namespace SecureShopContracts.SearchModels
{
public class MessageInfoSearchModel
{
public int? ClientId { get; set; }
public string? MessageId { get; set; }
}
}

View File

@ -6,6 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SecureShopDataModels\SecureShopDataModels.csproj" />
</ItemGroup>

View File

@ -0,0 +1,17 @@
using SecureShopContracts.BindingModels;
using SecureShopContracts.SearchModels;
using SecureShopContracts.ViewModels;
namespace SecureShopContracts.StoragesContracts
{
public interface IMessageInfoStorage
{
List<MessageInfoViewModel> GetFullList();
List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model);
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
MessageInfoViewModel? Insert(MessageInfoBindingModel model);
}
}

View File

@ -0,0 +1,24 @@
using SecureShopDataModels.Models;
using System.ComponentModel;
namespace SecureShopContracts.ViewModels
{
public class MessageInfoViewModel : IMessageInfoModel
{
public string MessageId { get; set; } = string.Empty;
public int? ClientId { get; set; }
[DisplayName("Отправитель")]
public string SenderName { get; set; } = string.Empty;
[DisplayName("Дата письма")]
public DateTime DateDelivery { get; set; }
[DisplayName("Заголовок")]
public string Subject { get; set; } = string.Empty;
[DisplayName("Текст")]
public string Body { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,17 @@
namespace SecureShopDataModels.Models
{
public interface IMessageInfoModel
{
string MessageId { get; }
int? ClientId { get; }
string SenderName { get; }
DateTime DateDelivery { get; }
string Subject { get; }
string Body { get; }
}
}

View File

@ -0,0 +1,49 @@
using SecureShopContracts.BindingModels;
using SecureShopContracts.SearchModels;
using SecureShopContracts.StoragesContracts;
using SecureShopContracts.ViewModels;
using SecureShopDatabaseImplement.Models;
namespace SecureShopDatabaseImplement.Implements
{
public class MessageInfoStorage : IMessageInfoStorage
{
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
{
using var context = new SecureShopDatabase();
return context.MessageInfos
.FirstOrDefault(x => !string.IsNullOrEmpty(x.MessageId) && x.MessageId == model.MessageId)
?.GetViewModel;
}
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
{
using var context = new SecureShopDatabase();
return context.MessageInfos
.Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
public List<MessageInfoViewModel> GetFullList()
{
using var context = new SecureShopDatabase();
return context.MessageInfos
.Select(x => x.GetViewModel)
.ToList();
}
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
{
using var context = new SecureShopDatabase();
var newMessage = MessageInfo.Create(model);
if (newMessage == null)
{
return null;
}
context.MessageInfos.Add(newMessage);
context.SaveChanges();
return newMessage.GetViewModel;
}
}
}

View File

@ -18,8 +18,9 @@ namespace SecureShopDatabaseImplement.Models
[ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new();
public static Client? Create(ClientBindingModel model)
[ForeignKey("ClientId")]
public virtual List<MessageInfo> MessageInfos { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
if (model == null)
{

View File

@ -0,0 +1,52 @@
using SecureShopContracts.BindingModels;
using SecureShopContracts.ViewModels;
using SecureShopDataModels.Models;
using System.ComponentModel.DataAnnotations;
namespace SecureShopDatabaseImplement.Models
{
public class MessageInfo : IMessageInfoModel
{
[Key]
public string MessageId { get; set; } = string.Empty;
public int? ClientId { get; set; }
[Required]
public string SenderName { get; set; } = string.Empty;
[Required]
public DateTime DateDelivery { get; set; } = DateTime.Now;
[Required]
public string Subject { get; set; } = string.Empty;
[Required]
public string Body { get; set; } = string.Empty;
public virtual Client? Client { get; set; }
public static MessageInfo? Create(MessageInfoBindingModel? model)
{
if (model == null)
{
return null;
}
return new MessageInfo()
{
MessageId = model.MessageId,
ClientId = model.ClientId,
SenderName = model.SenderName,
DateDelivery = model.DateDelivery,
Subject = model.Subject,
Body = model.Body
};
}
public MessageInfoViewModel GetViewModel => new()
{
MessageId = MessageId,
ClientId = ClientId,
SenderName = SenderName,
DateDelivery = DateDelivery,
Subject = Subject,
Body = Body
};
}
}

View File

@ -25,5 +25,7 @@ namespace SecureShopDatabaseImplement
public virtual DbSet<Client> Clients { set; get; }
public virtual DbSet<Implementer> Implementers { set; get; }
public virtual DbSet<MessageInfo> MessageInfos { set; get; }
}
}

View File

@ -7,9 +7,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

View File

@ -11,9 +11,11 @@ namespace SecureShopFileImplement
private readonly string SecureFileName = "Secure.xml";
public List<Facilities> Facilitiess { get; private set; }
private readonly string ClientFileName = "Client.xml";
private readonly string MessageInfoFileName = "MessageInfo.xml";
public List<Order> Orders { get; private set; }
public List<Secure> Secures { get; private set; }
public List<Client> Clients { get; private set; }
public List<MessageInfo> MessageInfos { get; private set; }
public static DataFileSingleton GetInstance()
{
@ -28,12 +30,15 @@ namespace SecureShopFileImplement
public void SaveSecures() => SaveData(Secures, SecureFileName, "Secures", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
public void SaveMessageInfos() => SaveData(MessageInfos, MessageInfoFileName, "MessageInfos", x => x.GetXElement);
private DataFileSingleton()
{
Facilitiess = LoadData(FacilitiesFileName, "Facilities", x => Facilities.Create(x)!)!;
Secures = LoadData(SecureFileName, "Secure", x => Secure.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
MessageInfos = LoadData(MessageInfoFileName, "MessageInfo", x => MessageInfo.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{

View File

@ -0,0 +1,57 @@
using SecureShopContracts.BindingModels;
using SecureShopContracts.SearchModels;
using SecureShopContracts.StoragesContracts;
using SecureShopContracts.ViewModels;
using SecureShopFileImplement.Models;
namespace SecureShopFileImplement.Implements
{
public class MessageInfoStorage : IMessageInfoStorage
{
private readonly DataFileSingleton _source;
public MessageInfoStorage()
{
_source = DataFileSingleton.GetInstance();
}
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
{
if (!string.IsNullOrEmpty(model.MessageId))
{
return _source.MessageInfos
.FirstOrDefault(x => x.MessageId == model.MessageId)
?.GetViewModel;
}
return null;
}
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
{
if (model.ClientId.HasValue)
{
return _source.MessageInfos
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<MessageInfoViewModel> GetFullList()
{
return _source.MessageInfos.Select(x => x.GetViewModel).ToList();
}
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
{
var newMessage = MessageInfo.Create(model);
if (newMessage == null)
{
return null;
}
_source.MessageInfos.Add(newMessage);
_source.SaveClients();
return newMessage.GetViewModel;
}
}
}

View File

@ -26,6 +26,10 @@ namespace SecureShopFileImplement.Implements
{
return _source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => GetViewModel(x)).ToList();
}
if (model.Status.HasValue)
{
return _source.Orders.Where(x => x.Status == model.Status).Select(x => GetViewModel(x)).ToList();
}
if (!model.Id.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
{
return _source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
@ -36,6 +40,14 @@ namespace SecureShopFileImplement.Implements
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (model.ImplementerId.HasValue && model.Status.HasValue)
{
return _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.Status)?.GetViewModel;
}
if (model.ImplementerId.HasValue)
{
return _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel;
}
if (!model.Id.HasValue)
{
return null;

View File

@ -0,0 +1,67 @@
using SecureShopContracts.BindingModels;
using SecureShopContracts.ViewModels;
using SecureShopDataModels.Models;
using System.Xml.Linq;
namespace SecureShopFileImplement.Models
{
public class MessageInfo : IMessageInfoModel
{
public string MessageId { get; set; } = string.Empty;
public int? ClientId { get; set; }
public string SenderName { get; set; } = string.Empty;
public DateTime DateDelivery { get; set; } = DateTime.Now;
public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
public static MessageInfo? Create(MessageInfoBindingModel model)
{
if (model == null)
{
return null;
}
return new MessageInfo()
{
MessageId = model.MessageId,
ClientId = model.ClientId,
SenderName = model.SenderName,
DateDelivery = model.DateDelivery,
Subject = model.Subject,
Body = model.Body
};
}
public static MessageInfo? Create(XElement element)
{
if (element == null)
{
return null;
}
return new MessageInfo()
{
MessageId = element.Element("MessageId")!.Value,
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
SenderName = element.Element("MessageId")!.Value,
DateDelivery = DateTime.ParseExact(element.Element("DateDelivery")!.Value, "G", null),
Subject = element.Element("MessageId")!.Value,
Body = element.Element("MessageId")!.Value
};
}
public MessageInfoViewModel GetViewModel => new()
{
MessageId = MessageId,
ClientId = ClientId,
SenderName = SenderName,
DateDelivery = DateDelivery,
Subject = Subject,
Body = Body
};
public XElement GetXElement => new("MessageInfo", new XAttribute("MessageId", MessageId), new XElement("ClientId", ClientId), new XElement("SenderName", SenderName), new XElement("DateDelivery", DateDelivery), new XElement("Subject", Subject), new XElement("Body", Body));
}
}

View File

@ -10,6 +10,7 @@ namespace SecureShopListImplement
public List<Secure> Secures { get; set; }
public List<Client> Clients { get; set; }
public List<Implementer> Implementers { get; set; }
public List<MessageInfo> MessageInfos { get; set; }
private DataListSingleton()
{
@ -17,6 +18,7 @@ namespace SecureShopListImplement
Orders = new List<Order>();
Secures = new List<Secure>();
Clients = new List<Client>();
MessageInfos = new();
Implementers = new();
}

View File

@ -0,0 +1,65 @@
using SecureShopContracts.BindingModels;
using SecureShopContracts.SearchModels;
using SecureShopContracts.StoragesContracts;
using SecureShopContracts.ViewModels;
using SecureShopListImplement.Models;
namespace SecureShopListImplement.Implements
{
public class MessageInfoStorage : IMessageInfoStorage
{
private readonly DataListSingleton _source;
public MessageInfoStorage()
{
_source = DataListSingleton.GetInstance();
}
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
{
foreach (var elem in _source.MessageInfos)
{
if (!string.IsNullOrEmpty(model.MessageId) && model.MessageId == elem.MessageId)
return elem.GetViewModel;
}
return null;
}
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
{
var result = new List<MessageInfoViewModel>();
if (model.ClientId.HasValue)
{
foreach (var message in _source.MessageInfos)
{
if (message.ClientId.HasValue && message.ClientId == model.ClientId)
{
result.Add(message.GetViewModel);
}
}
}
return result;
}
public List<MessageInfoViewModel> GetFullList()
{
var result = new List<MessageInfoViewModel>();
foreach (var message in _source.MessageInfos)
{
result.Add(message.GetViewModel);
}
return result;
}
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
{
var newMessage = MessageInfo.Create(model);
if (newMessage == null)
{
return null;
}
_source.MessageInfos.Add(newMessage);
return newMessage.GetViewModel;
}
}
}

View File

@ -39,6 +39,17 @@ namespace SecureShopListImplement.Implements
}
return result;
}
if (model.Status.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.Status == model.Status)
{
result.Add(GetViewModel(order));
}
}
return result;
}
if (!model.Id.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
{
foreach (var order in _source.Orders)

View File

@ -0,0 +1,47 @@
using SecureShopContracts.BindingModels;
using SecureShopContracts.ViewModels;
using SecureShopDataModels.Models;
namespace SecureShopListImplement.Models
{
public class MessageInfo : IMessageInfoModel
{
public string MessageId { get; private set; } = string.Empty;
public int? ClientId { get; private set; }
public string SenderName { get; private set; } = string.Empty;
public DateTime DateDelivery { get; private set; } = DateTime.Now;
public string Subject { get; private set; } = string.Empty;
public string Body { get; private set; } = string.Empty;
public static MessageInfo? Create(MessageInfoBindingModel? model)
{
if (model == null)
{
return null;
}
return new MessageInfo()
{
MessageId = model.MessageId,
ClientId = model.ClientId,
SenderName = model.SenderName,
DateDelivery = model.DateDelivery,
Subject = model.Subject,
Body = model.Body
};
}
public MessageInfoViewModel GetViewModel => new()
{
MessageId = MessageId,
ClientId = ClientId,
SenderName = SenderName,
DateDelivery = DateDelivery,
Subject = Subject,
Body = Body
};
}
}

View File

@ -14,10 +14,13 @@ namespace SecureShopRestApi.Controllers
private readonly IClientLogic _logic;
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
private readonly IMessageInfoLogic _mailLogic;
public ClientController(IClientLogic logic, ILogger<ClientController> logger, IMessageInfoLogic mailLogic)
{
_logger = logger;
_logic = logic;
_mailLogic = mailLogic;
}
[HttpGet]
@ -38,6 +41,23 @@ namespace SecureShopRestApi.Controllers
}
}
[HttpGet]
public List<MessageInfoViewModel>? GetMessages(int clientId)
{
try
{
return _mailLogic.ReadList(new MessageInfoSearchModel
{
ClientId = clientId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения писем клиента");
throw;
}
}
[HttpPost]
public void Register(ClientBindingModel model)
{

View File

@ -1,4 +1,6 @@
using SecureShopBusinessLogic.BusinessLogics;
using SecureShopBusinessLogic.MailWorker;
using SecureShopContracts.BindingModels;
using SecureShopContracts.BusinessLogicsContracts;
using SecureShopContracts.StoragesContracts;
using SecureShopDatabaseImplement.Implements;
@ -13,11 +15,15 @@ builder.Services.AddTransient<IClientStorage, ClientStorage>();
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
builder.Services.AddTransient<ISecureStorage, SecureStorage>();
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
builder.Services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
builder.Services.AddTransient<IClientLogic, ClientLogic>();
builder.Services.AddTransient<ISecureLogic, SecureLogic>();
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
@ -29,6 +35,17 @@ builder.Services.AddSwaggerGen(c =>
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.
if (app.Environment.IsDevelopment())
{

View File

@ -8,7 +8,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
<ItemGroup>

View File

@ -5,5 +5,11 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"SmtpClientHost": "smtp.gmail.com",
"SmtpClientPort": "587",
"PopHost": "pop.gmail.com",
"PopPort": "995",
"MailLogin": "vertolet.kirill73@gmail.com",
"MailPassword": "xehc ozzy jxqa gtvt"
}