diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.Designer.cs
new file mode 100644
index 0000000..884e814
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.Designer.cs
@@ -0,0 +1,125 @@
+namespace BlacksmithWorkshop
+{
+ 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()
+ {
+ dataGridView = new DataGridView();
+ Id = new DataGridViewTextBoxColumn();
+ СlientFIO = new DataGridViewTextBoxColumn();
+ Email = new DataGridViewTextBoxColumn();
+ Password = new DataGridViewTextBoxColumn();
+ buttonDelete = new Button();
+ buttonUpdate = new Button();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // dataGridView
+ //
+ dataGridView.BackgroundColor = SystemColors.ButtonHighlight;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Columns.AddRange(new DataGridViewColumn[] { Id, СlientFIO, Email, Password });
+ dataGridView.Location = new Point(-4, 1);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.Size = new Size(657, 450);
+ dataGridView.TabIndex = 0;
+ //
+ // Id
+ //
+ Id.HeaderText = "Id";
+ Id.MinimumWidth = 6;
+ Id.Name = "Id";
+ Id.Width = 125;
+ //
+ // СlientFIO
+ //
+ СlientFIO.HeaderText = "ФИО клиента";
+ СlientFIO.MinimumWidth = 6;
+ СlientFIO.Name = "СlientFIO";
+ СlientFIO.Width = 125;
+ //
+ // Email
+ //
+ Email.HeaderText = "E-mail";
+ Email.MinimumWidth = 6;
+ Email.Name = "Email";
+ Email.Width = 125;
+ //
+ // Password
+ //
+ Password.HeaderText = "Пароль";
+ Password.MinimumWidth = 6;
+ Password.Name = "Password";
+ Password.Width = 125;
+ //
+ // buttonDelete
+ //
+ buttonDelete.Location = new Point(671, 28);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(94, 29);
+ buttonDelete.TabIndex = 1;
+ buttonDelete.Text = "Удалить";
+ buttonDelete.UseVisualStyleBackColor = true;
+ buttonDelete.Click += ButtonDelete_Click;
+ //
+ // buttonUpdate
+ //
+ buttonUpdate.Location = new Point(671, 84);
+ buttonUpdate.Name = "buttonUpdate";
+ buttonUpdate.Size = new Size(94, 29);
+ buttonUpdate.TabIndex = 2;
+ buttonUpdate.Text = "Обновить";
+ buttonUpdate.UseVisualStyleBackColor = true;
+ buttonUpdate.Click += ButtonUpdate_Click;
+ //
+ // FormClients
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(buttonUpdate);
+ Controls.Add(buttonDelete);
+ Controls.Add(dataGridView);
+ Name = "FormClients";
+ Text = "Клиенты";
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonDelete;
+ private Button buttonUpdate;
+ private DataGridViewTextBoxColumn Id;
+ private DataGridViewTextBoxColumn СlientFIO;
+ private DataGridViewTextBoxColumn Email;
+ private DataGridViewTextBoxColumn Password;
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.cs
new file mode 100644
index 0000000..9ab64db
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.cs
@@ -0,0 +1,90 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using Microsoft.EntityFrameworkCore.Diagnostics;
+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 BlacksmithWorkshop
+{
+ 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 LoadData()
+ {
+ try
+ {
+ var list = _logic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["Id"].Visible = false;
+ dataGridView.Columns["ClientFIO"].AutoSizeMode =
+ DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["Email"].AutoSizeMode =
+ DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ }
+ _logger.LogInformation("Загрузка клиентов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки клиентов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonUpdate_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void ButtonDelete_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);
+ _logger.LogInformation("Удаление клиента");
+ try
+ {
+ if (!_logic.Delete(new ClientBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления клиента");
+ MessageBox.Show(ex.Message, "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.resx
new file mode 100644
index 0000000..073cbb8
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormClients.resx
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
index cb3c202..c2d082e 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
@@ -1,216 +1,217 @@
namespace BlacksmithWorkshop
{
- partial class FormMain
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
+ partial class FormMain
+ {
+ ///
+ /// 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);
- }
+ ///
+ /// 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
+ #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.menuStrip1 = new System.Windows.Forms.MenuStrip();
- this.справочникиToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
- this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.кузнечныеИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.ComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.ComponentsManufactueToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.OrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.dataGridView = new System.Windows.Forms.DataGridView();
- this.buttonCreateOrder = new System.Windows.Forms.Button();
- this.buttonnTakeOrderInWork = new System.Windows.Forms.Button();
- this.buttonOrderReady = new System.Windows.Forms.Button();
- this.buttonIssuedOrder = new System.Windows.Forms.Button();
- this.buttonRef = new System.Windows.Forms.Button();
- this.menuStrip1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
- this.SuspendLayout();
- //
- // menuStrip1
- //
- this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
- this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.справочникиToolStripMenuItem1,
- this.отчётыToolStripMenuItem});
- this.menuStrip1.Location = new System.Drawing.Point(0, 0);
- this.menuStrip1.Name = "menuStrip1";
- this.menuStrip1.Size = new System.Drawing.Size(920, 28);
- this.menuStrip1.TabIndex = 0;
- this.menuStrip1.Text = "menuStrip1";
- //
- // справочникиToolStripMenuItem1
- //
- this.справочникиToolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.компонентыToolStripMenuItem,
- this.кузнечныеИзделияToolStripMenuItem});
- this.справочникиToolStripMenuItem1.Name = "справочникиToolStripMenuItem1";
- this.справочникиToolStripMenuItem1.Size = new System.Drawing.Size(117, 24);
- this.справочникиToolStripMenuItem1.Text = "Справочники";
- //
- // компонентыToolStripMenuItem
- //
- this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
- this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(227, 26);
- this.компонентыToolStripMenuItem.Text = "Компоненты";
- this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
- //
- // кузнечныеИзделияToolStripMenuItem
- //
- this.кузнечныеИзделияToolStripMenuItem.Name = "кузнечныеИзделияToolStripMenuItem";
- this.кузнечныеИзделияToolStripMenuItem.Size = new System.Drawing.Size(227, 26);
- this.кузнечныеИзделияToolStripMenuItem.Text = "КузнечныеИзделия";
- this.кузнечныеИзделияToolStripMenuItem.Click += new System.EventHandler(this.КузнечныеИзделияToolStripMenuItem_Click);
- //
- // отчётыToolStripMenuItem
- //
- this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.ComponentsToolStripMenuItem,
- this.ComponentsManufactueToolStripMenuItem,
- this.OrdersToolStripMenuItem});
- this.отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
- this.отчётыToolStripMenuItem.Size = new System.Drawing.Size(73, 24);
- this.отчётыToolStripMenuItem.Text = "Отчёты";
- //
- // ComponentsToolStripMenuItem
- //
- this.ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem";
- this.ComponentsToolStripMenuItem.Size = new System.Drawing.Size(276, 26);
- this.ComponentsToolStripMenuItem.Text = "Список компонентов";
- this.ComponentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
- //
- // ComponentsManufactueToolStripMenuItem
- //
- this.ComponentsManufactueToolStripMenuItem.Name = "ComponentsManufactueToolStripMenuItem";
- this.ComponentsManufactueToolStripMenuItem.Size = new System.Drawing.Size(276, 26);
- this.ComponentsManufactueToolStripMenuItem.Text = "Компоненты по изделиям";
- this.ComponentsManufactueToolStripMenuItem.Click += new System.EventHandler(this.ComponentsManufactueToolStripMenuItem_Click);
- //
- // OrdersToolStripMenuItem
- //
- this.OrdersToolStripMenuItem.Name = "OrdersToolStripMenuItem";
- this.OrdersToolStripMenuItem.Size = new System.Drawing.Size(276, 26);
- this.OrdersToolStripMenuItem.Text = "Список заказов";
- this.OrdersToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click);
- //
- // dataGridView
- //
- this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
- this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- this.dataGridView.Location = new System.Drawing.Point(12, 31);
- this.dataGridView.Name = "dataGridView";
- this.dataGridView.RowHeadersWidth = 51;
- this.dataGridView.RowTemplate.Height = 29;
- this.dataGridView.Size = new System.Drawing.Size(684, 407);
- this.dataGridView.TabIndex = 1;
- //
- // buttonCreateOrder
- //
- this.buttonCreateOrder.Location = new System.Drawing.Point(721, 55);
- this.buttonCreateOrder.Name = "buttonCreateOrder";
- this.buttonCreateOrder.Size = new System.Drawing.Size(187, 29);
- this.buttonCreateOrder.TabIndex = 2;
- this.buttonCreateOrder.Text = "Создать заказ";
- this.buttonCreateOrder.UseVisualStyleBackColor = true;
- this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
- //
- // buttonnTakeOrderInWork
- //
- this.buttonnTakeOrderInWork.Location = new System.Drawing.Point(721, 111);
- this.buttonnTakeOrderInWork.Name = "buttonnTakeOrderInWork";
- this.buttonnTakeOrderInWork.Size = new System.Drawing.Size(187, 29);
- this.buttonnTakeOrderInWork.TabIndex = 3;
- this.buttonnTakeOrderInWork.Text = "Отдать на выполнение";
- this.buttonnTakeOrderInWork.UseVisualStyleBackColor = true;
- this.buttonnTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
- //
- // buttonOrderReady
- //
- this.buttonOrderReady.Location = new System.Drawing.Point(721, 166);
- this.buttonOrderReady.Name = "buttonOrderReady";
- this.buttonOrderReady.Size = new System.Drawing.Size(187, 29);
- this.buttonOrderReady.TabIndex = 4;
- this.buttonOrderReady.Text = "Заказ готов";
- this.buttonOrderReady.UseVisualStyleBackColor = true;
- this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
- //
- // buttonIssuedOrder
- //
- this.buttonIssuedOrder.Location = new System.Drawing.Point(721, 221);
- this.buttonIssuedOrder.Name = "buttonIssuedOrder";
- this.buttonIssuedOrder.Size = new System.Drawing.Size(187, 29);
- this.buttonIssuedOrder.TabIndex = 5;
- this.buttonIssuedOrder.Text = "Заказ выдан";
- this.buttonIssuedOrder.UseVisualStyleBackColor = true;
- this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
- //
- // buttonRef
- //
- this.buttonRef.Location = new System.Drawing.Point(721, 280);
- this.buttonRef.Name = "buttonRef";
- this.buttonRef.Size = new System.Drawing.Size(187, 29);
- this.buttonRef.TabIndex = 6;
- this.buttonRef.Text = "Обновить список";
- this.buttonRef.UseVisualStyleBackColor = true;
- this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
- //
- // FormMain
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(920, 450);
- this.Controls.Add(this.buttonRef);
- this.Controls.Add(this.buttonIssuedOrder);
- this.Controls.Add(this.buttonOrderReady);
- this.Controls.Add(this.buttonnTakeOrderInWork);
- this.Controls.Add(this.buttonCreateOrder);
- this.Controls.Add(this.dataGridView);
- this.Controls.Add(this.menuStrip1);
- this.MainMenuStrip = this.menuStrip1;
- this.Name = "FormMain";
- this.Text = "Магазин кузнечных изделий";
- this.menuStrip1.ResumeLayout(false);
- this.menuStrip1.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
- this.ResumeLayout(false);
- this.PerformLayout();
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ menuStrip1 = new MenuStrip();
+ справочникиToolStripMenuItem1 = new ToolStripMenuItem();
+ компонентыToolStripMenuItem = new ToolStripMenuItem();
+ кузнечныеИзделияToolStripMenuItem = new ToolStripMenuItem();
+ отчётыToolStripMenuItem = new ToolStripMenuItem();
+ ComponentsToolStripMenuItem = new ToolStripMenuItem();
+ ComponentsManufactueToolStripMenuItem = new ToolStripMenuItem();
+ OrdersToolStripMenuItem = new ToolStripMenuItem();
+ dataGridView = new DataGridView();
+ buttonCreateOrder = new Button();
+ buttonnTakeOrderInWork = new Button();
+ buttonOrderReady = new Button();
+ buttonIssuedOrder = new Button();
+ buttonRef = new Button();
+ клиентыToolStripMenuItem = new ToolStripMenuItem();
+ menuStrip1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // menuStrip1
+ //
+ menuStrip1.ImageScalingSize = new Size(20, 20);
+ menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem1, отчётыToolStripMenuItem });
+ menuStrip1.Location = new Point(0, 0);
+ menuStrip1.Name = "menuStrip1";
+ menuStrip1.Size = new Size(920, 28);
+ menuStrip1.TabIndex = 0;
+ menuStrip1.Text = "menuStrip1";
+ //
+ // справочникиToolStripMenuItem1
+ //
+ справочникиToolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, кузнечныеИзделияToolStripMenuItem, клиентыToolStripMenuItem });
+ справочникиToolStripMenuItem1.Name = "справочникиToolStripMenuItem1";
+ справочникиToolStripMenuItem1.Size = new Size(117, 24);
+ справочникиToolStripMenuItem1.Text = "Справочники";
+ //
+ // компонентыToolStripMenuItem
+ //
+ компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
+ компонентыToolStripMenuItem.Size = new Size(227, 26);
+ компонентыToolStripMenuItem.Text = "Компоненты";
+ компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
+ //
+ // кузнечныеИзделияToolStripMenuItem
+ //
+ кузнечныеИзделияToolStripMenuItem.Name = "кузнечныеИзделияToolStripMenuItem";
+ кузнечныеИзделияToolStripMenuItem.Size = new Size(227, 26);
+ кузнечныеИзделияToolStripMenuItem.Text = "КузнечныеИзделия";
+ кузнечныеИзделияToolStripMenuItem.Click += КузнечныеИзделияToolStripMenuItem_Click;
+ //
+ // отчётыToolStripMenuItem
+ //
+ отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ComponentsManufactueToolStripMenuItem, OrdersToolStripMenuItem });
+ отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
+ отчётыToolStripMenuItem.Size = new Size(73, 24);
+ отчётыToolStripMenuItem.Text = "Отчёты";
+ //
+ // ComponentsToolStripMenuItem
+ //
+ ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem";
+ ComponentsToolStripMenuItem.Size = new Size(276, 26);
+ ComponentsToolStripMenuItem.Text = "Список компонентов";
+ ComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
+ //
+ // ComponentsManufactueToolStripMenuItem
+ //
+ ComponentsManufactueToolStripMenuItem.Name = "ComponentsManufactueToolStripMenuItem";
+ ComponentsManufactueToolStripMenuItem.Size = new Size(276, 26);
+ ComponentsManufactueToolStripMenuItem.Text = "Компоненты по изделиям";
+ ComponentsManufactueToolStripMenuItem.Click += ComponentsManufactueToolStripMenuItem_Click;
+ //
+ // OrdersToolStripMenuItem
+ //
+ OrdersToolStripMenuItem.Name = "OrdersToolStripMenuItem";
+ OrdersToolStripMenuItem.Size = new Size(276, 26);
+ OrdersToolStripMenuItem.Text = "Список заказов";
+ OrdersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
+ //
+ // dataGridView
+ //
+ dataGridView.BackgroundColor = SystemColors.ButtonHighlight;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(12, 31);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.Size = new Size(684, 407);
+ dataGridView.TabIndex = 1;
+ //
+ // buttonCreateOrder
+ //
+ buttonCreateOrder.Location = new Point(721, 55);
+ buttonCreateOrder.Name = "buttonCreateOrder";
+ buttonCreateOrder.Size = new Size(187, 29);
+ buttonCreateOrder.TabIndex = 2;
+ buttonCreateOrder.Text = "Создать заказ";
+ buttonCreateOrder.UseVisualStyleBackColor = true;
+ buttonCreateOrder.Click += ButtonCreateOrder_Click;
+ //
+ // buttonnTakeOrderInWork
+ //
+ buttonnTakeOrderInWork.Location = new Point(721, 111);
+ buttonnTakeOrderInWork.Name = "buttonnTakeOrderInWork";
+ buttonnTakeOrderInWork.Size = new Size(187, 29);
+ buttonnTakeOrderInWork.TabIndex = 3;
+ buttonnTakeOrderInWork.Text = "Отдать на выполнение";
+ buttonnTakeOrderInWork.UseVisualStyleBackColor = true;
+ buttonnTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
+ //
+ // buttonOrderReady
+ //
+ buttonOrderReady.Location = new Point(721, 166);
+ buttonOrderReady.Name = "buttonOrderReady";
+ buttonOrderReady.Size = new Size(187, 29);
+ buttonOrderReady.TabIndex = 4;
+ buttonOrderReady.Text = "Заказ готов";
+ buttonOrderReady.UseVisualStyleBackColor = true;
+ buttonOrderReady.Click += ButtonOrderReady_Click;
+ //
+ // buttonIssuedOrder
+ //
+ buttonIssuedOrder.Location = new Point(721, 221);
+ buttonIssuedOrder.Name = "buttonIssuedOrder";
+ buttonIssuedOrder.Size = new Size(187, 29);
+ buttonIssuedOrder.TabIndex = 5;
+ buttonIssuedOrder.Text = "Заказ выдан";
+ buttonIssuedOrder.UseVisualStyleBackColor = true;
+ buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
+ //
+ // buttonRef
+ //
+ buttonRef.Location = new Point(721, 280);
+ buttonRef.Name = "buttonRef";
+ buttonRef.Size = new Size(187, 29);
+ buttonRef.TabIndex = 6;
+ buttonRef.Text = "Обновить список";
+ buttonRef.UseVisualStyleBackColor = true;
+ buttonRef.Click += ButtonRef_Click;
+ //
+ // клиентыToolStripMenuItem
+ //
+ клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
+ клиентыToolStripMenuItem.Size = new Size(227, 26);
+ клиентыToolStripMenuItem.Text = "Клиенты";
+ клиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click;
+ //
+ // FormMain
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(920, 450);
+ Controls.Add(buttonRef);
+ Controls.Add(buttonIssuedOrder);
+ Controls.Add(buttonOrderReady);
+ Controls.Add(buttonnTakeOrderInWork);
+ Controls.Add(buttonCreateOrder);
+ Controls.Add(dataGridView);
+ Controls.Add(menuStrip1);
+ MainMenuStrip = menuStrip1;
+ Name = "FormMain";
+ Text = "Магазин кузнечных изделий";
+ menuStrip1.ResumeLayout(false);
+ menuStrip1.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
- }
+ #endregion
- #endregion
-
- private MenuStrip menuStrip1;
- private DataGridView dataGridView;
- private Button buttonCreateOrder;
- private ToolStripMenuItem справочникиToolStripMenuItem1;
- private Button buttonnTakeOrderInWork;
- private Button buttonOrderReady;
- private Button buttonIssuedOrder;
- private Button buttonRef;
- private ToolStripMenuItem компонентыToolStripMenuItem;
- private ToolStripMenuItem кузнечныеИзделияToolStripMenuItem;
- private ToolStripMenuItem отчётыToolStripMenuItem;
- private ToolStripMenuItem ComponentsToolStripMenuItem;
- private ToolStripMenuItem ComponentsManufactueToolStripMenuItem;
- private ToolStripMenuItem OrdersToolStripMenuItem;
- }
+ private MenuStrip menuStrip1;
+ private DataGridView dataGridView;
+ private Button buttonCreateOrder;
+ private ToolStripMenuItem справочникиToolStripMenuItem1;
+ private Button buttonnTakeOrderInWork;
+ private Button buttonOrderReady;
+ private Button buttonIssuedOrder;
+ private Button buttonRef;
+ private ToolStripMenuItem компонентыToolStripMenuItem;
+ private ToolStripMenuItem кузнечныеИзделияToolStripMenuItem;
+ private ToolStripMenuItem отчётыToolStripMenuItem;
+ private ToolStripMenuItem ComponentsToolStripMenuItem;
+ private ToolStripMenuItem ComponentsManufactueToolStripMenuItem;
+ private ToolStripMenuItem OrdersToolStripMenuItem;
+ private ToolStripMenuItem клиентыToolStripMenuItem;
+ }
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
index 089135f..946c915 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
@@ -15,227 +15,238 @@ using System.Windows.Forms;
namespace BlacksmithWorkshop
{
- public partial class FormMain : Form
- {
+ public partial class FormMain : Form
+ {
- private readonly ILogger _logger;
- private readonly IOrderLogic _orderLogic;
- IReportLogic _reportLogic;
- public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic)
- {
- InitializeComponent();
- _logger = logger;
- _orderLogic = orderLogic;
- LoadData();
- _reportLogic = reportLogic;
- }
+ private readonly ILogger _logger;
+ private readonly IOrderLogic _orderLogic;
+ IReportLogic _reportLogic;
+ public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _orderLogic = orderLogic;
+ LoadData();
+ _reportLogic = reportLogic;
+ }
- private void FormMain_Load(object sender, EventArgs e)
- {
- LoadData();
- }
- private void LoadData()
- {
- _logger.LogInformation("Загрузка заказов");
- try
- {
- var list = _orderLogic.ReadList(null);
- if (list != null)
- {
- dataGridView.DataSource = list;
- dataGridView.Columns["ManufactureId"].Visible = false;
-
- }
- _logger.LogInformation("Загрузка компонентов");
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Ошибка загрузки компонентов");
- MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
- MessageBoxIcon.Error);
- }
- }
+ private void FormMain_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка заказов");
+ try
+ {
+ var list = _orderLogic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["ManufactureId"].Visible = false;
+
+ }
+ _logger.LogInformation("Загрузка компонентов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки компонентов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
- private void КузнечныеИзделияToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var service = Program.ServiceProvider?.GetService(typeof(FormManufactures));
- if (service is FormManufactures form)
- {
- form.ShowDialog();
- }
-
- }
+ private void КузнечныеИзделияToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormManufactures));
+ if (service is FormManufactures form)
+ {
+ form.ShowDialog();
+ }
- private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
- if (service is FormComponents form)
- {
- form.ShowDialog();
- }
- }
+ }
- private void ButtonCreateOrder_Click(object sender, EventArgs e)
- {
- var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
- if (service is FormCreateOrder form)
- {
- form.ShowDialog();
- LoadData();
- }
- }
+ private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
+ if (service is FormComponents form)
+ {
+ form.ShowDialog();
+ }
+ }
- private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
- {
- if (dataGridView.SelectedRows.Count == 1)
- {
- int id =
- Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
- _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
- try
- {
- var operationResult = _orderLogic.TakeOrderInWork(new
- OrderBindingModel
- { Id = id,
- ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
- ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].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())
-
+ private void ButtonCreateOrder_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
+ if (service is FormCreateOrder form)
+ {
+ form.ShowDialog();
+ LoadData();
+ }
+ }
- });
- if (!operationResult)
- {
- throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
- }
- LoadData();
-
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Ошибка передачи заказа в работу");
- MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
- MessageBoxIcon.Error);
- }
- }
- }
-
- private void ButtonOrderReady_Click(object sender, EventArgs e)
- {
- if (dataGridView.SelectedRows.Count == 1)
- {
- int id =
- Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
- _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'",
- id);
- try
- {
- var operationResult = _orderLogic.FinishOrder(new
- OrderBindingModel
- {
- Id = id,
- ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
- ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].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())
- });
- if (!operationResult)
- {
- throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
- }
- LoadData();
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Ошибка отметки о готовности заказа");
- MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
+ private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ int id =
+ Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
+ try
+ {
+ var operationResult = _orderLogic.TakeOrderInWork(new
+ OrderBindingModel
+ {
+ Id = id,
+ ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
+ ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].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())
- }
+ });
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ LoadData();
- private void ButtonIssuedOrder_Click(object sender, EventArgs e)
- {
- if (dataGridView.SelectedRows.Count == 1)
- {
- int id =
- Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
- _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'",
- id);
- try
- {
- var operationResult = _orderLogic.DeliveryOrder(new
- OrderBindingModel
- {
- Id = id,
- ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
- Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
- ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].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())
- });
- if (!operationResult)
- {
- throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
- }
- _logger.LogInformation("Заказ №{id} выдан", id);
- LoadData();
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Ошибка отметки о выдачи заказа");
- MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
- MessageBoxIcon.Error);
- }
- }
- }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка передачи заказа в работу");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
- private void ButtonRef_Click(object sender, EventArgs e)
- {
- LoadData();
+ private void ButtonOrderReady_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ int id =
+ Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'",
+ id);
+ try
+ {
+ var operationResult = _orderLogic.FinishOrder(new
+ OrderBindingModel
+ {
+ Id = id,
+ ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
+ ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].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())
+ });
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка отметки о готовности заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
- }
- private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
- {
- using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- _reportLogic.SaveComponentsToWordFile(new ReportBindingModel
- {
- FileName = dialog.FileName
- });
- MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK,
- MessageBoxIcon.Information);
- }
+ }
- }
+ private void ButtonIssuedOrder_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ int id =
+ Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'",
+ id);
+ try
+ {
+ var operationResult = _orderLogic.DeliveryOrder(new
+ OrderBindingModel
+ {
+ Id = id,
+ ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
+ Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
+ ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].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())
+ });
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ _logger.LogInformation("Заказ №{id} выдан", id);
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка отметки о выдачи заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
- private void ComponentsManufactueToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var service =
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+
+ }
+
+ private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ _reportLogic.SaveComponentsToWordFile(new ReportBindingModel
+ {
+ FileName = dialog.FileName
+ });
+ MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK,
+ MessageBoxIcon.Information);
+ }
+
+ }
+
+ private void ComponentsManufactueToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service =
Program.ServiceProvider?.GetService(typeof(FormReportManufactureComponents));
- if (service is FormReportManufactureComponents form)
- {
- form.ShowDialog();
- }
- }
+ if (service is FormReportManufactureComponents form)
+ {
+ form.ShowDialog();
+ }
+ }
- private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var service =
+ private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service =
Program.ServiceProvider?.GetService(typeof(FormReportOrders));
- if (service is FormReportOrders form)
- {
- form.ShowDialog();
- }
- }
- }
+ if (service is FormReportOrders form)
+ {
+ form.ShowDialog();
+ }
+ }
+
+ private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service =
+Program.ServiceProvider?.GetService(typeof(FormClients));
+ if (service is FormClients form)
+ {
+ form.ShowDialog();
+ }
+ }
+ }
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
index 8c82ab3..ae55b43 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
@@ -60,6 +60,7 @@ namespace BlacksmithWorkshop
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs
index 5a07914..7dfe420 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs
@@ -1,7 +1,9 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
+using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -12,29 +14,115 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
{
public class ClientLogic : IClientLogic
{
- public bool Create(ClientBindingModel model)
+ private readonly ILogger _logger;
+ private readonly IClientStorage _clientStorage;
+ public ClientLogic(ILogger logger, IClientStorage
+ clientStorage)
+ {
+ _logger = logger;
+ _clientStorage = clientStorage;
+ }
+ public bool Create(ClientBindingModel model)
{
- throw new NotImplementedException();
- }
+ CheckModel(model);
+ if (_clientStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+
+ }
public bool Delete(ClientBindingModel model)
{
- throw new NotImplementedException();
- }
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_clientStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
public ClientViewModel? ReadElement(ClientSearchModel model)
{
- throw new NotImplementedException();
- }
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. ClientFIO:{ ClientFIO}. ClientEmail:{ ClientEmail}. Id:{ Id}", model.ClientFIO, model.Email, 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 List? ReadList(ClientSearchModel? model)
{
- throw new NotImplementedException();
- }
+ _logger.LogInformation("ReadElement. ClientFIO:{ ClientFIO}. ClientEmail:{ ClientEmail}. Id:{ Id}", model.ClientFIO, model.Email, 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 bool Update(ClientBindingModel model)
{
- throw new NotImplementedException();
- }
- }
+ CheckModel(model);
+ if (_clientStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update 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("Введите E-Mail",
+ nameof(model.Email));
+ }
+ if (string.IsNullOrEmpty(model.Password))
+ {
+ throw new ArgumentNullException("Введите пароль",
+ nameof(model.Password));
+ }
+
+ _logger.LogInformation("Client. Client:{ClientFIO}. Email:{ Email}. Id: { Id}", model.ClientFIO, model.Email, model.Id);
+ var element = _clientStorage.GetElement(new ClientSearchModel
+ {
+ Email = model.Email
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Данный e-mail уже зарегистрирован");
+ }
+ }
+ }
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs
index 073af43..8e70a50 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs
@@ -27,5 +27,10 @@ namespace BlacksmithWorkshopContracts.ViewModels
public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; }
- }
+ public int ClientId { get; set; }
+ [DisplayName("Клиент")]
+ public string ClientFIO { get; set;} = string.Empty;
+
+
+ }
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModel/Models/IOrderModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModel/Models/IOrderModel.cs
index 4f870b9..d22f8f0 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDataModel/Models/IOrderModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModel/Models/IOrderModel.cs
@@ -15,5 +15,6 @@ namespace BlacksmithWorkshopDataModel.Models
OrderStatus Status { get; }
DateTime DateCreate { get; }
DateTime? DateImplement { get; }
- }
+ int ClientId { get; }
+ }
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs
index 1de51a2..60fc240 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDatabase.cs
@@ -23,6 +23,7 @@ optionsBuilder)
public virtual DbSet Manufactures { set; get; }
public virtual DbSet ManufactureComponents { set; get; }
public virtual DbSet Orders { set; get; }
+ public virtual DbSet Clients { set; get; }
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ClientStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ClientStorage.cs
index 91087c0..7237c29 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ClientStorage.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ClientStorage.cs
@@ -2,6 +2,7 @@
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -14,28 +15,67 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
{
public ClientViewModel? Delete(ClientBindingModel model)
{
- throw new NotImplementedException();
- }
+ using var context = new BlacksmithWorkshopDatabase();
+ var element = context.Clients.FirstOrDefault(rec => rec.Id ==
+ model.Id);
+ if (element != null)
+ {
+ context.Clients.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
public ClientViewModel? GetElement(ClientSearchModel model)
{
- throw new NotImplementedException();
- }
+ if (string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Clients
+ .FirstOrDefault(x =>
+ (!string.IsNullOrEmpty(model.Email) && x.Email ==
+ model.Email) ||
+ (model.Id.HasValue && x.Id == model.Id))
+ ?.GetViewModel;
+ }
public List GetFilteredList(ClientSearchModel model)
{
- throw new NotImplementedException();
- }
+ if (string.IsNullOrEmpty(model.Email) || !model.Id.HasValue)
+ {
+ return new();
+ }
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Clients
+ .Where(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
public List GetFullList()
{
- throw new NotImplementedException();
- }
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Clients
+ .ToList()
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
public ClientViewModel? Insert(ClientBindingModel model)
{
- throw new NotImplementedException();
- }
+ var newClient = Client.Create(model);
+ if (newClient == null)
+ {
+ return null;
+ }
+ using var context = new BlacksmithWorkshopDatabase();
+ context.Clients.Add(newClient);
+ context.SaveChanges();
+ return newClient.GetViewModel;
+ }
public ClientViewModel? Update(ClientBindingModel model)
{
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs
index 970072e..f4ff11e 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs
@@ -50,7 +50,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
}
using var context = new BlacksmithWorkshopDatabase();
return context.Orders
- .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
+ .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || model.ClientId == x.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Client.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Client.cs
new file mode 100644
index 0000000..0288a60
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Client.cs
@@ -0,0 +1,68 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModel.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BlacksmithWorkshopDatabaseImplement.Models
+{
+ public class Client : IClientModel
+ {
+ public int Id { get; private set; }
+ [Required]
+ public string ClientFIO { get; private set; } = string.Empty;
+ [Required]
+ public string Email { get; private set; } = string.Empty;
+ [Required]
+ 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(ClientViewModel model)
+ {
+ 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/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs
index 2e0b5fc..a523657 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs
@@ -4,6 +4,7 @@ using BlacksmithWorkshopDataModel.Enums;
using BlacksmithWorkshopDataModel.Models;
using System;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -13,6 +14,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
{
public class Order : IOrderModel
{
+ public int Id { get; private set; }
public int ManufactureId { get; private set; }
public int Count { get; private set; }
@@ -25,9 +27,12 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
public DateTime? DateImplement { get; private set; }
- public int Id { get; private set; }
-
- public static Order? Create(OrderBindingModel model)
+ [Required]
+ public int ClientId { get; private set; }
+
+
+
+ public static Order? Create(OrderBindingModel model)
{
if (model == null)
{
@@ -42,7 +47,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
- DateImplement = model.DateImplement
+ DateImplement = model.DateImplement,
+ ClientId = model.ClientId
};
@@ -62,9 +68,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
+ ClientId = model.ClientId;
- }
+
+ }
public OrderViewModel GetViewModel => new()
{
Id = Id,
@@ -74,7 +82,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
- DateImplement = DateImplement
- };
- }
+ DateImplement = DateImplement,
+ ClientId = ClientId
+ };
+
+
+ }
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs
index 738f39c..360d2d0 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs
@@ -14,10 +14,12 @@ namespace BlacksmithWorkshopFileImplement
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string ManufactureFileName = "Manufacture.xml";
- public List Components { get; private set; }
+ private readonly string ClientFileName = "Client.xml";
+ public List Components { get; private set; }
public List Orders { get; private set; }
public List Manufactures { get; private set; }
- public static DataFileSingleton GetInstance()
+ public List Clients { get; private set; }
+ public static DataFileSingleton GetInstance()
{
if (instance == null)
{
@@ -30,14 +32,17 @@ namespace BlacksmithWorkshopFileImplement
public void SaveManufactures() => SaveData(Manufactures, ManufactureFileName,
"Manufactures", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
- private DataFileSingleton()
+ public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
+ private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x =>
Component.Create(x)!)!;
Manufactures = LoadData(ManufactureFileName, "Manufacture", x =>
Manufacture.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/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs
index 8c81a04..57783b7 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs
@@ -2,6 +2,7 @@
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -12,34 +13,82 @@ namespace BlacksmithWorkshopFileImplement.Implements
{
public class ClientStorage : IClientStorage
{
- public ClientViewModel? Delete(ClientBindingModel model)
+ private readonly DataFileSingleton source;
+ public ClientStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+ public ClientViewModel? Delete(ClientBindingModel model)
{
- throw new NotImplementedException();
- }
+ var element = source.Clients.FirstOrDefault(x => x.Id ==
+ model.Id);
+ if (element != null)
+ {
+ source.Clients.Remove(element);
+ source.SaveClients();
+ return element.GetViewModel;
+ }
+ return null;
+ }
public ClientViewModel? GetElement(ClientSearchModel model)
{
- throw new NotImplementedException();
- }
+ if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ return source.Clients
+ .FirstOrDefault(x =>
+ (!string.IsNullOrEmpty(model.Email) && x.Email ==
+ model.Email) ||
+ (model.Id.HasValue && x.Id == model.Id))
+ ?.GetViewModel;
+ }
public List GetFilteredList(ClientSearchModel model)
{
- throw new NotImplementedException();
- }
+ if (string.IsNullOrEmpty(model.Email))
+ {
+ return new();
+ }
+ return source.Clients
+ .Where(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
public List GetFullList()
{
- throw new NotImplementedException();
- }
+ return source.Clients
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
public ClientViewModel? Insert(ClientBindingModel model)
{
- throw new NotImplementedException();
- }
+ 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)
{
- throw new NotImplementedException();
- }
+ var client = source.Clients.FirstOrDefault(x => x.Id ==
+ model.Id);
+ if (client == null)
+ {
+ return null;
+ }
+ client.Update(model);
+ source.SaveComponents();
+ return client.GetViewModel;
+ }
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs
index df61cb1..8c41a73 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs
@@ -49,7 +49,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
return new();
}
return source.Orders
- .Where(x => x.Id == model.Id)
+ .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Client.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Client.cs
new file mode 100644
index 0000000..90e4c1c
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Client.cs
@@ -0,0 +1,76 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModel.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace BlacksmithWorkshopFileImplement.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/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs
index c43a5a6..6028159 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs
@@ -27,6 +27,7 @@ namespace BlacksmithWorkshopFileImplement.Models
public DateTime? DateImplement { get; private set; }
public int Id { get; private set; }
+ public int ClientId { get; private set; }
public static Order? Create(OrderBindingModel model)
{
if (model == null)
@@ -42,7 +43,8 @@ namespace BlacksmithWorkshopFileImplement.Models
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
- DateImplement = model.DateImplement
+ DateImplement = model.DateImplement,
+ ClientId = model.ClientId
};
@@ -62,8 +64,9 @@ namespace BlacksmithWorkshopFileImplement.Models
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
- DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value)
- };
+ DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value),
+ ClientId = Convert.ToInt32(element.Element("ClientId")!.Value)
+ };
}
public void Update(OrderBindingModel model)
{
@@ -79,9 +82,10 @@ namespace BlacksmithWorkshopFileImplement.Models
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
+ ClientId = model.ClientId;
- }
+ }
public OrderViewModel GetViewModel => new()
{
Id = Id,
@@ -91,8 +95,10 @@ namespace BlacksmithWorkshopFileImplement.Models
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
- DateImplement = DateImplement
- };
+ DateImplement = DateImplement,
+
+ ClientId = ClientId
+ };
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("ManufactureId", ManufactureId),
@@ -101,7 +107,8 @@ namespace BlacksmithWorkshopFileImplement.Models
new XElement("Sum", Sum.ToString()),
new XElement("Status", ((int)Status).ToString()),
new XElement("DateCreate", DateCreate.ToString()),
- new XElement("DateImplement", DateImplement.ToString()));
+ new XElement("DateImplement", DateImplement.ToString()),
+ new XElement("ClientId", ClientId));
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs
index 4106e9f..9d4df92 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs
@@ -13,11 +13,13 @@ namespace BlacksmithWorkshopListImplement
public List Components { get; set; }
public List Orders { get; set; }
public List Manufactures { get; set; }
- private DataListSingleton()
+ public List Clients { get; set; }
+ private DataListSingleton()
{
Components = new List();
Orders = new List();
Manufactures = new List();
+ Clients = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs
index 4d34d6d..2005398 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs
@@ -2,6 +2,7 @@
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -11,35 +12,102 @@ using System.Threading.Tasks;
namespace BlacksmithWorkshopListImplement.Implements
{
public class ClientStorage : IClientStorage
+
{
- public ClientViewModel? Delete(ClientBindingModel model)
+ private readonly DataListSingleton _source;
+ public ClientStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public ClientViewModel? Delete(ClientBindingModel model)
{
- throw new NotImplementedException();
- }
+ 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;
+ }
public ClientViewModel? GetElement(ClientSearchModel model)
{
- throw new NotImplementedException();
- }
+ if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var client in _source.Clients)
+ {
+ if ((!string.IsNullOrEmpty(model.Email) &&
+ client.Email == model.Email) ||
+ (model.Id.HasValue && client.Id == model.Id))
+ {
+ return client.GetViewModel;
+ }
+ }
+ return null;
+ }
public List GetFilteredList(ClientSearchModel model)
{
- throw new NotImplementedException();
- }
+ var result = new List();
+ if (string.IsNullOrEmpty(model.Email))
+ {
+ return result;
+ }
+ foreach (var client in _source.Clients)
+ {
+ if (client.Email.Equals(model.Email) && client.Password.Equals(model.Password))
+ {
+ result.Add(client.GetViewModel);
+ }
+ }
+ return result;
+ }
public List GetFullList()
{
- throw new NotImplementedException();
- }
+ var result = new List();
+ foreach (var client in _source.Clients)
+ {
+ result.Add(client.GetViewModel);
+ }
+ return result;
+ }
public ClientViewModel? Insert(ClientBindingModel model)
{
- throw new NotImplementedException();
- }
+ model.Id = 1;
+ foreach (var client in _source.Clients)
+ {
+ if (model.Id <= client.Id)
+ {
+ model.Id = client.Id + 1;
+ }
+ }
+ var newClients = Client.Create(model);
+ if (newClients == null)
+ {
+ return null;
+ }
+ _source.Clients.Add(newClients);
+ return newClients.GetViewModel;
+ }
public ClientViewModel? Update(ClientBindingModel model)
{
- throw new NotImplementedException();
- }
+ foreach (var client in _source.Clients)
+ {
+ if (client.Id == model.Id)
+ {
+ client.Update(model);
+ return client.GetViewModel;
+ }
+ }
+ return null;
+ }
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs
index b31c2dd..9066413 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs
@@ -59,7 +59,7 @@ namespace BlacksmithWorkshopListImplement.Implements
foreach (var order in _source.Orders)
{
- if (order.Id == model.Id )/*|| model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo)*/
+ if (order.Id == model.Id && model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo || order.ClientId == model.ClientId)
{
result.Add(order.GetViewModel);
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Client.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Client.cs
new file mode 100644
index 0000000..9b42749
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Client.cs
@@ -0,0 +1,54 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModel.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BlacksmithWorkshopListImplement.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/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs
index 6a2e8d4..9ad5391 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs
@@ -31,6 +31,7 @@ namespace BlacksmithWorkshopListImplement.Models
public int Id { get; set; }
+
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
@@ -46,7 +47,8 @@ namespace BlacksmithWorkshopListImplement.Models
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
ManufactureId = model.ManufactureId,
- ManufactureName = model.ManufactureName
+ ManufactureName = model.ManufactureName,
+ ClientId = model.ClientId
};
}
public void Update(OrderBindingModel? model)
@@ -63,6 +65,7 @@ namespace BlacksmithWorkshopListImplement.Models
DateImplement = model.DateImplement;
ManufactureId = model.ManufactureId;
ManufactureName = model.ManufactureName;
+ ClientId = model.ClientId;
}
public OrderViewModel GetViewModel => new()
{
@@ -73,7 +76,10 @@ namespace BlacksmithWorkshopListImplement.Models
DateCreate = DateCreate,
DateImplement = DateImplement,
ManufactureId = ManufactureId,
- ManufactureName = ManufactureName
+ ManufactureName = ManufactureName,
+ ClientId = ClientId
};
- }
+
+ public int ClientId { get; set; }
+ }
}