diff --git a/SecuritySystem/FormClients.Designer.cs b/SecuritySystem/FormClients.Designer.cs
new file mode 100644
index 0000000..d239091
--- /dev/null
+++ b/SecuritySystem/FormClients.Designer.cs
@@ -0,0 +1,94 @@
+namespace SecuritySystemView
+{
+ partial class FormClients
+ {
+ ///
+ /// 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();
+ this.buttonDel = new System.Windows.Forms.Button();
+ this.buttonRef = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.AllowUserToAddRows = false;
+ this.dataGridView.AllowUserToDeleteRows = false;
+ this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
+ this.dataGridView.Location = new System.Drawing.Point(0, 0);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.ReadOnly = true;
+ this.dataGridView.RowHeadersVisible = false;
+ this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
+ this.dataGridView.Size = new System.Drawing.Size(350, 312);
+ this.dataGridView.TabIndex = 0;
+ //
+ // buttonDel
+ //
+ this.buttonDel.Location = new System.Drawing.Point(368, 12);
+ this.buttonDel.Name = "buttonDel";
+ this.buttonDel.Size = new System.Drawing.Size(75, 23);
+ this.buttonDel.TabIndex = 3;
+ this.buttonDel.Text = "Удалить";
+ this.buttonDel.UseVisualStyleBackColor = true;
+ this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(368, 53);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(75, 23);
+ this.buttonRef.TabIndex = 4;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // FormClients
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(464, 312);
+ this.Controls.Add(this.buttonRef);
+ this.Controls.Add(this.buttonDel);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormClients";
+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+ this.Text = "Клиенты";
+ this.Load += new System.EventHandler(this.FormClients_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+ private System.Windows.Forms.DataGridView dataGridView;
+ private System.Windows.Forms.Button buttonDel;
+ private System.Windows.Forms.Button buttonRef;
+ }
+}
\ No newline at end of file
diff --git a/SecuritySystem/FormClients.cs b/SecuritySystem/FormClients.cs
new file mode 100644
index 0000000..93664f0
--- /dev/null
+++ b/SecuritySystem/FormClients.cs
@@ -0,0 +1,78 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.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 SecuritySystemView
+{
+ public partial class FormClients : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IClientLogic _logic;
+ public FormClients(ILogger logger, IClientLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void FormClients_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ private void LoadData()
+ {
+ try
+ {
+ var list = _logic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["Id"].Visible = false;
+ dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ }
+ _logger.LogInformation("Загрузка клиентов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки клиентов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonDel_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ try
+ {
+ if (!_logic.Delete(new ClientBindingModel { Id = id }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ _logger.LogInformation("Удаление клиента");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления клиента");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ LoadData();
+ }
+ }
+ }
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/SecuritySystem/FormReportManufactureComponents.resx b/SecuritySystem/FormClients.resx
similarity index 100%
rename from SecuritySystem/FormReportManufactureComponents.resx
rename to SecuritySystem/FormClients.resx
diff --git a/SecuritySystem/FormCreateOrder.Designer.cs b/SecuritySystem/FormCreateOrder.Designer.cs
index ba1b6eb..41df3bb 100644
--- a/SecuritySystem/FormCreateOrder.Designer.cs
+++ b/SecuritySystem/FormCreateOrder.Designer.cs
@@ -28,107 +28,133 @@
///
private void InitializeComponent()
{
- this.labelSecure = new System.Windows.Forms.Label();
- this.comboBoxSecure = new System.Windows.Forms.ComboBox();
- this.labelCount = new System.Windows.Forms.Label();
- this.textBoxCount = new System.Windows.Forms.TextBox();
- this.labelSum = new System.Windows.Forms.Label();
- this.textBoxSum = new System.Windows.Forms.TextBox();
- this.buttonCancel = new System.Windows.Forms.Button();
- this.buttonSave = new System.Windows.Forms.Button();
- this.SuspendLayout();
+ labelSecure = new Label();
+ comboBoxSecure = new ComboBox();
+ labelCount = new Label();
+ textBoxCount = new TextBox();
+ labelSum = new Label();
+ textBoxSum = new TextBox();
+ buttonCancel = new Button();
+ buttonSave = new Button();
+ labelClient = new Label();
+ comboBoxClient = new ComboBox();
+ SuspendLayout();
//
// labelSecure
//
- this.labelSecure.AutoSize = true;
- this.labelSecure.Location = new System.Drawing.Point(12, 15);
- this.labelSecure.Name = "labelSecure";
- this.labelSecure.Size = new System.Drawing.Size(75, 20);
- this.labelSecure.TabIndex = 0;
- this.labelSecure.Text = "Изделие: ";
+ labelSecure.AutoSize = true;
+ labelSecure.Location = new Point(10, 11);
+ labelSecure.Name = "labelSecure";
+ labelSecure.Size = new Size(59, 15);
+ labelSecure.TabIndex = 0;
+ labelSecure.Text = "Изделие: ";
//
// comboBoxSecure
//
- this.comboBoxSecure.FormattingEnabled = true;
- this.comboBoxSecure.Location = new System.Drawing.Point(115, 12);
- this.comboBoxSecure.Name = "comboBoxSecure";
- this.comboBoxSecure.Size = new System.Drawing.Size(358, 28);
- this.comboBoxSecure.TabIndex = 1;
- this.comboBoxSecure.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSecure_SelectedIndexChanged);
+ comboBoxSecure.FormattingEnabled = true;
+ comboBoxSecure.Location = new Point(101, 9);
+ comboBoxSecure.Margin = new Padding(3, 2, 3, 2);
+ comboBoxSecure.Name = "comboBoxSecure";
+ comboBoxSecure.Size = new Size(314, 23);
+ comboBoxSecure.TabIndex = 1;
+ comboBoxSecure.SelectedIndexChanged += ComboBoxSecure_SelectedIndexChanged;
//
// labelCount
//
- this.labelCount.AutoSize = true;
- this.labelCount.Location = new System.Drawing.Point(12, 49);
- this.labelCount.Name = "labelCount";
- this.labelCount.Size = new System.Drawing.Size(97, 20);
- this.labelCount.TabIndex = 2;
- this.labelCount.Text = "Количество: ";
+ labelCount.AutoSize = true;
+ labelCount.Location = new Point(10, 37);
+ labelCount.Name = "labelCount";
+ labelCount.Size = new Size(78, 15);
+ labelCount.TabIndex = 2;
+ labelCount.Text = "Количество: ";
//
// textBoxCount
//
- this.textBoxCount.Location = new System.Drawing.Point(115, 46);
- this.textBoxCount.Name = "textBoxCount";
- this.textBoxCount.Size = new System.Drawing.Size(358, 27);
- this.textBoxCount.TabIndex = 3;
- this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged);
+ textBoxCount.Location = new Point(101, 34);
+ textBoxCount.Margin = new Padding(3, 2, 3, 2);
+ textBoxCount.Name = "textBoxCount";
+ textBoxCount.Size = new Size(314, 23);
+ textBoxCount.TabIndex = 3;
+ textBoxCount.TextChanged += TextBoxCount_TextChanged;
//
// labelSum
//
- this.labelSum.AutoSize = true;
- this.labelSum.Location = new System.Drawing.Point(12, 80);
- this.labelSum.Name = "labelSum";
- this.labelSum.Size = new System.Drawing.Size(62, 20);
- this.labelSum.TabIndex = 4;
- this.labelSum.Text = "Сумма: ";
+ labelSum.AutoSize = true;
+ labelSum.Location = new Point(10, 63);
+ labelSum.Name = "labelSum";
+ labelSum.Size = new Size(51, 15);
+ labelSum.TabIndex = 4;
+ labelSum.Text = "Сумма: ";
//
// textBoxSum
//
- this.textBoxSum.Location = new System.Drawing.Point(115, 80);
- this.textBoxSum.Name = "textBoxSum";
- this.textBoxSum.ReadOnly = true;
- this.textBoxSum.Size = new System.Drawing.Size(358, 27);
- this.textBoxSum.TabIndex = 5;
+ textBoxSum.Location = new Point(101, 60);
+ textBoxSum.Margin = new Padding(3, 2, 3, 2);
+ textBoxSum.Name = "textBoxSum";
+ textBoxSum.ReadOnly = true;
+ textBoxSum.Size = new Size(314, 23);
+ textBoxSum.TabIndex = 5;
//
// buttonCancel
//
- this.buttonCancel.Location = new System.Drawing.Point(337, 113);
- this.buttonCancel.Name = "buttonCancel";
- this.buttonCancel.Size = new System.Drawing.Size(110, 32);
- this.buttonCancel.TabIndex = 6;
- this.buttonCancel.Text = "Отмена";
- this.buttonCancel.UseVisualStyleBackColor = true;
- this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ buttonCancel.Location = new Point(294, 126);
+ buttonCancel.Margin = new Padding(3, 2, 3, 2);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(96, 24);
+ buttonCancel.TabIndex = 6;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += ButtonCancel_Click;
//
// buttonSave
//
- this.buttonSave.Location = new System.Drawing.Point(221, 113);
- this.buttonSave.Name = "buttonSave";
- this.buttonSave.Size = new System.Drawing.Size(110, 32);
- this.buttonSave.TabIndex = 7;
- this.buttonSave.Text = "Сохранить";
- this.buttonSave.UseVisualStyleBackColor = true;
- this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ buttonSave.Location = new Point(192, 126);
+ buttonSave.Margin = new Padding(3, 2, 3, 2);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(96, 24);
+ buttonSave.TabIndex = 7;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += ButtonSave_Click;
+ //
+ // labelClient
+ //
+ labelClient.AutoSize = true;
+ labelClient.Location = new Point(10, 91);
+ labelClient.Name = "labelClient";
+ labelClient.Size = new Size(49, 15);
+ labelClient.TabIndex = 8;
+ labelClient.Text = "Клиент:";
+ //
+ // comboBoxClient
+ //
+ comboBoxClient.FormattingEnabled = true;
+ comboBoxClient.Location = new Point(101, 88);
+ comboBoxClient.Name = "comboBoxClient";
+ comboBoxClient.Size = new Size(314, 23);
+ comboBoxClient.TabIndex = 9;
//
// FormCreateOrder
//
- this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(485, 158);
- this.Controls.Add(this.buttonSave);
- this.Controls.Add(this.buttonCancel);
- this.Controls.Add(this.textBoxSum);
- this.Controls.Add(this.labelSum);
- this.Controls.Add(this.textBoxCount);
- this.Controls.Add(this.labelCount);
- this.Controls.Add(this.comboBoxSecure);
- this.Controls.Add(this.labelSecure);
- this.Name = "FormCreateOrder";
- this.Text = "Заказ";
- this.Load += new System.EventHandler(this.FormCreateOrder_Load);
- this.ResumeLayout(false);
- this.PerformLayout();
-
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(424, 161);
+ Controls.Add(comboBoxClient);
+ Controls.Add(labelClient);
+ Controls.Add(buttonSave);
+ Controls.Add(buttonCancel);
+ Controls.Add(textBoxSum);
+ Controls.Add(labelSum);
+ Controls.Add(textBoxCount);
+ Controls.Add(labelCount);
+ Controls.Add(comboBoxSecure);
+ Controls.Add(labelSecure);
+ Margin = new Padding(3, 2, 3, 2);
+ Name = "FormCreateOrder";
+ Text = "Заказ";
+ Load += FormCreateOrder_Load;
+ ResumeLayout(false);
+ PerformLayout();
}
#endregion
@@ -141,5 +167,7 @@
private TextBox textBoxSum;
private Button buttonCancel;
private Button buttonSave;
+ private Label labelClient;
+ private ComboBox comboBoxClient;
}
}
\ No newline at end of file
diff --git a/SecuritySystem/FormCreateOrder.cs b/SecuritySystem/FormCreateOrder.cs
index 4af9c06..16ab678 100644
--- a/SecuritySystem/FormCreateOrder.cs
+++ b/SecuritySystem/FormCreateOrder.cs
@@ -1,9 +1,5 @@
-using Microsoft.Extensions.Logging;
-using SecuritySystemContracts.BindingModels;
-using SecuritySystemContracts.BusinessLogicsContracts;
-using SecuritySystemContracts.SearchModels;
-using SecuritySystemContracts.ViewModels;
-using System;
+using System;
+using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@@ -13,6 +9,14 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.BusinessLogicsContracts;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.BusinessLogicsContracts;
+
namespace SecuritySystemView
{
public partial class FormCreateOrder : Form
@@ -20,24 +24,52 @@ namespace SecuritySystemView
private readonly ILogger _logger;
private readonly ISecureLogic _logicM;
private readonly IOrderLogic _logicO;
+ private readonly IClientLogic _logicC;
private List? _list;
- public FormCreateOrder(ILogger logger, ISecureLogic logicM, IOrderLogic logicO)
+ public FormCreateOrder(ILogger logger, ISecureLogic logicM, IOrderLogic logicO, IClientLogic logicC)
{
InitializeComponent();
_logger = logger;
_logicM = logicM;
_logicO = logicO;
+ _logicC = logicC;
}
private void FormCreateOrder_Load(object sender, EventArgs e)
{
- _list = _logicM.ReadList(null);
- if (_list != null)
+ _logger.LogInformation("Загрузка поездок для заказа");
+ try
{
- comboBoxSecure.DisplayMember = "SecureName";
- comboBoxSecure.ValueMember = "Id";
- comboBoxSecure.DataSource = _list;
- comboBoxSecure.SelectedItem = null;
- _logger.LogInformation("Загрузка изделий для заказа");
+ var list = _logicM.ReadList(null);
+ if (list != null)
+ {
+ comboBoxSecure.DisplayMember = "SecureName";
+ comboBoxSecure.ValueMember = "Id";
+ comboBoxSecure.DataSource = list;
+ comboBoxSecure.SelectedItem = null;
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки списка поездок");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ _logger.LogInformation("Загрузка списка клиентов");
+ try
+ {
+ var list = _logicC.ReadList(null);
+ if (list != null)
+ {
+ comboBoxClient.DisplayMember = "ClientFIO";
+ comboBoxClient.ValueMember = "Id";
+ comboBoxClient.DataSource = list;
+ comboBoxClient.SelectedItem = null;
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки списка клиентов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CalcSum()
@@ -47,7 +79,7 @@ namespace SecuritySystemView
try
{
int id = Convert.ToInt32(comboBoxSecure.SelectedValue);
- var Secure = _logicM.ReadElement(new SecureSearchModel { Id = id });
+ var Secure = _logicM.ReadElement(new SecuresearchModel { Id = id });
int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (Secure?.Price ?? 0), 2).ToString();
_logger.LogInformation("Расчет суммы заказа");
@@ -79,6 +111,11 @@ namespace SecuritySystemView
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
+ if (comboBoxClient.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
_logger.LogInformation("Создание заказа");
try
{
@@ -86,6 +123,7 @@ namespace SecuritySystemView
{
SecureId = Convert.ToInt32(comboBoxSecure.SelectedValue),
SecureName = comboBoxSecure.Text,
+ ClientId = Convert.ToInt32(comboBoxClient.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text)
});
diff --git a/SecuritySystem/FormMain.Designer.cs b/SecuritySystem/FormMain.Designer.cs
index 4d84de8..7b759ba 100644
--- a/SecuritySystem/FormMain.Designer.cs
+++ b/SecuritySystem/FormMain.Designer.cs
@@ -34,14 +34,15 @@
goodsToolStripMenuItem = new ToolStripMenuItem();
отчетыToolStripMenuItem = new ToolStripMenuItem();
componentListToolStripMenuItem = new ToolStripMenuItem();
+ componentsSecureToolStripMenuItem = new ToolStripMenuItem();
+ orderListToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
- componentsSecureToolStripMenuItem = new ToolStripMenuItem();
- orderListToolStripMenuItem = new ToolStripMenuItem();
+ clientsToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@@ -59,7 +60,7 @@
//
// guideToolStripMenuItem
//
- guideToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, goodsToolStripMenuItem });
+ guideToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, goodsToolStripMenuItem, clientsToolStripMenuItem });
guideToolStripMenuItem.Name = "guideToolStripMenuItem";
guideToolStripMenuItem.Size = new Size(87, 20);
guideToolStripMenuItem.Text = "Справочник";
@@ -67,14 +68,14 @@
// componentsToolStripMenuItem
//
componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
- componentsToolStripMenuItem.Size = new Size(145, 22);
+ componentsToolStripMenuItem.Size = new Size(180, 22);
componentsToolStripMenuItem.Text = "Компоненты";
componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
//
// goodsToolStripMenuItem
//
goodsToolStripMenuItem.Name = "goodsToolStripMenuItem";
- goodsToolStripMenuItem.Size = new Size(145, 22);
+ goodsToolStripMenuItem.Size = new Size(180, 22);
goodsToolStripMenuItem.Text = "Изделия";
goodsToolStripMenuItem.Click += GoodsToolStripMenuItem_Click;
//
@@ -89,9 +90,23 @@
//
componentListToolStripMenuItem.Name = "componentListToolStripMenuItem";
componentListToolStripMenuItem.Size = new Size(218, 22);
- componentListToolStripMenuItem.Text = "Список компонентов";
+ componentListToolStripMenuItem.Text = "Список коспонентов";
componentListToolStripMenuItem.Click += ComponentListToolStripMenuItem_Click;
//
+ // componentsSecureToolStripMenuItem
+ //
+ componentsSecureToolStripMenuItem.Name = "componentsSecureToolStripMenuItem";
+ componentsSecureToolStripMenuItem.Size = new Size(218, 22);
+ componentsSecureToolStripMenuItem.Text = "Компоненты по изделиям";
+ componentsSecureToolStripMenuItem.Click += ComponentSecuresToolStripMenuItem_Click;
+ //
+ // orderListToolStripMenuItem
+ //
+ orderListToolStripMenuItem.Name = "orderListToolStripMenuItem";
+ orderListToolStripMenuItem.Size = new Size(218, 22);
+ orderListToolStripMenuItem.Text = "Список заказов";
+ orderListToolStripMenuItem.Click += OrderListToolStripMenuItem_Click;
+ //
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
@@ -161,19 +176,12 @@
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
- // componentsSecureToolStripMenuItem
+ // clientsToolStripMenuItem
//
- componentsSecureToolStripMenuItem.Name = "componentsSecureToolStripMenuItem";
- componentsSecureToolStripMenuItem.Size = new Size(218, 22);
- componentsSecureToolStripMenuItem.Text = "Компоненты по изделиям";
- componentsSecureToolStripMenuItem.Click += ComponentSecuresToolStripMenuItem_Click;
- //
- // orderListToolStripMenuItem
- //
- orderListToolStripMenuItem.Name = "orderListToolStripMenuItem";
- orderListToolStripMenuItem.Size = new Size(218, 22);
- orderListToolStripMenuItem.Text = "Список заказов";
- orderListToolStripMenuItem.Click += OrderListToolStripMenuItem_Click;
+ clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
+ clientsToolStripMenuItem.Size = new Size(180, 22);
+ clientsToolStripMenuItem.Text = "Клиенты";
+ clientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click;
//
// FormMain
//
@@ -190,7 +198,7 @@
MainMenuStrip = menuStrip1;
Margin = new Padding(3, 2, 3, 2);
Name = "FormMain";
- Text = "Система охраны";
+ Text = "Кузнечная мастерская";
Load += FormMain_Load;
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
@@ -215,5 +223,6 @@
private ToolStripMenuItem componentListToolStripMenuItem;
private ToolStripMenuItem componentsSecureToolStripMenuItem;
private ToolStripMenuItem orderListToolStripMenuItem;
+ private ToolStripMenuItem clientsToolStripMenuItem;
}
}
\ No newline at end of file
diff --git a/SecuritySystem/FormMain.cs b/SecuritySystem/FormMain.cs
index 0506420..40671bc 100644
--- a/SecuritySystem/FormMain.cs
+++ b/SecuritySystem/FormMain.cs
@@ -11,8 +11,9 @@ using System.Windows.Forms;
using Microsoft.Extensions.Logging;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
-using SecuritySystemDataModels.Models;
-using SecuritySystemDataModels.Enums;
+
+
+using SecuritySystemView;
namespace SecuritySystemView
{
@@ -41,7 +42,8 @@ namespace SecuritySystemView
{
dataGridView.DataSource = list;
dataGridView.Columns["SecureId"].Visible = false;
- dataGridView.Columns["SecureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["ClientId"].Visible = false;
+ dataGridView.Columns["DateImplement"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка заказов");
}
@@ -61,8 +63,16 @@ namespace SecuritySystemView
}
private void GoodsToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormSecuries));
- if (service is FormSecuries form)
+ var service = Program.ServiceProvider?.GetService(typeof(FormSecures));
+ if (service is FormSecures form)
+ {
+ form.ShowDialog();
+ }
+ }
+ private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormClients));
+ if (service is FormClients form)
{
form.ShowDialog();
}
@@ -86,13 +96,7 @@ namespace SecuritySystemView
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{
- Id = id,
- SecureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SecureId"].Value),
- SecureName = dataGridView.SelectedRows[0].Cells["SecureName"].Value.ToString(),
- Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
- Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
- Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
- DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
+ Id = id
});
if (!operationResult)
{
@@ -117,15 +121,8 @@ namespace SecuritySystemView
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{
- Id = id,
- SecureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SecureId"].Value),
- SecureName = dataGridView.SelectedRows[0].Cells["SecureName"].Value.ToString(),
- Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
- Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
- Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
- DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
- DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc)
- });
+ Id = id
+ });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
@@ -149,14 +146,7 @@ namespace SecuritySystemView
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
{
- Id = id,
- SecureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SecureId"].Value),
- SecureName = dataGridView.SelectedRows[0].Cells["SecureName"].Value.ToString(),
- Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
- Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
- Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
- DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
- DateImplement = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateImplement"].Value.ToString()),
+ Id = id
});
if (!operationResult)
{
@@ -201,10 +191,5 @@ namespace SecuritySystemView
form.ShowDialog();
}
}
-
- private void списокToolStripMenuItem_Click(object sender, EventArgs e)
- {
-
- }
}
}
diff --git a/SecuritySystem/FormReportManufactureComponents.Designer.cs b/SecuritySystem/FormReportSecureComponents.Designer.cs
similarity index 100%
rename from SecuritySystem/FormReportManufactureComponents.Designer.cs
rename to SecuritySystem/FormReportSecureComponents.Designer.cs
diff --git a/SecuritySystem/FormReportManufactureComponents.cs b/SecuritySystem/FormReportSecureComponents.cs
similarity index 100%
rename from SecuritySystem/FormReportManufactureComponents.cs
rename to SecuritySystem/FormReportSecureComponents.cs
diff --git a/SecuritySystem/FormSecuries.resx b/SecuritySystem/FormReportSecureComponents.resx
similarity index 100%
rename from SecuritySystem/FormSecuries.resx
rename to SecuritySystem/FormReportSecureComponents.resx
diff --git a/SecuritySystem/FormSecure.cs b/SecuritySystem/FormSecure.cs
index bbfe2b7..31480a8 100644
--- a/SecuritySystem/FormSecure.cs
+++ b/SecuritySystem/FormSecure.cs
@@ -37,7 +37,7 @@ namespace SecuritySystemView
_logger.LogInformation("Загрузка изделия");
try
{
- var view = _logic.ReadElement(new SecureSearchModel { Id = _id.Value });
+ var view = _logic.ReadElement(new SecuresearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.SecureName;
@@ -79,8 +79,8 @@ namespace SecuritySystemView
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormSecuriesComponent));
- if (service is FormSecuriesComponent form)
+ var service = Program.ServiceProvider?.GetService(typeof(FormSecureComponent));
+ if (service is FormSecureComponent form)
{
if (form.ShowDialog() == DialogResult.OK)
{
@@ -105,8 +105,8 @@ namespace SecuritySystemView
{
if (dataGridView.SelectedRows.Count == 1)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormSecuriesComponent));
- if (service is FormSecuriesComponent form)
+ var service = Program.ServiceProvider?.GetService(typeof(FormSecureComponent));
+ if (service is FormSecureComponent form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
diff --git a/SecuritySystem/FormSecuriesComponent.Designer.cs b/SecuritySystem/FormSecureComponent.Designer.cs
similarity index 99%
rename from SecuritySystem/FormSecuriesComponent.Designer.cs
rename to SecuritySystem/FormSecureComponent.Designer.cs
index cbbfb1d..cc7af8c 100644
--- a/SecuritySystem/FormSecuriesComponent.Designer.cs
+++ b/SecuritySystem/FormSecureComponent.Designer.cs
@@ -1,6 +1,6 @@
namespace SecuritySystemView
{
- partial class FormSecuriesComponent
+ partial class FormSecureComponent
{
///
/// Required designer variable.
diff --git a/SecuritySystem/FormSecuriesComponent.cs b/SecuritySystem/FormSecureComponent.cs
similarity index 95%
rename from SecuritySystem/FormSecuriesComponent.cs
rename to SecuritySystem/FormSecureComponent.cs
index ad94391..3176540 100644
--- a/SecuritySystem/FormSecuriesComponent.cs
+++ b/SecuritySystem/FormSecureComponent.cs
@@ -13,7 +13,7 @@ using System.Windows.Forms;
namespace SecuritySystemView
{
- public partial class FormSecuriesComponent : Form
+ public partial class FormSecureComponent : Form
{
private readonly List? _list;
public int Id
@@ -50,7 +50,7 @@ namespace SecuritySystemView
get { return Convert.ToInt32(textBoxCount.Text); }
set { textBoxCount.Text = value.ToString(); }
}
- public FormSecuriesComponent(IComponentLogic logic)
+ public FormSecureComponent(IComponentLogic logic)
{
InitializeComponent();
_list = logic.ReadList(null);
diff --git a/SecuritySystem/FormSecuriesComponent.resx b/SecuritySystem/FormSecureComponent.resx
similarity index 100%
rename from SecuritySystem/FormSecuriesComponent.resx
rename to SecuritySystem/FormSecureComponent.resx
diff --git a/SecuritySystem/FormSecuries.Designer.cs b/SecuritySystem/FormSecures.Designer.cs
similarity index 97%
rename from SecuritySystem/FormSecuries.Designer.cs
rename to SecuritySystem/FormSecures.Designer.cs
index 718eb7d..74c6dc4 100644
--- a/SecuritySystem/FormSecuries.Designer.cs
+++ b/SecuritySystem/FormSecures.Designer.cs
@@ -1,6 +1,6 @@
namespace SecuritySystemView
{
- partial class FormSecuries
+ partial class FormSecures
{
///
/// Required designer variable.
@@ -109,9 +109,9 @@
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.ToolsPanel);
this.Controls.Add(this.dataGridView);
- this.Name = "FormSecuries";
+ this.Name = "FormSecures";
this.Text = "Изделия";
- this.Load += new System.EventHandler(this.FormSecuries_Load);
+ this.Load += new System.EventHandler(this.FormSecures_Load);
this.ToolsPanel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
diff --git a/SecuritySystem/FormSecuries.cs b/SecuritySystem/FormSecures.cs
similarity index 95%
rename from SecuritySystem/FormSecuries.cs
rename to SecuritySystem/FormSecures.cs
index 0537fb5..fd85fb5 100644
--- a/SecuritySystem/FormSecuries.cs
+++ b/SecuritySystem/FormSecures.cs
@@ -14,17 +14,17 @@ using System.Windows.Forms;
namespace SecuritySystemView
{
- public partial class FormSecuries : Form
+ public partial class FormSecures : Form
{
private readonly ILogger _logger;
private readonly ISecureLogic _logic;
- public FormSecuries(ILogger logger, ISecureLogic logic)
+ public FormSecures(ILogger logger, ISecureLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
- private void FormSecuries_Load(object sender, EventArgs e)
+ private void FormSecures_Load(object sender, EventArgs e)
{
LoadData();
}
diff --git a/SecuritySystem/FormSecures.resx b/SecuritySystem/FormSecures.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/SecuritySystem/FormSecures.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/SecuritySystem/Program.cs b/SecuritySystem/Program.cs
index 3747ee7..2288f57 100644
--- a/SecuritySystem/Program.cs
+++ b/SecuritySystem/Program.cs
@@ -9,6 +9,10 @@ using SecuritySystemDatabaseImplement.Implements;
using SecuritySystemContracts.BusinessLogicsContracts;
using SecuritySystemContracts.StoragesContracts;
using SecureCompanyBusinessLogic.BusinessLogics;
+using SecuritySystemBusinessLogic.BusinessLogics;
+using SecuritySystemContracts.BusinessLogicsContracts;
+using SecuritySystemContracts.StorageContracts;
+using SecuritySystemView;
namespace SecuritySystemView
{
@@ -40,10 +44,12 @@ namespace SecuritySystemView
services.AddTransient();
services.AddTransient();
- services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -54,10 +60,11 @@ namespace SecuritySystemView
services.AddTransient();
services.AddTransient();
services.AddTransient();
- services.AddTransient();
- services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/SecuritySystem/Properties/DataSources/SecuritySystemContracts.StoragesContracts.ISecureStorage.datasource b/SecuritySystem/Properties/DataSources/SecuritySystemContracts.StoragesContracts.ISecureStorage.datasource
index c1a7d7f..9b5ca5f 100644
--- a/SecuritySystem/Properties/DataSources/SecuritySystemContracts.StoragesContracts.ISecureStorage.datasource
+++ b/SecuritySystem/Properties/DataSources/SecuritySystemContracts.StoragesContracts.ISecureStorage.datasource
@@ -5,6 +5,6 @@
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
-
- SecuritySystemContracts.StoragesContracts.ISecureStorage, SecuritySystemContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
+
+ SecuritySystemContracts.StoragesContracts.ISecurestorage, SecuritySystemContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
\ No newline at end of file
diff --git a/SecuritySystemBusinessLogic/BusinessLogics/ClientLogic.cs b/SecuritySystemBusinessLogic/BusinessLogics/ClientLogic.cs
new file mode 100644
index 0000000..0bf885b
--- /dev/null
+++ b/SecuritySystemBusinessLogic/BusinessLogics/ClientLogic.cs
@@ -0,0 +1,117 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.BusinessLogicsContracts;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.StorageContracts;
+using SecuritySystemContracts.ViewModels;
+using SecuritySystemDataModels.Models;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemBusinessLogic.BusinessLogics
+{
+ public class ClientLogic : IClientLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IClientStorage _clientStorage;
+ public ClientLogic(ILogger logger, IClientStorage clientStorage)
+ {
+ _logger = logger;
+ _clientStorage = clientStorage;
+ }
+ public List? ReadList(ClientSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. ClientFIO:{ClientFIO}. Id:{Id}", model?.ClientFIO, model?.Id);
+ var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+ public ClientViewModel? ReadElement(ClientSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. ClientFIO:{ClientFIO}. Id:{Id}", model.ClientFIO, model.Id);
+ var element = _clientStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+ public bool Create(ClientBindingModel model)
+ {
+ CheckModel(model);
+ if (_clientStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Update(ClientBindingModel model)
+ {
+ CheckModel(model);
+ if (_clientStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Delete(ClientBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_clientStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+ private void CheckModel(ClientBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.ClientFIO))
+ {
+ throw new ArgumentNullException("Нет имени клиента", nameof(model.ClientFIO));
+ }
+ if (string.IsNullOrEmpty(model.Email))
+ {
+ throw new ArgumentNullException("Нет логина клиента", nameof(model.ClientFIO));
+ }
+ if (string.IsNullOrEmpty(model.Password))
+ {
+ throw new ArgumentNullException("Нет пароля учетной записи клиента", nameof(model.ClientFIO));
+ }
+ _logger.LogInformation("Client. ClientFIO:{ClientFIO}. Email:{Email}. Password:{Password}. Id:{Id}", model.ClientFIO, model.Email, model.Password, model.Id);
+ var element = _clientStorage.GetElement(new ClientSearchModel
+ {
+ Email = model.Email
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Клиент с таким логином уже есть");
+ }
+ }
+ }
+}
diff --git a/SecuritySystemBusinessLogic/BusinessLogics/ReportLogic.cs b/SecuritySystemBusinessLogic/BusinessLogics/ReportLogic.cs
index 76bb264..d1b91e1 100644
--- a/SecuritySystemBusinessLogic/BusinessLogics/ReportLogic.cs
+++ b/SecuritySystemBusinessLogic/BusinessLogics/ReportLogic.cs
@@ -11,15 +11,15 @@ namespace SecureCompanyBusinessLogic.BusinessLogics
public class ReportLogic : IReportLogic
{
private readonly IComponentStorage _componentStorage;
- private readonly ISecureStorage _SecureStorage;
+ private readonly ISecurestorage _Securestorage;
private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
- public ReportLogic(ISecureStorage SecureStorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
+ public ReportLogic(ISecurestorage Securestorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
- _SecureStorage = SecureStorage;
+ _Securestorage = Securestorage;
_componentStorage = componentStorage;
_orderStorage = orderStorage;
_saveToExcel = saveToExcel;
@@ -34,7 +34,7 @@ namespace SecureCompanyBusinessLogic.BusinessLogics
public List GetSecureComponent()
{
var components = _componentStorage.GetFullList();
- var Secures = _SecureStorage.GetFullList();
+ var Secures = _Securestorage.GetFullList();
var list = new List();
foreach (var Secure in Secures)
@@ -88,7 +88,7 @@ namespace SecureCompanyBusinessLogic.BusinessLogics
{
FileName = model.FileName,
Title = "Список компонент",
- Secures = _SecureStorage.GetFullList()
+ Secures = _Securestorage.GetFullList()
});
}
diff --git a/SecuritySystemBusinessLogic/BusinessLogics/SecureLogic.cs b/SecuritySystemBusinessLogic/BusinessLogics/SecureLogic.cs
index 6d18575..6a28a16 100644
--- a/SecuritySystemBusinessLogic/BusinessLogics/SecureLogic.cs
+++ b/SecuritySystemBusinessLogic/BusinessLogics/SecureLogic.cs
@@ -11,18 +11,18 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
public class SecureLogic : ISecureLogic
{
private readonly ILogger _logger;
- private readonly ISecureStorage _SecureStorage;
+ private readonly ISecurestorage _Securestorage;
- public SecureLogic(ILogger logger, ISecureStorage SecureStorage)
+ public SecureLogic(ILogger logger, ISecurestorage Securestorage)
{
_logger = logger;
- _SecureStorage = SecureStorage;
+ _Securestorage = Securestorage;
}
- public List? ReadList(SecureSearchModel? model)
+ public List? ReadList(SecuresearchModel? model)
{
_logger.LogInformation("ReadList. SecureName:{SecureName}.Id:{ Id}", model?.SecureName, model?.Id);
- var list = model == null ? _SecureStorage.GetFullList() : _SecureStorage.GetFilteredList(model);
+ var list = model == null ? _Securestorage.GetFullList() : _Securestorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
@@ -32,14 +32,14 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
return list;
}
- public SecureViewModel? ReadElement(SecureSearchModel model)
+ public SecureViewModel? ReadElement(SecuresearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. SecureName:{SecureName}.Id:{ Id}", model.SecureName, model.Id);
- var element = _SecureStorage.GetElement(model);
+ var element = _Securestorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
@@ -52,7 +52,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
public bool Create(SecureBindingModel model)
{
CheckModel(model);
- if (_SecureStorage.Insert(model) == null)
+ if (_Securestorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
@@ -63,7 +63,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
public bool Update(SecureBindingModel model)
{
CheckModel(model);
- if (_SecureStorage.Update(model) == null)
+ if (_Securestorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
@@ -75,7 +75,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
- if (_SecureStorage.Delete(model) == null)
+ if (_Securestorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
@@ -102,7 +102,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
throw new ArgumentNullException("Цена камеры должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation("Secure. SecureName:{SecureName}.Cost:{ Cost}. Id: { Id}", model.SecureName, model.Price, model.Id);
- var element = _SecureStorage.GetElement(new SecureSearchModel
+ var element = _Securestorage.GetElement(new SecuresearchModel
{
SecureName = model.SecureName
});
diff --git a/SecuritySystemContracts/BindingModels/ClientBindingModel.cs b/SecuritySystemContracts/BindingModels/ClientBindingModel.cs
new file mode 100644
index 0000000..82bf42f
--- /dev/null
+++ b/SecuritySystemContracts/BindingModels/ClientBindingModel.cs
@@ -0,0 +1,17 @@
+using SecuritySystemDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemContracts.BindingModels
+{
+ public class ClientBindingModel : IClientModel
+ {
+ public int Id { get; set; }
+ public string ClientFIO { get; set; } = string.Empty;
+ public string Email { get; set; } = string.Empty;
+ public string Password { get; set; } = string.Empty;
+ }
+}
diff --git a/SecuritySystemContracts/BindingModels/OrderBindingModel.cs b/SecuritySystemContracts/BindingModels/OrderBindingModel.cs
index e37083b..2c3503c 100644
--- a/SecuritySystemContracts/BindingModels/OrderBindingModel.cs
+++ b/SecuritySystemContracts/BindingModels/OrderBindingModel.cs
@@ -7,6 +7,7 @@ namespace SecuritySystemContracts.BindingModels
{
public int Id { get; set; }
public int SecureId { get; set; }
+ public int ClientId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public string SecureName { get; set; } = string.Empty;
diff --git a/SecuritySystemContracts/BusinessLogicsContracts/IClientLogic.cs b/SecuritySystemContracts/BusinessLogicsContracts/IClientLogic.cs
new file mode 100644
index 0000000..d20825e
--- /dev/null
+++ b/SecuritySystemContracts/BusinessLogicsContracts/IClientLogic.cs
@@ -0,0 +1,21 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemContracts.BusinessLogicsContracts
+{
+ public interface IClientLogic
+ {
+ List? ReadList(ClientSearchModel? model);
+ ClientViewModel? ReadElement(ClientSearchModel model);
+ bool Create(ClientBindingModel model);
+ bool Update(ClientBindingModel model);
+ bool Delete(ClientBindingModel model);
+ }
+}
diff --git a/SecuritySystemContracts/BusinessLogicsContracts/ISecureLogic.cs b/SecuritySystemContracts/BusinessLogicsContracts/ISecureLogic.cs
index 58f0398..65fbbaf 100644
--- a/SecuritySystemContracts/BusinessLogicsContracts/ISecureLogic.cs
+++ b/SecuritySystemContracts/BusinessLogicsContracts/ISecureLogic.cs
@@ -12,8 +12,8 @@ namespace SecuritySystemContracts.BusinessLogicsContracts
{
public interface ISecureLogic
{
- List? ReadList(SecureSearchModel? model);
- SecureViewModel? ReadElement(SecureSearchModel model);
+ List? ReadList(SecuresearchModel? model);
+ SecureViewModel? ReadElement(SecuresearchModel model);
bool Create(SecureBindingModel model);
bool Update(SecureBindingModel model);
bool Delete(SecureBindingModel model);
diff --git a/SecuritySystemContracts/SearchModels/ClientSearchModel.cs b/SecuritySystemContracts/SearchModels/ClientSearchModel.cs
new file mode 100644
index 0000000..287bd75
--- /dev/null
+++ b/SecuritySystemContracts/SearchModels/ClientSearchModel.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemContracts.SearchModels
+{
+ public class ClientSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ClientFIO { get; set; }
+ public string? Email { get; set;}
+ public string? Password { get; set;}
+ }
+}
diff --git a/SecuritySystemContracts/SearchModels/OrderSearchModel.cs b/SecuritySystemContracts/SearchModels/OrderSearchModel.cs
index 66eea1f..4a70aaa 100644
--- a/SecuritySystemContracts/SearchModels/OrderSearchModel.cs
+++ b/SecuritySystemContracts/SearchModels/OrderSearchModel.cs
@@ -9,6 +9,7 @@ namespace SecuritySystemContracts.SearchModels
public class OrderSearchModel
{
public int? Id { get; set; }
+ public int? ClientId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
diff --git a/SecuritySystemContracts/SearchModels/SecureSearchModel.cs b/SecuritySystemContracts/SearchModels/SecureSearchModel.cs
index 8547e9f..1c86d2f 100644
--- a/SecuritySystemContracts/SearchModels/SecureSearchModel.cs
+++ b/SecuritySystemContracts/SearchModels/SecureSearchModel.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace SecuritySystemContracts.SearchModels
{
- public class SecureSearchModel
+ public class SecuresearchModel
{
public int? Id { get; set; }
public string? SecureName { get; set; }
diff --git a/SecuritySystemContracts/StorageContracts/IClientStorage.cs b/SecuritySystemContracts/StorageContracts/IClientStorage.cs
new file mode 100644
index 0000000..7d05a11
--- /dev/null
+++ b/SecuritySystemContracts/StorageContracts/IClientStorage.cs
@@ -0,0 +1,23 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.ViewModels;
+using SecuritySystemDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemContracts.StorageContracts
+{
+ public interface IClientStorage
+ {
+ List GetFullList();
+ List GetFilteredList(ClientSearchModel model);
+ ClientViewModel? GetElement(ClientSearchModel model);
+ ClientViewModel? Insert(ClientBindingModel model);
+ ClientViewModel? Update(ClientBindingModel model);
+ ClientViewModel? Delete(ClientBindingModel model);
+ }
+}
diff --git a/SecuritySystemContracts/StorageContracts/ISecureStorage.cs b/SecuritySystemContracts/StorageContracts/ISecureStorage.cs
index 7dc62cc..7f168a9 100644
--- a/SecuritySystemContracts/StorageContracts/ISecureStorage.cs
+++ b/SecuritySystemContracts/StorageContracts/ISecureStorage.cs
@@ -9,11 +9,11 @@ using System.Threading.Tasks;
namespace SecuritySystemContracts.StoragesContracts
{
- public interface ISecureStorage
+ public interface ISecurestorage
{
List GetFullList();
- List GetFilteredList(SecureSearchModel model);
- SecureViewModel? GetElement(SecureSearchModel model);
+ List GetFilteredList(SecuresearchModel model);
+ SecureViewModel? GetElement(SecuresearchModel model);
SecureViewModel? Insert(SecureBindingModel model);
SecureViewModel? Update(SecureBindingModel model);
SecureViewModel? Delete(SecureBindingModel model);
diff --git a/SecuritySystemContracts/ViewModels/ClientViewModel.cs b/SecuritySystemContracts/ViewModels/ClientViewModel.cs
new file mode 100644
index 0000000..de2e2a9
--- /dev/null
+++ b/SecuritySystemContracts/ViewModels/ClientViewModel.cs
@@ -0,0 +1,21 @@
+using SecuritySystemDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemContracts.ViewModels
+{
+ public class ClientViewModel : IClientModel
+ {
+ public int Id { get; set; }
+ [DisplayName("ФИО клиента")]
+ public string ClientFIO { get; set; } = string.Empty;
+ [DisplayName("Логин (эл. почта)")]
+ public string Email { get; set; } = string.Empty;
+ [DisplayName("Пароль")]
+ public string Password { get; set; } = string.Empty;
+ }
+}
diff --git a/SecuritySystemContracts/ViewModels/OrderViewModel.cs b/SecuritySystemContracts/ViewModels/OrderViewModel.cs
index 49fed59..62e6458 100644
--- a/SecuritySystemContracts/ViewModels/OrderViewModel.cs
+++ b/SecuritySystemContracts/ViewModels/OrderViewModel.cs
@@ -17,6 +17,9 @@ namespace SecuritySystemContracts.ViewModels
[DisplayName("Изделие")]
public string SecureName { get; set; } = string.Empty;
[DisplayName("Количество")]
+ public int ClientId { get; set; }
+ [DisplayName("Клиент")]
+ public string ClientFIO { get; set; } = string.Empty;
public int Count { get; set; }
[DisplayName("Сумма")]
public double Sum { get; set; }
diff --git a/SecuritySystemDataModels/Models/IClientModel.cs b/SecuritySystemDataModels/Models/IClientModel.cs
new file mode 100644
index 0000000..4c0b40a
--- /dev/null
+++ b/SecuritySystemDataModels/Models/IClientModel.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemDataModels.Models
+{
+ public interface IClientModel : IId
+ {
+ string ClientFIO { get; }
+ string Email { get; }
+ string Password { get; }
+ }
+}
diff --git a/SecuritySystemDataModels/Models/IOrderModel.cs b/SecuritySystemDataModels/Models/IOrderModel.cs
index 1f705ee..91f72af 100644
--- a/SecuritySystemDataModels/Models/IOrderModel.cs
+++ b/SecuritySystemDataModels/Models/IOrderModel.cs
@@ -11,6 +11,7 @@ namespace SecuritySystemDataModels.Models
public interface IOrderModel : IId
{
int SecureId { get; }
+ int ClientId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }
diff --git a/SecuritySystemDatabaseImplement/Implements/ClientStorage.cs b/SecuritySystemDatabaseImplement/Implements/ClientStorage.cs
new file mode 100644
index 0000000..3926941
--- /dev/null
+++ b/SecuritySystemDatabaseImplement/Implements/ClientStorage.cs
@@ -0,0 +1,96 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.StorageContracts;
+using SecuritySystemContracts.ViewModels;
+using SecuritySystemDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemDatabaseImplement.Implements
+{
+ public class ClientStorage : IClientStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new SecuritySystemDatabase();
+ return context.Clients
+ .Include(x => x.Orders)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public List GetFilteredList(ClientSearchModel model)
+ {
+ if (model == null)
+ {
+ return new();
+ }
+ if (!string.IsNullOrEmpty(model.Email))
+ {
+ using var context = new SecuritySystemDatabase();
+ return context.Clients
+ .Include(x => x.Orders)
+ .Where(x => x.Email.Contains(model.Email))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ return new();
+ }
+ public ClientViewModel? GetElement(ClientSearchModel model)
+ {
+ using var context = new SecuritySystemDatabase();
+ if (model.Id.HasValue)
+ {
+ return context.Clients
+ .FirstOrDefault(x => (x.Id == model.Id))?.GetViewModel;
+ }
+ else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
+ {
+ return context.Clients
+ .FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password))?.GetViewModel;
+ }
+ return new();
+ }
+ public ClientViewModel? Insert(ClientBindingModel model)
+ {
+ var newClient = Client.Create(model);
+ if (newClient == null)
+ {
+ return null;
+ }
+ using var context = new SecuritySystemDatabase();
+ context.Clients.Add(newClient);
+ context.SaveChanges();
+ return newClient.GetViewModel;
+ }
+ public ClientViewModel? Update(ClientBindingModel model)
+ {
+ using var context = new SecuritySystemDatabase();
+ var client = context.Clients.FirstOrDefault(x => x.Id == model.Id);
+ if (client == null)
+ {
+ return null;
+ }
+ client.Update(model);
+ context.SaveChanges();
+ return client.GetViewModel;
+ }
+ public ClientViewModel? Delete(ClientBindingModel model)
+ {
+ using var context = new SecuritySystemDatabase();
+ var element = context.Clients
+ .Include(x => x.Orders)
+ .FirstOrDefault(rec => rec.Id == model.Id);
+ if (element != null)
+ {
+ context.Clients.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/SecuritySystemDatabaseImplement/Implements/OrderStorage.cs b/SecuritySystemDatabaseImplement/Implements/OrderStorage.cs
index 3cdc314..e6b6983 100644
--- a/SecuritySystemDatabaseImplement/Implements/OrderStorage.cs
+++ b/SecuritySystemDatabaseImplement/Implements/OrderStorage.cs
@@ -1,9 +1,10 @@
-using SecuritySystemContracts.BindingModels;
+
+using Microsoft.EntityFrameworkCore;
+using SecuritySystemDatabaseImplement.Models;
+using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.SearchModels;
using SecuritySystemContracts.StoragesContracts;
using SecuritySystemContracts.ViewModels;
-using Microsoft.EntityFrameworkCore;
-using SecuritySystemDatabaseImplement.Models;
namespace SecuritySystemDatabaseImplement.Implements
{
@@ -15,7 +16,11 @@ namespace SecuritySystemDatabaseImplement.Implements
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
- var deletedElement = context.Orders.Include(x => x.Secure).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
+ var deletedElement = context.Orders
+ .Include(x => x.Secure)
+ .Include(x => x.Client)
+ .FirstOrDefault(x => x.Id == model.Id)
+ ?.GetViewModel;
context.Orders.Remove(element);
context.SaveChanges();
return deletedElement;
@@ -29,29 +34,55 @@ namespace SecuritySystemDatabaseImplement.Implements
return null;
}
using var context = new SecuritySystemDatabase();
- return context.Orders.Include(x => x.Secure).FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
+ return context.Orders
+ .Include(x => x.Secure)
+ .Include(x => x.Client)
+ .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
+ ?.GetViewModel;
}
public List GetFilteredList(OrderSearchModel model)
{
- if (model is null)
- return new();
-
using var context = new SecuritySystemDatabase();
- if (!model.Id.HasValue)
+ if (model.Id.HasValue)
{
return context.Orders
.Include(x => x.Secure)
+ .Include(x => x.Client)
+ .Where(x => x.Id == model.Id)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ else if (model.DateFrom != null && model.DateTo != null)
+ {
+ return context.Orders
+ .Include(x => x.Secure)
+ .Include(x => x.Client)
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
-
- return context.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
+ else if (model.ClientId.HasValue)
+ {
+ return context.Orders
+ .Include(x => x.Secure)
+ .Include(x => x.Client)
+ .Where(x => x.ClientId == model.ClientId)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ else
+ {
+ return new();
+ }
}
public List GetFullList()
{
using var context = new SecuritySystemDatabase();
- return context.Orders.Include(x => x.Secure).Select(x => x.GetViewModel).ToList();
+ return context.Orders
+ .Include(x => x.Secure)
+ .Include(x => x.Client)
+ .Select(x => x.GetViewModel)
+ .ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
{
@@ -63,7 +94,11 @@ namespace SecuritySystemDatabaseImplement.Implements
using var context = new SecuritySystemDatabase();
context.Orders.Add(newOrder);
context.SaveChanges();
- return context.Orders.Include(x => x.Secure).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
+ return context.Orders
+ .Include(x => x.Secure)
+ .Include(x => x.Client)
+ .FirstOrDefault(x => x.Id == newOrder.Id)
+ ?.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
@@ -75,7 +110,11 @@ namespace SecuritySystemDatabaseImplement.Implements
}
order.Update(model);
context.SaveChanges();
- return context.Orders.Include(x => x.Secure).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
+ return context.Orders
+ .Include(x => x.Secure)
+ .Include(x => x.Client)
+ .FirstOrDefault(x => x.Id == model.Id)
+ ?.GetViewModel;
}
}
}
diff --git a/SecuritySystemDatabaseImplement/Implements/SecureStorage.cs b/SecuritySystemDatabaseImplement/Implements/SecureStorage.cs
index 9b5151e..609062b 100644
--- a/SecuritySystemDatabaseImplement/Implements/SecureStorage.cs
+++ b/SecuritySystemDatabaseImplement/Implements/SecureStorage.cs
@@ -6,14 +6,14 @@ using SecuritySystemDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace SecuritySystemDatabaseImplement.Implements
{
- public class SecureStorage : ISecureStorage
+ public class Securestorage : ISecurestorage
{
public List GetFullList()
{
using var context = new SecuritySystemDatabase();
return context.Secures.Include(x => x.Components).ThenInclude(x => x.Component).ToList().Select(x => x.GetViewModel).ToList();
}
- public List GetFilteredList(SecureSearchModel model)
+ public List GetFilteredList(SecuresearchModel model)
{
if (string.IsNullOrEmpty(model.SecureName))
{
@@ -23,7 +23,7 @@ namespace SecuritySystemDatabaseImplement.Implements
return context.Secures.Include(x => x.Components).ThenInclude(x => x.Component).Where(x => x.SecureName.Contains(model.SecureName)).ToList()
.Select(x => x.GetViewModel).ToList();
}
- public SecureViewModel? GetElement(SecureSearchModel model)
+ public SecureViewModel? GetElement(SecuresearchModel model)
{
if (string.IsNullOrEmpty(model.SecureName) &&
!model.Id.HasValue)
diff --git a/SecuritySystemDatabaseImplement/Migrations/20230404083020_InitialCreate4.Designer.cs b/SecuritySystemDatabaseImplement/Migrations/20230404083020_InitialCreate4.Designer.cs
deleted file mode 100644
index 28de3ce..0000000
--- a/SecuritySystemDatabaseImplement/Migrations/20230404083020_InitialCreate4.Designer.cs
+++ /dev/null
@@ -1,171 +0,0 @@
-//
-using System;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Migrations;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
-using SecuritySystemDatabaseImplement;
-
-#nullable disable
-
-namespace SecuritySystemDatabaseImplement.Migrations
-{
- [DbContext(typeof(SecuritySystemDatabase))]
- [Migration("20230404083020_InitialCreate4")]
- partial class InitialCreate4
- {
- ///
- protected override void BuildTargetModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder
- .HasAnnotation("ProductVersion", "7.0.4")
- .HasAnnotation("Relational:MaxIdentifierLength", 63);
-
- NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
-
- modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("integer");
-
- NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
-
- b.Property("ComponentName")
- .IsRequired()
- .HasColumnType("text");
-
- b.Property("Cost")
- .HasColumnType("double precision");
-
- b.HasKey("Id");
-
- b.ToTable("Components");
- });
-
- modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("integer");
-
- NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
-
- b.Property("Count")
- .HasColumnType("integer");
-
- b.Property("DateCreate")
- .HasColumnType("timestamp with time zone");
-
- b.Property("DateImplement")
- .HasColumnType("timestamp with time zone");
-
- b.Property("SecureId")
- .HasColumnType("integer");
-
- b.Property("Status")
- .HasColumnType("integer");
-
- b.Property("Sum")
- .HasColumnType("double precision");
-
- b.HasKey("Id");
-
- b.HasIndex("SecureId");
-
- b.ToTable("Orders");
- });
-
- modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("integer");
-
- NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
-
- b.Property("Price")
- .HasColumnType("double precision");
-
- b.Property("SecureName")
- .IsRequired()
- .HasColumnType("text");
-
- b.HasKey("Id");
-
- b.ToTable("Secures");
- });
-
- modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("integer");
-
- NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
-
- b.Property("ComponentId")
- .HasColumnType("integer");
-
- b.Property("Count")
- .HasColumnType("integer");
-
- b.Property("SecureId")
- .HasColumnType("integer");
-
- b.HasKey("Id");
-
- b.HasIndex("ComponentId");
-
- b.HasIndex("SecureId");
-
- b.ToTable("SecureComponents");
- });
-
- modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
- {
- b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
- .WithMany("Orders")
- .HasForeignKey("SecureId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Secure");
- });
-
- modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b =>
- {
- b.HasOne("SecuritySystemDatabaseImplement.Models.Component", "Component")
- .WithMany("SecureComponents")
- .HasForeignKey("ComponentId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
- .WithMany("Components")
- .HasForeignKey("SecureId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Component");
-
- b.Navigation("Secure");
- });
-
- modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
- {
- b.Navigation("SecureComponents");
- });
-
- modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b =>
- {
- b.Navigation("Components");
-
- b.Navigation("Orders");
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/SecuritySystemDatabaseImplement/Migrations/20230404083020_InitialCreate4.cs b/SecuritySystemDatabaseImplement/Migrations/20230404083020_InitialCreate4.cs
deleted file mode 100644
index ba4a396..0000000
--- a/SecuritySystemDatabaseImplement/Migrations/20230404083020_InitialCreate4.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using Microsoft.EntityFrameworkCore.Migrations;
-
-#nullable disable
-
-namespace SecuritySystemDatabaseImplement.Migrations
-{
- ///
- public partial class InitialCreate4 : Migration
- {
- ///
- protected override void Up(MigrationBuilder migrationBuilder)
- {
-
- }
-
- ///
- protected override void Down(MigrationBuilder migrationBuilder)
- {
-
- }
- }
-}
diff --git a/SecuritySystemDatabaseImplement/Migrations/20230404083007_InitialCreate.Designer.cs b/SecuritySystemDatabaseImplement/Migrations/20230423054524_with client.Designer.cs
similarity index 79%
rename from SecuritySystemDatabaseImplement/Migrations/20230404083007_InitialCreate.Designer.cs
rename to SecuritySystemDatabaseImplement/Migrations/20230423054524_with client.Designer.cs
index 89afd67..f9c945d 100644
--- a/SecuritySystemDatabaseImplement/Migrations/20230404083007_InitialCreate.Designer.cs
+++ b/SecuritySystemDatabaseImplement/Migrations/20230423054524_with client.Designer.cs
@@ -12,8 +12,8 @@ using SecuritySystemDatabaseImplement;
namespace SecuritySystemDatabaseImplement.Migrations
{
[DbContext(typeof(SecuritySystemDatabase))]
- [Migration("20230404083007_InitialCreate")]
- partial class InitialCreate
+ [Migration("20230423054524_with client")]
+ partial class withclient
{
///
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -25,6 +25,31 @@ namespace SecuritySystemDatabaseImplement.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+ modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ClientFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Email")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Clients");
+ });
+
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
{
b.Property("Id")
@@ -53,6 +78,9 @@ namespace SecuritySystemDatabaseImplement.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+ b.Property("ClientId")
+ .HasColumnType("integer");
+
b.Property("Count")
.HasColumnType("integer");
@@ -73,6 +101,8 @@ namespace SecuritySystemDatabaseImplement.Migrations
b.HasKey("Id");
+ b.HasIndex("ClientId");
+
b.HasIndex("SecureId");
b.ToTable("Orders");
@@ -126,12 +156,20 @@ namespace SecuritySystemDatabaseImplement.Migrations
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
{
+ b.HasOne("SecuritySystemDatabaseImplement.Models.Client", "Client")
+ .WithMany("Orders")
+ .HasForeignKey("ClientId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
.WithMany("Orders")
.HasForeignKey("SecureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
+ b.Navigation("Client");
+
b.Navigation("Secure");
});
@@ -154,6 +192,11 @@ namespace SecuritySystemDatabaseImplement.Migrations
b.Navigation("Secure");
});
+ modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Client", b =>
+ {
+ b.Navigation("Orders");
+ });
+
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
{
b.Navigation("SecureComponents");
diff --git a/SecuritySystemDatabaseImplement/Migrations/20230404083007_InitialCreate.cs b/SecuritySystemDatabaseImplement/Migrations/20230423054524_with client.cs
similarity index 79%
rename from SecuritySystemDatabaseImplement/Migrations/20230404083007_InitialCreate.cs
rename to SecuritySystemDatabaseImplement/Migrations/20230423054524_with client.cs
index 0eee1a3..f262b4a 100644
--- a/SecuritySystemDatabaseImplement/Migrations/20230404083007_InitialCreate.cs
+++ b/SecuritySystemDatabaseImplement/Migrations/20230423054524_with client.cs
@@ -7,11 +7,26 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace SecuritySystemDatabaseImplement.Migrations
{
///
- public partial class InitialCreate : Migration
+ public partial class withclient : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
+ migrationBuilder.CreateTable(
+ name: "Clients",
+ columns: table => new
+ {
+ Id = table.Column(type: "integer", nullable: false)
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ ClientFIO = table.Column(type: "text", nullable: false),
+ Email = table.Column(type: "text", nullable: false),
+ Password = table.Column(type: "text", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Clients", x => x.Id);
+ });
+
migrationBuilder.CreateTable(
name: "Components",
columns: table => new
@@ -47,6 +62,7 @@ namespace SecuritySystemDatabaseImplement.Migrations
Id = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
SecureId = table.Column(type: "integer", nullable: false),
+ ClientId = table.Column(type: "integer", nullable: false),
Count = table.Column(type: "integer", nullable: false),
Sum = table.Column(type: "double precision", nullable: false),
Status = table.Column(type: "integer", nullable: false),
@@ -56,6 +72,12 @@ namespace SecuritySystemDatabaseImplement.Migrations
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Orders_Clients_ClientId",
+ column: x => x.ClientId,
+ principalTable: "Clients",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Secures_SecureId",
column: x => x.SecureId,
@@ -91,6 +113,11 @@ namespace SecuritySystemDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade);
});
+ migrationBuilder.CreateIndex(
+ name: "IX_Orders_ClientId",
+ table: "Orders",
+ column: "ClientId");
+
migrationBuilder.CreateIndex(
name: "IX_Orders_SecureId",
table: "Orders",
@@ -116,6 +143,9 @@ namespace SecuritySystemDatabaseImplement.Migrations
migrationBuilder.DropTable(
name: "SecureComponents");
+ migrationBuilder.DropTable(
+ name: "Clients");
+
migrationBuilder.DropTable(
name: "Components");
diff --git a/SecuritySystemDatabaseImplement/Migrations/SecuritySystemDatabaseModelSnapshot.cs b/SecuritySystemDatabaseImplement/Migrations/SecuritySystemDatabaseModelSnapshot.cs
index 9e14cab..09ac6dc 100644
--- a/SecuritySystemDatabaseImplement/Migrations/SecuritySystemDatabaseModelSnapshot.cs
+++ b/SecuritySystemDatabaseImplement/Migrations/SecuritySystemDatabaseModelSnapshot.cs
@@ -22,6 +22,31 @@ namespace SecuritySystemDatabaseImplement.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+ modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ClientFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Email")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Clients");
+ });
+
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
{
b.Property("Id")
@@ -50,6 +75,9 @@ namespace SecuritySystemDatabaseImplement.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+ b.Property("ClientId")
+ .HasColumnType("integer");
+
b.Property("Count")
.HasColumnType("integer");
@@ -70,6 +98,8 @@ namespace SecuritySystemDatabaseImplement.Migrations
b.HasKey("Id");
+ b.HasIndex("ClientId");
+
b.HasIndex("SecureId");
b.ToTable("Orders");
@@ -123,12 +153,20 @@ namespace SecuritySystemDatabaseImplement.Migrations
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b =>
{
+ b.HasOne("SecuritySystemDatabaseImplement.Models.Client", "Client")
+ .WithMany("Orders")
+ .HasForeignKey("ClientId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure")
.WithMany("Orders")
.HasForeignKey("SecureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
+ b.Navigation("Client");
+
b.Navigation("Secure");
});
@@ -151,6 +189,11 @@ namespace SecuritySystemDatabaseImplement.Migrations
b.Navigation("Secure");
});
+ modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Client", b =>
+ {
+ b.Navigation("Orders");
+ });
+
modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b =>
{
b.Navigation("SecureComponents");
diff --git a/SecuritySystemDatabaseImplement/Models/Client.cs b/SecuritySystemDatabaseImplement/Models/Client.cs
new file mode 100644
index 0000000..10cabfd
--- /dev/null
+++ b/SecuritySystemDatabaseImplement/Models/Client.cs
@@ -0,0 +1,57 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.ViewModels;
+using SecuritySystemDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemDatabaseImplement.Models
+{
+ public class Client : IClientModel
+ {
+ public int Id { get; set; }
+ [Required]
+ public string ClientFIO { get; set; } = string.Empty;
+ [Required]
+ public string Email { get; set; } = string.Empty;
+ [Required]
+ public string Password { get; set; } = string.Empty;
+ [ForeignKey("ClientId")]
+ public virtual List Orders { get; set; } = new();
+ public static Client? Create(ClientBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Client()
+ {
+ Id = model.Id,
+ ClientFIO = model.ClientFIO,
+ Email = model.Email,
+ Password = model.Password
+ };
+ }
+ public void Update(ClientBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ClientFIO = model.ClientFIO;
+ Email = model.Email;
+ Password = model.Password;
+ }
+ public ClientViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ClientFIO = ClientFIO,
+ Email = Email,
+ Password = Password
+ };
+ }
+}
diff --git a/SecuritySystemDatabaseImplement/Models/Order.cs b/SecuritySystemDatabaseImplement/Models/Order.cs
index e03a300..fbf58ad 100644
--- a/SecuritySystemDatabaseImplement/Models/Order.cs
+++ b/SecuritySystemDatabaseImplement/Models/Order.cs
@@ -17,6 +17,7 @@ namespace SecuritySystemDatabaseImplement.Models
public int Id { get; set; }
[Required]
public int SecureId { get; set; }
+ public int ClientId { get; set; }
[Required]
public int Count { get; set; }
[Required]
@@ -27,6 +28,7 @@ namespace SecuritySystemDatabaseImplement.Models
public DateTime DateCreate { get; set; }
public DateTime? DateImplement { get; set; }
public virtual Secure Secure { get; set; }
+ public virtual Client Client { get; set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
@@ -37,6 +39,7 @@ namespace SecuritySystemDatabaseImplement.Models
{
Id = model.Id,
SecureId = model.SecureId,
+ ClientId = model.ClientId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@@ -59,6 +62,8 @@ namespace SecuritySystemDatabaseImplement.Models
Id = Id,
SecureId = SecureId,
SecureName = Secure.SecureName,
+ ClientId = ClientId,
+ ClientFIO = Client.ClientFIO,
Count = Count,
Sum = Sum,
Status = Status,
diff --git a/SecuritySystemDatabaseImplement/SecuritySystemDatabase.cs b/SecuritySystemDatabaseImplement/SecuritySystemDatabase.cs
index 0588be8..d1e71d7 100644
--- a/SecuritySystemDatabaseImplement/SecuritySystemDatabase.cs
+++ b/SecuritySystemDatabaseImplement/SecuritySystemDatabase.cs
@@ -17,5 +17,7 @@ namespace SecuritySystemDatabaseImplement
public virtual DbSet Secures { set; get; }
public virtual DbSet SecureComponents { set; get; }
public virtual DbSet Orders { set; get; }
+ public virtual DbSet Clients { set; get; }
+
}
}
diff --git a/SecuritySystemFileImplement/DataFileSingletone.cs b/SecuritySystemFileImplement/DataFileSingletone.cs
index 3b742c1..3fa222f 100644
--- a/SecuritySystemFileImplement/DataFileSingletone.cs
+++ b/SecuritySystemFileImplement/DataFileSingletone.cs
@@ -15,9 +15,11 @@ namespace SecuritySystemFileImplement
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string SecureFileName = "Secure.xml";
+ private readonly string ClientFileName = "Client.xml";
public List Components { get; private set; }
public List Orders { get; private set; }
public List Secures { get; private set; }
+ public List Clients { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
@@ -29,11 +31,13 @@ namespace SecuritySystemFileImplement
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
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);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.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)!)!;
}
private static List? LoadData(string filename, string xmlNodeName, Func selectFunction)
{
diff --git a/SecuritySystemFileImplement/Implements/ClientStorage.cs b/SecuritySystemFileImplement/Implements/ClientStorage.cs
new file mode 100644
index 0000000..11e5bab
--- /dev/null
+++ b/SecuritySystemFileImplement/Implements/ClientStorage.cs
@@ -0,0 +1,87 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.StorageContracts;
+using SecuritySystemContracts.ViewModels;
+using SecuritySystemFileImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemFileImplement.Implements
+{
+ public class ClientStorage : IClientStorage
+ {
+ private readonly DataFileSingleton source;
+ public ClientStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ return source.Clients
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public List GetFilteredList(ClientSearchModel model)
+ {
+ if (!string.IsNullOrEmpty(model.Email))
+ {
+ return source.Clients
+ .Where(x => x.Email.Contains(model.Email))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ return new();
+ }
+ public ClientViewModel? GetElement(ClientSearchModel model)
+ {
+ if (model.Id.HasValue)
+ {
+ return source.Clients
+ .FirstOrDefault(x => (x.Id == model.Id))?.GetViewModel;
+ }
+ else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
+ {
+ return source.Clients
+ .FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password))?.GetViewModel;
+ }
+ return new();
+ }
+ public ClientViewModel? Insert(ClientBindingModel model)
+ {
+ model.Id = source.Clients.Count > 0 ? source.Clients.Max(x => x.Id) + 1 : 1;
+ var newClient = Client.Create(model);
+ if (newClient == null)
+ {
+ return null;
+ }
+ source.Clients.Add(newClient);
+ source.SaveClients();
+ return newClient.GetViewModel;
+ }
+ public ClientViewModel? Update(ClientBindingModel model)
+ {
+ var client = source.Clients.FirstOrDefault(x => x.Id == model.Id);
+ if (client == null)
+ {
+ return null;
+ }
+ client.Update(model);
+ source.SaveClients();
+ return client.GetViewModel;
+ }
+ public ClientViewModel? Delete(ClientBindingModel model)
+ {
+ var client = source.Clients.FirstOrDefault(x => x.Id == model.Id);
+ if (client != null)
+ {
+ source.Clients.Remove(client);
+ source.SaveClients();
+ return client.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/SecuritySystemFileImplement/Implements/OrderStorage.cs b/SecuritySystemFileImplement/Implements/OrderStorage.cs
index b292106..803567b 100644
--- a/SecuritySystemFileImplement/Implements/OrderStorage.cs
+++ b/SecuritySystemFileImplement/Implements/OrderStorage.cs
@@ -22,10 +22,6 @@ namespace SecuritySystemFileImplement.Implements
}
public List GetFilteredList(OrderSearchModel model)
{
- if (!model.Id.HasValue && (model.DateFrom == null || model.DateTo == null))
- {
- return new();
- }
if (model.Id.HasValue)
{
return source.Orders
@@ -33,13 +29,21 @@ namespace SecuritySystemFileImplement.Implements
.Select(x => GetViewModel(x))
.ToList();
}
- else
+ else if (model.DateFrom != null && model.DateTo != null)
{
return source.Orders
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => GetViewModel(x))
.ToList();
}
+ else if (model.ClientId.HasValue)
+ {
+ return source.Orders
+ .Where(x => x.ClientId == model.ClientId)
+ .Select(x => GetViewModel(x))
+ .ToList();
+ }
+ return new();
}
public List GetFullList()
{
diff --git a/SecuritySystemFileImplement/Implements/SecureStorage.cs b/SecuritySystemFileImplement/Implements/SecureStorage.cs
index c280cfd..1e149ce 100644
--- a/SecuritySystemFileImplement/Implements/SecureStorage.cs
+++ b/SecuritySystemFileImplement/Implements/SecureStorage.cs
@@ -15,14 +15,14 @@ using SecuritySystemFileImplement;
namespace SecuritySystemFileImplement.Implements
{
- public class SecureStorage : ISecureStorage
+ public class Securestorage : ISecurestorage
{
private readonly DataFileSingleton source;
- public SecureStorage()
+ public Securestorage()
{
source = DataFileSingleton.GetInstance();
}
- public SecureViewModel? GetElement(SecureSearchModel model)
+ public SecureViewModel? GetElement(SecuresearchModel model)
{
if (string.IsNullOrEmpty(model.SecureName) && !model.Id.HasValue)
{
@@ -30,7 +30,7 @@ namespace SecuritySystemFileImplement.Implements
}
return source.Secures.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SecureName) && x.SecureName == model.SecureName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
- public List GetFilteredList(SecureSearchModel model)
+ public List GetFilteredList(SecuresearchModel model)
{
if (string.IsNullOrEmpty(model.SecureName))
{
diff --git a/SecuritySystemFileImplement/Models/Client.cs b/SecuritySystemFileImplement/Models/Client.cs
new file mode 100644
index 0000000..e4dd062
--- /dev/null
+++ b/SecuritySystemFileImplement/Models/Client.cs
@@ -0,0 +1,70 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.ViewModels;
+using SecuritySystemDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace SecuritySystemFileImplement.Models
+{
+ public class Client : IClientModel
+ {
+ public int Id { get; private set; }
+ public string ClientFIO { get; private set; } = string.Empty;
+ public string Email { get; private set; } = string.Empty;
+ public string Password { get; private set; } = string.Empty;
+ public static Client? Create(ClientBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Client()
+ {
+ Id = model.Id,
+ ClientFIO = model.ClientFIO,
+ Email = model.Email,
+ Password = model.Password,
+ };
+ }
+ public static Client? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new Client()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ ClientFIO = element.Element("ClientFIO")!.Value,
+ Email = element.Element("Email")!.Value,
+ Password = element.Element("Password")!.Value
+ };
+ }
+ public void Update(ClientBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ClientFIO = model.ClientFIO;
+ Email = model.Email;
+ Password = model.Password;
+ }
+ public ClientViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ClientFIO = ClientFIO,
+ Email = Email,
+ Password = Password
+ };
+ public XElement GetXElement => new("Client",
+ new XAttribute("Id", Id),
+ new XElement("ClientFIO", ClientFIO),
+ new XElement("Email", Email),
+ new XElement("Password", Password));
+ }
+}
diff --git a/SecuritySystemFileImplement/Models/Order.cs b/SecuritySystemFileImplement/Models/Order.cs
index 61320f2..da649e6 100644
--- a/SecuritySystemFileImplement/Models/Order.cs
+++ b/SecuritySystemFileImplement/Models/Order.cs
@@ -16,6 +16,7 @@ namespace SecuritySystemFileImplement.Models
{
public int Id { get; private set; }
public int SecureId { get; private set; }
+ public int ClientId { get; private set; }
public string SecureName { get; private set; } = string.Empty;
public int Count { get; private set; }
public double Sum { get; private set; }
diff --git a/SecuritySystemListImplement/DataListSingletone.cs b/SecuritySystemListImplement/DataListSingletone.cs
index 7a9a84a..e687c2a 100644
--- a/SecuritySystemListImplement/DataListSingletone.cs
+++ b/SecuritySystemListImplement/DataListSingletone.cs
@@ -13,12 +13,14 @@ namespace SecuritySystemListImplement
private static DataListSingleton? _instance;
public List Components { get; set; }
public List Orders { get; set; }
- public List Securies { get; set; }
+ public List Secures { get; set; }
+ public List Clients { get; set; }
private DataListSingleton()
{
Components = new List();
Orders = new List();
- Securies = new List();
+ Secures = new List();
+ Clients = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/SecuritySystemListImplement/Implements/ClientStorage.cs b/SecuritySystemListImplement/Implements/ClientStorage.cs
new file mode 100644
index 0000000..da94d79
--- /dev/null
+++ b/SecuritySystemListImplement/Implements/ClientStorage.cs
@@ -0,0 +1,109 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.SearchModels;
+using SecuritySystemContracts.StorageContracts;
+using SecuritySystemContracts.ViewModels;
+using SecuritySystemListImplement.Models;
+
+namespace SecuritySystemListImplement.Implements
+{
+ public class ClientStorage : IClientStorage
+ {
+ private readonly DataListSingleton _source;
+ public ClientStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var client in _source.Clients)
+ {
+ result.Add(client.GetViewModel);
+ }
+ return result;
+ }
+ public List GetFilteredList(ClientSearchModel model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.Email))
+ {
+ return result;
+ }
+ foreach (var client in _source.Clients)
+ {
+ if (client.Email.Contains(model.Email))
+ {
+ result.Add(client.GetViewModel);
+ }
+ }
+ return result;
+ }
+ public ClientViewModel? GetElement(ClientSearchModel model)
+ {
+ if (model.Id.HasValue)
+ {
+ foreach (var client in _source.Clients)
+ {
+ if (client.Id == model.Id)
+ {
+ return client.GetViewModel;
+ }
+ }
+ }
+ else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
+ {
+ foreach (var client in _source.Clients)
+ {
+ if (client.Email == model.Email && client.Password == model.Password)
+ {
+ return client.GetViewModel;
+ }
+ }
+ }
+ return null;
+ }
+ public ClientViewModel? Insert(ClientBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var client in _source.Clients)
+ {
+ if (model.Id <= client.Id)
+ {
+ model.Id = client.Id + 1;
+ }
+ }
+ var newClient = Client.Create(model);
+ if (newClient == null)
+ {
+ return null;
+ }
+ _source.Clients.Add(newClient);
+ return newClient.GetViewModel;
+ }
+ public ClientViewModel? Update(ClientBindingModel model)
+ {
+ foreach (var client in _source.Clients)
+ {
+ if (client.Id == model.Id)
+ {
+ client.Update(model);
+ return client.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ClientViewModel? Delete(ClientBindingModel model)
+ {
+ for (int i = 0; i < _source.Clients.Count; ++i)
+ {
+ if (_source.Clients[i].Id == model.Id)
+ {
+ var element = _source.Clients[i];
+ _source.Clients.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/SecuritySystemListImplement/Implements/SecureStorage.cs b/SecuritySystemListImplement/Implements/SecureStorage.cs
index a01cbf9..a1f08a1 100644
--- a/SecuritySystemListImplement/Implements/SecureStorage.cs
+++ b/SecuritySystemListImplement/Implements/SecureStorage.cs
@@ -7,30 +7,30 @@ using SecuritySystemContracts.ViewModels;
namespace SecuritySystemListImplement.Implements
{
- public class SecureStorage : ISecureStorage
+ public class Securestorage : ISecurestorage
{
private readonly DataListSingleton _source;
- public SecureStorage()
+ public Securestorage()
{
_source = DataListSingleton.GetInstance();
}
public List GetFullList()
{
var result = new List();
- foreach (var Secure in _source.Securies)
+ foreach (var Secure in _source.Secures)
{
result.Add(Secure.GetViewModel);
}
return result;
}
- public List GetFilteredList(SecureSearchModel model)
+ public List GetFilteredList(SecuresearchModel model)
{
var result = new List();
if (string.IsNullOrEmpty(model.SecureName))
{
return result;
}
- foreach (var Secure in _source.Securies)
+ foreach (var Secure in _source.Secures)
{
if (Secure.SecureName.Contains(model.SecureName))
{
@@ -39,13 +39,13 @@ namespace SecuritySystemListImplement.Implements
}
return result;
}
- public SecureViewModel? GetElement(SecureSearchModel model)
+ public SecureViewModel? GetElement(SecuresearchModel model)
{
if (string.IsNullOrEmpty(model.SecureName) && !model.Id.HasValue)
{
return null;
}
- foreach (var Secure in _source.Securies)
+ foreach (var Secure in _source.Secures)
{
if ((!string.IsNullOrEmpty(model.SecureName) && Secure.SecureName == model.SecureName) ||
(model.Id.HasValue && Secure.Id == model.Id))
@@ -58,7 +58,7 @@ namespace SecuritySystemListImplement.Implements
public SecureViewModel? Insert(SecureBindingModel model)
{
model.Id = 1;
- foreach (var Secure in _source.Securies)
+ foreach (var Secure in _source.Secures)
{
if (model.Id <= Secure.Id)
{
@@ -70,12 +70,12 @@ namespace SecuritySystemListImplement.Implements
{
return null;
}
- _source.Securies.Add(newSecure);
+ _source.Secures.Add(newSecure);
return newSecure.GetViewModel;
}
public SecureViewModel? Update(SecureBindingModel model)
{
- foreach (var Secure in _source.Securies)
+ foreach (var Secure in _source.Secures)
{
if (Secure.Id == model.Id)
{
@@ -87,12 +87,12 @@ namespace SecuritySystemListImplement.Implements
}
public SecureViewModel? Delete(SecureBindingModel model)
{
- for (int i = 0; i < _source.Securies.Count; ++i)
+ for (int i = 0; i < _source.Secures.Count; ++i)
{
- if (_source.Securies[i].Id == model.Id)
+ if (_source.Secures[i].Id == model.Id)
{
- var element = _source.Securies[i];
- _source.Securies.RemoveAt(i);
+ var element = _source.Secures[i];
+ _source.Secures.RemoveAt(i);
return element.GetViewModel;
}
}
diff --git a/SecuritySystemListImplement/Models/Client.cs b/SecuritySystemListImplement/Models/Client.cs
new file mode 100644
index 0000000..b08db90
--- /dev/null
+++ b/SecuritySystemListImplement/Models/Client.cs
@@ -0,0 +1,50 @@
+using SecuritySystemContracts.BindingModels;
+using SecuritySystemContracts.ViewModels;
+using SecuritySystemDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecuritySystemListImplement.Models
+{
+ public class Client : IClientModel
+ {
+ public int Id { get; private set; }
+ public string ClientFIO { get; private set; } = string.Empty;
+ public string Email { get; private set; } = string.Empty;
+ public string Password { get; private set; } = string.Empty;
+ public static Client? Create(ClientBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Client()
+ {
+ Id = model.Id,
+ ClientFIO = model.ClientFIO,
+ Email = model.Email,
+ Password = model.Password,
+ };
+ }
+ public void Update(ClientBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ClientFIO = model.ClientFIO;
+ Email = model.Email;
+ Password = model.Password;
+ }
+ public ClientViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ClientFIO = ClientFIO,
+ Email = Email,
+ Password = Password
+ };
+ }
+}
diff --git a/SecuritySystemListImplement/Models/Order.cs b/SecuritySystemListImplement/Models/Order.cs
index 1d073ec..cb02f22 100644
--- a/SecuritySystemListImplement/Models/Order.cs
+++ b/SecuritySystemListImplement/Models/Order.cs
@@ -16,16 +16,13 @@ namespace SecuritySystemListImplement.Models
public int Id { get; private set; }
public int SecureId { get; private set; }
-
public string SecureName { get; private set; } = string.Empty;
+ public int ClientId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
-
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
-
public DateTime DateCreate { get; set; } = DateTime.Now;
-
public DateTime? DateImplement { get; set; }
public static Order? Create(OrderBindingModel? model)