diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormClients.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormClients.Designer.cs
new file mode 100644
index 0000000..d81fc81
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormClients.Designer.cs
@@ -0,0 +1,90 @@
+namespace PrecastConcretePlantView
+{
+ 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.buttonRef = new System.Windows.Forms.Button();
+ this.buttonDel = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(12, 3);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowTemplate.Height = 25;
+ this.dataGridView.Size = new System.Drawing.Size(566, 327);
+ this.dataGridView.TabIndex = 6;
+ //
+ // buttonRef
+ //
+ this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRef.Location = new System.Drawing.Point(650, 70);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(90, 37);
+ this.buttonRef.TabIndex = 11;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ //
+ // buttonDel
+ //
+ this.buttonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDel.Location = new System.Drawing.Point(650, 15);
+ this.buttonDel.Name = "buttonDel";
+ this.buttonDel.Size = new System.Drawing.Size(90, 33);
+ this.buttonDel.TabIndex = 10;
+ this.buttonDel.Text = "Удалить";
+ this.buttonDel.UseVisualStyleBackColor = true;
+ //
+ // FormClients
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(752, 342);
+ this.Controls.Add(this.buttonRef);
+ this.Controls.Add(this.buttonDel);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormClients";
+ this.Text = "FormClients";
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonRef;
+ private Button buttonDel;
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormClients.cs b/PrecastConcretePlant/PrecastConcretePlant/FormClients.cs
new file mode 100644
index 0000000..e9f291d
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormClients.cs
@@ -0,0 +1,84 @@
+using Microsoft.Extensions.Logging;
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.BusinessLogicsContracts;
+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 PrecastConcretePlantView
+{
+ 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 FormViewClients_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);
+ _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);
+ }
+ }
+ }
+ }
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormClients.resx b/PrecastConcretePlant/PrecastConcretePlant/FormClients.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormClients.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs
index 7525c24..8ce8f67 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs
@@ -42,6 +42,7 @@
this.pastriesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.pastryComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@@ -128,7 +129,8 @@
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.reinforcedToolStripMenuItem,
- this.componentToolStripMenuItem});
+ this.componentToolStripMenuItem,
+ this.clientsToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.справочникиToolStripMenuItem.Text = "Справочники";
@@ -136,14 +138,14 @@
// reinforcedToolStripMenuItem
//
this.reinforcedToolStripMenuItem.Name = "reinforcedToolStripMenuItem";
- this.reinforcedToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
+ this.reinforcedToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.reinforcedToolStripMenuItem.Text = "Изделия";
this.reinforcedToolStripMenuItem.Click += new System.EventHandler(this.ReinforcedToolStripMenuItem_Click);
//
// componentToolStripMenuItem
//
this.componentToolStripMenuItem.Name = "componentToolStripMenuItem";
- this.componentToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
+ this.componentToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.componentToolStripMenuItem.Text = "Компоненты";
this.componentToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
@@ -178,6 +180,13 @@
this.ordersToolStripMenuItem.Text = "Список заказов";
this.ordersToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click);
//
+ // clientsToolStripMenuItem
+ //
+ this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
+ this.clientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.clientsToolStripMenuItem.Text = "Клиенты";
+ this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
+ //
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@@ -217,5 +226,6 @@
private ToolStripMenuItem pastriesToolStripMenuItem;
private ToolStripMenuItem pastryComponentsToolStripMenuItem;
private ToolStripMenuItem ordersToolStripMenuItem;
+ private ToolStripMenuItem clientsToolStripMenuItem;
}
}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs
index e1869de..f709908 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs
@@ -35,8 +35,9 @@ namespace PrecastConcretePlantView
dataGridView.DataSource = list;
dataGridView.Columns["Id"].HeaderText = "Номер заказа";
dataGridView.Columns["ReinforcedId"].Visible = false;
- dataGridView.Columns["ReinforcedName"].AutoSizeMode =
- DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["ClientId"].Visible = false;
+ dataGridView.Columns["ReinforcedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка заказов");
}
@@ -184,5 +185,14 @@ namespace PrecastConcretePlantView
form.ShowDialog();
}
}
+
+ private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormClients));
+ if (service is FormClients form)
+ {
+ form.ShowDialog();
+ }
+ }
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/PrecastConcretePlant/Program.cs
index 326a72d..a914093 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/Program.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/Program.cs
@@ -9,7 +9,6 @@ using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using PrecastConcretePlantBusinessLogic.OfficePackage.Implement;
using PrecastConcretePlantBusinessLogic.OfficePackage;
-using PrecastConcretePlantBusinessLogic;
namespace PrecastConcretePlant
@@ -47,6 +46,8 @@ namespace PrecastConcretePlant
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -61,6 +62,7 @@ namespace PrecastConcretePlant
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ClientLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ClientLogic.cs
new file mode 100644
index 0000000..7061b8b
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ClientLogic.cs
@@ -0,0 +1,115 @@
+using Microsoft.Extensions.Logging;
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.BusinessLogicsContracts;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.StoragesContract;
+using PrecastConcretePlantContracts.ViewModels;
+
+namespace PrecastConcretePlantBusinessLogic.BusinessLogic
+{
+ public class ClientLogic : IClientLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IClientStorage _clientStorage;
+ public ClientLogic(ILogger logger, IClientStorage clientStorage)
+ {
+ _logger = logger;
+ _clientStorage = clientStorage;
+ }
+
+ public bool Create(ClientBindingModel model)
+ {
+ CheckModel(model);
+ if (_clientStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert 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;
+ }
+
+ public ClientViewModel? ReadElement(ClientSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. Email:{Email}.Id:{ Id}",
+ 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)
+ {
+ _logger.LogInformation("ReadList. Email:{Email}.Id:{ Id} ", 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)
+ {
+ 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("Нет логина клиента", nameof(model.Email));
+ }
+ _logger.LogInformation("Client. Id: {Id}, FIO: {fio}, email: {email}", model.Id, model.ClientFIO, model.Email);
+ var element = _clientStorage.GetElement(new ClientSearchModel
+ {
+ Email = model.Email,
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Клиент с таким логином уже есть");
+ }
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ComponentLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ComponentLogic.cs
similarity index 100%
rename from PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ComponentLogic.cs
rename to PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ComponentLogic.cs
diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs
similarity index 100%
rename from PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs
rename to PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs
diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ReinforcedLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReinforcedLogic.cs
similarity index 100%
rename from PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ReinforcedLogic.cs
rename to PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReinforcedLogic.cs
diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ReportLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs
similarity index 98%
rename from PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ReportLogic.cs
rename to PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs
index b858c00..96d0db5 100644
--- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ReportLogic.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ReportLogic.cs
@@ -11,7 +11,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace PrecastConcretePlantBusinessLogic
+namespace PrecastConcretePlantBusinessLogic.BusinessLogic
{
public class ReportLogic : IReportLogic
{
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ClientBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ClientBindingModel.cs
new file mode 100644
index 0000000..c14a353
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ClientBindingModel.cs
@@ -0,0 +1,12 @@
+using PrecastConcretePlantDataModels;
+
+namespace PrecastConcretePlantContracts.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;
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs
index 522fe37..ed2ee53 100644
--- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs
@@ -7,6 +7,7 @@ namespace PrecastConcretePlantContracts.BindingModels
{
public int Id { get; set; }
public int ReinforcedId { get; set; }
+ public int ClientId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IClientLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IClientLogic.cs
new file mode 100644
index 0000000..0b96541
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IClientLogic.cs
@@ -0,0 +1,15 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.ViewModels;
+
+namespace PrecastConcretePlantContracts.BusinessLogicsContracts
+{
+ public interface IClientLogic
+ {
+ List? ReadList(ClientSearchModel? model);
+ ClientViewModel? ReadElement(ClientSearchModel model);
+ bool Create(ClientBindingModel model);
+ bool Update(ClientBindingModel model);
+ bool Delete(ClientBindingModel model);
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ClientSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ClientSearchModel.cs
new file mode 100644
index 0000000..3f44f82
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ClientSearchModel.cs
@@ -0,0 +1,11 @@
+namespace PrecastConcretePlantContracts.SearchModels
+{
+ public class ClientSearchModel
+ {
+ public int? Id { get; set; }
+
+ public string? Email { get; set; }
+
+ public string? Password { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs
index d032997..f0a18e3 100644
--- a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs
@@ -5,5 +5,6 @@
public int? Id { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
+ public int? ClientId { get; set; }
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IClientStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IClientStorage.cs
new file mode 100644
index 0000000..32b2146
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IClientStorage.cs
@@ -0,0 +1,16 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.ViewModels;
+
+namespace PrecastConcretePlantContracts.StoragesContract
+{
+ 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);
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ClientViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ClientViewModel.cs
new file mode 100644
index 0000000..968d07d
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ClientViewModel.cs
@@ -0,0 +1,16 @@
+using PrecastConcretePlantDataModels;
+using System.ComponentModel;
+
+namespace PrecastConcretePlantContracts.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;
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs
index fe09ad6..0aca3a4 100644
--- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs
@@ -9,10 +9,11 @@ namespace PrecastConcretePlantContracts.ViewModels
[DisplayName("Номер")]
public int Id { get; set; }
public int ReinforcedId { get; set; }
-
+ public int ClientId { get; set; }
+ [DisplayName("Фамилия клиента")]
+ public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Изделие")]
public string ReinforcedName { get; set; } = string.Empty;
-
[DisplayName("Количество")]
public int Count { get; set; }
diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/IClientModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/IClientModel.cs
new file mode 100644
index 0000000..f02d85d
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/IClientModel.cs
@@ -0,0 +1,9 @@
+namespace PrecastConcretePlantDataModels
+{
+ public interface IClientModel : IId
+ {
+ string ClientFIO { get; }
+ string Email { get; }
+ string Password { get; }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Client.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Client.cs
new file mode 100644
index 0000000..b754a28
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Client.cs
@@ -0,0 +1,60 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.ComponentModel.DataAnnotations;
+using PrecastConcretePlantDatabaseImplement.Models;
+
+namespace PrecastConcretePlantDatabaseImplement
+{
+ public class Client : IClientModel
+ {
+ [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 int Id { get; private set; }
+
+ [ForeignKey("ClientId")]
+ public virtual List Orders { get; set; } = new();
+
+ public static Client? Create(ClientBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ 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/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/ClientStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/ClientStorage.cs
new file mode 100644
index 0000000..a23ece1
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/ClientStorage.cs
@@ -0,0 +1,87 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.StoragesContract;
+using PrecastConcretePlantContracts.ViewModels;
+
+namespace PrecastConcretePlantDatabaseImplement
+{
+ public class ClientStorage : IClientStorage
+ {
+
+ public ClientViewModel? Delete(ClientBindingModel model)
+ {
+ using var context = new PrecastConcretePlantDatabase();
+ var res = context.Clients.FirstOrDefault(x => x.Id == model.Id);
+ if (res != null)
+ {
+ context.Clients.Remove(res);
+ context.SaveChanges();
+ }
+ return res?.GetViewModel;
+ }
+
+ public ClientViewModel? GetElement(ClientSearchModel model)
+ {
+ using var context = new PrecastConcretePlantDatabase();
+ if (model.Id.HasValue)
+ return context.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
+ if (model.Email != null && model.Password != null)
+ return context.Clients
+ .FirstOrDefault(x => x.Email.Equals(model.Email)
+ && x.Password.Equals(model.Password))
+ ?.GetViewModel;
+ if (model.Email != null)
+ return context.Clients.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel;
+ return null;
+ }
+
+ public List GetFilteredList(ClientSearchModel model)
+ {
+ if (model == null)
+ {
+ return new();
+ }
+ if (model.Id.HasValue)
+ {
+ var res = GetElement(model);
+ return res != null ? new() { res } : new();
+ }
+ if (model.Email != null)
+ {
+ using var context = new PrecastConcretePlantDatabase();
+ return context.Clients
+ .Where(x => x.Email.Contains(model.Email))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ return new();
+ }
+
+ public List GetFullList()
+ {
+ using var context = new PrecastConcretePlantDatabase();
+ return context.Clients.Select(x => x.GetViewModel).ToList();
+ }
+
+ public ClientViewModel? Insert(ClientBindingModel model)
+ {
+ using var context = new PrecastConcretePlantDatabase();
+ var res = Client.Create(model);
+ if (res != null)
+ {
+ context.Clients.Add(res);
+ context.SaveChanges();
+ }
+ return res?.GetViewModel;
+ }
+
+ public ClientViewModel? Update(ClientBindingModel model)
+ {
+ using var context = new PrecastConcretePlantDatabase();
+ var res = context.Clients.FirstOrDefault(x => x.Id == model.Id);
+ res?.Update(model);
+ context.SaveChanges();
+ return res?.GetViewModel;
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230402164750_AddClient.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230402164750_AddClient.Designer.cs
new file mode 100644
index 0000000..f227c94
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230402164750_AddClient.Designer.cs
@@ -0,0 +1,214 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using PrecastConcretePlantDatabaseImplement;
+
+#nullable disable
+
+namespace PrecastConcretePlantDatabaseImplement.Migrations
+{
+ [DbContext(typeof(PrecastConcretePlantDatabase))]
+ [Migration("20230402164750_AddClient")]
+ partial class AddClient
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ClientFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Email")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Clients");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ComponentName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Cost")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.ToTable("Components");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ClientId")
+ .HasColumnType("int");
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("DateCreate")
+ .HasColumnType("datetime2");
+
+ b.Property("DateImplement")
+ .HasColumnType("datetime2");
+
+ b.Property("ReinforcedId")
+ .HasColumnType("int");
+
+ b.Property("Status")
+ .HasColumnType("int");
+
+ b.Property("Sum")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ClientId");
+
+ b.HasIndex("ReinforcedId");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Price")
+ .HasColumnType("float");
+
+ b.Property("ReinforcedName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Reinforceds");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ComponentId")
+ .HasColumnType("int");
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("ReinforcedId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ComponentId");
+
+ b.HasIndex("ReinforcedId");
+
+ b.ToTable("ReinforcedComponents");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
+ {
+ b.HasOne("PrecastConcretePlantDatabaseImplement.Client", "Client")
+ .WithMany("Orders")
+ .HasForeignKey("ClientId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
+ .WithMany("Orders")
+ .HasForeignKey("ReinforcedId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Client");
+
+ b.Navigation("Reinforced");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
+ {
+ b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component")
+ .WithMany("ReinforcedComponents")
+ .HasForeignKey("ComponentId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinfordced")
+ .WithMany("Components")
+ .HasForeignKey("ReinforcedId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Component");
+
+ b.Navigation("Reinfordced");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Client", b =>
+ {
+ b.Navigation("Orders");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
+ {
+ b.Navigation("ReinforcedComponents");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
+ {
+ b.Navigation("Components");
+
+ b.Navigation("Orders");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230402164750_AddClient.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230402164750_AddClient.cs
new file mode 100644
index 0000000..d80c8e7
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230402164750_AddClient.cs
@@ -0,0 +1,69 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace PrecastConcretePlantDatabaseImplement.Migrations
+{
+ ///
+ public partial class AddClient : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.Sql("DELETE FROM Orders");
+ migrationBuilder.AddColumn(
+ name: "ClientId",
+ table: "Orders",
+ type: "int",
+ nullable: false,
+ defaultValue: 0);
+
+ migrationBuilder.CreateTable(
+ name: "Clients",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ClientFIO = table.Column(type: "nvarchar(max)", nullable: false),
+ Email = table.Column(type: "nvarchar(max)", nullable: false),
+ Password = table.Column(type: "nvarchar(max)", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Clients", x => x.Id);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Orders_ClientId",
+ table: "Orders",
+ column: "ClientId");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Orders_Clients_ClientId",
+ table: "Orders",
+ column: "ClientId",
+ principalTable: "Clients",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Orders_Clients_ClientId",
+ table: "Orders");
+
+ migrationBuilder.DropTable(
+ name: "Clients");
+
+ migrationBuilder.DropIndex(
+ name: "IX_Orders_ClientId",
+ table: "Orders");
+
+ migrationBuilder.DropColumn(
+ name: "ClientId",
+ table: "Orders");
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs
index 5d1feb7..812d817 100644
--- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs
@@ -22,6 +22,31 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ClientFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Email")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Clients");
+ });
+
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
{
b.Property("Id")
@@ -50,6 +75,9 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+ b.Property("ClientId")
+ .HasColumnType("int");
+
b.Property("Count")
.HasColumnType("int");
@@ -70,6 +98,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
b.HasKey("Id");
+ b.HasIndex("ClientId");
+
b.HasIndex("ReinforcedId");
b.ToTable("Orders");
@@ -123,12 +153,20 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
{
+ b.HasOne("PrecastConcretePlantDatabaseImplement.Client", "Client")
+ .WithMany("Orders")
+ .HasForeignKey("ClientId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany("Orders")
.HasForeignKey("ReinforcedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
+ b.Navigation("Client");
+
b.Navigation("Reinforced");
});
@@ -151,6 +189,11 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
b.Navigation("Reinfordced");
});
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Client", b =>
+ {
+ b.Navigation("Orders");
+ });
+
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
{
b.Navigation("ReinforcedComponents");
diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Order.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Order.cs
index 850e265..fe55eb6 100644
--- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Order.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Order.cs
@@ -16,6 +16,10 @@ namespace PrecastConcretePlantDatabaseImplement.Models
[Required]
public int ReinforcedId { get; private set; }
+ [Required]
+
+ public int ClientId { get; private set; }
+
[Required]
public int Count { get; private set; }
@@ -32,6 +36,8 @@ namespace PrecastConcretePlantDatabaseImplement.Models
public Reinforced Reinforced { get; private set; }
+ public Client Client { get; private set; }
+
public static Order? Create(OrderBindingModel? model)
{
@@ -42,6 +48,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models
return new Order()
{
ReinforcedId = model.ReinforcedId,
+ ClientId = model.ClientId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@@ -73,6 +80,8 @@ namespace PrecastConcretePlantDatabaseImplement.Models
return new()
{
ReinforcedName = Reinforced?.ReinforcedName ?? string.Empty,
+ ClientId = ClientId,
+ ClientFIO = Client?.ClientFIO ?? string.Empty,
ReinforcedId = ReinforcedId,
Count = Count,
Sum = Sum,
diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabase.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabase.cs
index 49c9a88..901a808 100644
--- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabase.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabase.cs
@@ -23,5 +23,6 @@ namespace PrecastConcretePlantDatabaseImplement
public virtual DbSet Reinforceds { set; get; }
public virtual DbSet ReinforcedComponents { set; get; }
public virtual DbSet Orders { set; get; }
+ public virtual DbSet Clients { set; get; }
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Client.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Client.cs
new file mode 100644
index 0000000..435b04f
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Client.cs
@@ -0,0 +1,79 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace PrecastConcretePlantFileImplement
+{
+ public class Client : IClientModel
+ {
+ 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 int Id { get; private set; }
+
+ public static Client? Create(ClientBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ 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()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ ClientFIO = element.Element("FIO")!.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("FIO", ClientFIO),
+ new XElement("Email", Email),
+ new XElement("Password", Password)
+ );
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ClientStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ClientStorage.cs
new file mode 100644
index 0000000..b5b36f7
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ClientStorage.cs
@@ -0,0 +1,90 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.StoragesContract;
+using PrecastConcretePlantContracts.ViewModels;
+
+namespace PrecastConcretePlantFileImplement
+{
+ public class ClientStorage : IClientStorage
+ {
+ private readonly DataFileSingleton _source;
+ public ClientStorage()
+ {
+ _source = DataFileSingleton.GetInstance();
+ }
+
+ public ClientViewModel? Delete(ClientBindingModel model)
+ {
+ var res = _source.Clients.FirstOrDefault(x => x.Id == model.Id);
+ if (res != null)
+ {
+ _source.Clients.Remove(res);
+ _source.SaveClients();
+ }
+ return res?.GetViewModel;
+ }
+
+ public ClientViewModel? GetElement(ClientSearchModel model)
+ {
+ if (model.Id.HasValue)
+ return _source.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
+ if (model.Email != null && model.Password != null)
+ return _source.Clients
+ .FirstOrDefault(x => x.Email.Equals(model.Email)
+ && x.Password.Equals(model.Password))
+ ?.GetViewModel;
+ if (model.Email != null)
+ return _source.Clients.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel;
+ return null;
+ }
+
+ public List GetFilteredList(ClientSearchModel model)
+ {
+ if (model == null)
+ {
+ return new();
+ }
+ if (model.Id.HasValue)
+ {
+ var res = GetElement(model);
+ return res != null ? new() { res } : new();
+ }
+ if (model.Email != null)
+ {
+ return _source.Clients
+ .Where(x => x.Email.Contains(model.Email))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ return new();
+ }
+
+ public List GetFullList()
+ {
+ return _source.Clients.Select(x => x.GetViewModel).ToList();
+ }
+
+ public ClientViewModel? Insert(ClientBindingModel model)
+ {
+ model.Id = _source.Clients.Count > 0 ? _source.Clients.Max(x => x.Id) + 1 : 1;
+ var res = Client.Create(model);
+ if (res != null)
+ {
+ _source.Clients.Add(res);
+ _source.SaveClients();
+ }
+ return res?.GetViewModel;
+ }
+
+ public ClientViewModel? Update(ClientBindingModel model)
+ {
+ var res = _source.Clients.FirstOrDefault(x => x.Id == model.Id);
+ if (res != null)
+ {
+ res.Update(model);
+ _source.SaveClients();
+ }
+ return res?.GetViewModel;
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs
index 5ae7a7d..d539b03 100644
--- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs
@@ -9,9 +9,11 @@ namespace PrecastConcretePlantFileImplement
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string ReinforcedFileName = "Reinforced.xml";
+ private readonly string ClientFileName = "Client.xml";
public List Components { get; set; }
public List Orders { get; set; }
public List Reinforceds { get; set; }
+ public List Clients { get; private set; }
public static DataFileSingleton GetInstance()
{
@@ -24,12 +26,14 @@ namespace PrecastConcretePlantFileImplement
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SaveReinforceds() => SaveData(Reinforceds, ReinforcedFileName, "Reinforceds", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
+ public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Reinforceds = LoadData(ReinforcedFileName, "Reinforced", x => Reinforced.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/PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs
index e71490b..d49b807 100644
--- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs
@@ -13,6 +13,8 @@ namespace PrecastConcretePlantFileImplement.Models
public int ReinforcedId { get; private set; }
+ public int ClientId { get; set; }
+
public int Count { get; private set; }
public double Sum { get; private set; }
@@ -32,6 +34,7 @@ namespace PrecastConcretePlantFileImplement.Models
return new Order()
{
ReinforcedId = model.ReinforcedId,
+ ClientId = model.ClientId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@@ -54,6 +57,7 @@ namespace PrecastConcretePlantFileImplement.Models
Count = Convert.ToInt32(element.Element("Count")!.Value),
Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value),
ReinforcedId = Convert.ToInt32(element.Element("ReinforcedId")!.Value),
+ ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement),
};
@@ -64,12 +68,20 @@ namespace PrecastConcretePlantFileImplement.Models
{
return;
}
+ ReinforcedId = model.ReinforcedId;
+ Count = model.Count;
+ Sum = model.Sum;
Status = model.Status;
+ DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
+ Id = model.Id;
}
public OrderViewModel GetViewModel => new()
{
ReinforcedId = ReinforcedId,
+ ReinforcedName= DataFileSingleton.GetInstance().Reinforceds.FirstOrDefault(x => x.Id == ReinforcedId)?.ReinforcedName ?? string.Empty,
+ ClientFIO = DataFileSingleton.GetInstance().Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
+ ClientId = ClientId,
Count = Count,
Sum = Sum,
Status = Status,
@@ -80,11 +92,12 @@ namespace PrecastConcretePlantFileImplement.Models
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("ReinforcedId", ReinforcedId),
+ new XElement("ClientId", ClientId),
new XElement("Count", Count),
new XElement("Sum", Sum.ToString()),
new XElement("Status", (int)Status),
new XElement("DateCreate", DateCreate),
new XElement("DateImplement", DateImplement)
-);
+ );
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Client.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Client.cs
new file mode 100644
index 0000000..5ff32d1
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Client.cs
@@ -0,0 +1,56 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PrecastConcretePlantListImplement
+{
+ public class Client : IClientModel
+ {
+ 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 int Id { get; private set; }
+
+ public static Client? Create(ClientBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ 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/PrecastConcretePlant/PrecastConcretePlantListImplement/ClientStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/ClientStorage.cs
new file mode 100644
index 0000000..5cf0c4c
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/ClientStorage.cs
@@ -0,0 +1,101 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.StoragesContract;
+using PrecastConcretePlantContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PrecastConcretePlantListImplement
+{
+ public class ClientStorage : IClientStorage
+ {
+ private readonly DataListSingleton _source;
+ public ClientStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ 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;
+ }
+
+ public ClientViewModel? GetElement(ClientSearchModel model)
+ {
+ foreach (var client in _source.Clients)
+ {
+ if (model.Id.HasValue && model.Id == client.Id)
+ return client.GetViewModel;
+ if (model.Email != null && model.Password != null &&
+ client.Email.Equals(model.Email) && client.Password.Equals(model.Password))
+ return client.GetViewModel;
+ if (model.Email != null && client.Email.Equals(model.Email))
+ return client.GetViewModel;
+ }
+ return null;
+ }
+
+ public List GetFilteredList(ClientSearchModel model)
+ {
+ if (model == null)
+ {
+ return new();
+ }
+ var res = GetElement(model);
+ return res != null ? new() { res } : new();
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var client in _source.Clients)
+ {
+ result.Add(client.GetViewModel);
+ }
+ return result;
+ }
+
+ 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 res = Client.Create(model);
+ if (res != null)
+ {
+ _source.Clients.Add(res);
+ }
+ return res?.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;
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs
index 64027e4..d97f79f 100644
--- a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs
@@ -8,11 +8,13 @@ namespace PrecastConcretePlantListImplement
public List Components { get; set; }
public List Orders { get; set; }
public List Reinforced { get; set; }
+ public List Clients { get; set; }
private DataListSingleton()
{
Components = new List();
Orders = new List();
Reinforced = new List();
+ Clients = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Order.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Order.cs
index 7f1a2f1..ced16ad 100644
--- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Order.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Order.cs
@@ -12,6 +12,8 @@ namespace PrecastConcretePlantListImplement.Models
public int ReinforcedId { get; private set; }
+ public int ClientId { get; private set; }
+
public int Count { get; private set; }
public double Sum { get; private set; }
@@ -31,6 +33,7 @@ namespace PrecastConcretePlantListImplement.Models
return new Order()
{
ReinforcedId = model.ReinforcedId,
+ ClientId = model.ClientId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@@ -45,12 +48,18 @@ namespace PrecastConcretePlantListImplement.Models
{
return;
}
+ ReinforcedId = model.ReinforcedId;
+ Count = model.Count;
+ Sum = model.Sum;
Status = model.Status;
+ DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
+ Id = model.Id;
}
public OrderViewModel GetViewModel => new()
{
ReinforcedId = ReinforcedId,
+ ClientId = ClientId,
Count = Count,
Sum = Sum,
Status = Status,
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/OrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/OrderStorage.cs
index ad6b344..57c4ed2 100644
--- a/PrecastConcretePlant/PrecastConcretePlantListImplement/OrderStorage.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/OrderStorage.cs
@@ -13,7 +13,6 @@ namespace PrecastConcretePlantListImplement
{
_source = DataListSingleton.GetInstance();
}
-
public OrderViewModel? Delete(OrderBindingModel model)
{
for (int i = 0; i < _source.Orders.Count; ++i)
@@ -27,7 +26,6 @@ namespace PrecastConcretePlantListImplement
}
return null;
}
-
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
@@ -38,7 +36,7 @@ namespace PrecastConcretePlantListImplement
{
if (model.Id.HasValue && order.Id == model.Id)
{
- return order.GetViewModel;
+ return GetViewModel(order);
}
}
return null;
@@ -47,19 +45,20 @@ namespace PrecastConcretePlantListImplement
public List GetFilteredList(OrderSearchModel model)
{
var result = new List();
- if (!model.Id.HasValue)
- {
- return result;
- }
foreach (var order in _source.Orders)
{
if (order.Id == model.Id)
{
- return new() { order.GetViewModel };
+ return new() { GetViewModel(order) };
}
- if (model.DateFrom != null && model.DateTo != null && model.DateFrom <= order.DateCreate.Date && order.DateCreate <= model.DateTo)
+ else if (model.DateFrom.HasValue && model.DateTo.HasValue &&
+ model.DateFrom <= order.DateCreate.Date && order.DateCreate.Date <= model.DateTo)
{
- result.Add(order.GetViewModel);
+ result.Add(GetViewModel(order));
+ }
+ else if (model.ClientId.HasValue && order.ClientId == model.ClientId)
+ {
+ result.Add(GetViewModel(order));
}
}
return result;
@@ -118,6 +117,14 @@ namespace PrecastConcretePlantListImplement
break;
}
}
+ foreach (var client in _source.Clients)
+ {
+ if (client.Id == res.ClientId)
+ {
+ res.ClientFIO = client.ClientFIO;
+ break;
+ }
+ }
return res;
}
}