From a5df8ba5641bd849cf4e470fb714a77b22aaf626 Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Thu, 27 Apr 2023 22:54:15 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A8=D0=B5=D1=81=D1=82=D0=B0=D1=8F=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Confectionery/FormImplementer.Designer.cs | 163 ++++++++++++ .../Confectionery/FormImplementer.cs | 109 ++++++++ .../Confectionery/FormImplementer.resx | 60 +++++ .../FormImplementers.Designer.cs | 119 +++++++++ .../Confectionery/FormImplementers.cs | 110 ++++++++ .../Confectionery/FormImplementers.resx | 60 +++++ .../Confectionery/FormMain.Designer.cs | 54 ++-- Confectionery/Confectionery/FormMain.cs | 21 +- Confectionery/Confectionery/Program.cs | 5 + .../BusinessLogics/ImplementerLogic.cs | 126 +++++++++ .../BusinessLogics/OrderLogic.cs | 49 +++- .../BusinessLogics/WorkModeling.cs | 151 +++++++++++ .../BindingModels/ImplementerBindingModel.cs | 18 ++ .../BindingModels/OrderBindingModel.cs | 1 + .../IImplementerLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../BusinessLogicsContracts/IWorkProcess.cs | 16 ++ .../SearchModels/ImplementerSearchModel.cs | 15 ++ .../SearchModels/OrderSearchModel.cs | 5 +- .../StoragesContracts/IImplementerStorage.cs | 21 ++ .../ViewModels/ImplementerViewModel.cs | 23 ++ .../ViewModels/OrderViewModel.cs | 3 + .../ConfectioneryDatabase.cs | 1 + .../Implements/ImplementerStorage.cs | 96 +++++++ .../Implements/OrderStorage.cs | 38 ++- .../20230427171040_AddImplementer.Designer.cs | 250 ++++++++++++++++++ .../20230427171040_AddImplementer.cs | 67 +++++ .../20230427171237_FixOrders.Designer.cs | 250 ++++++++++++++++++ .../Migrations/20230427171237_FixOrders.cs | 22 ++ .../ConfectioneryDatabaseModelSnapshot.cs | 43 +++ .../Models/Implementer.cs | 63 +++++ .../Models/Order.cs | 14 +- .../Models/IImplementerModel.cs | 16 ++ .../Models/IOrderModel.cs | 1 + .../DataFileSingleton.cs | 4 + .../Implements/ImplementerStorage.cs | 86 ++++++ .../Implements/OrderStorage.cs | 27 +- .../Models/Implementer.cs | 81 ++++++ .../Models/Order.cs | 12 +- .../DataListSingleton.cs | 2 + .../Implements/ImplementerStorage.cs | 112 ++++++++ .../Implements/OrderStorage.cs | 36 ++- .../Models/Implementer.cs | 58 ++++ .../Models/Order.cs | 4 +- .../Controllers/ImplementerController.cs | 107 ++++++++ Confectionery/ConfectioneryRestApi/Program.cs | 2 + 46 files changed, 2468 insertions(+), 74 deletions(-) create mode 100644 Confectionery/Confectionery/FormImplementer.Designer.cs create mode 100644 Confectionery/Confectionery/FormImplementer.cs create mode 100644 Confectionery/Confectionery/FormImplementer.resx create mode 100644 Confectionery/Confectionery/FormImplementers.Designer.cs create mode 100644 Confectionery/Confectionery/FormImplementers.cs create mode 100644 Confectionery/Confectionery/FormImplementers.resx create mode 100644 Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ImplementerLogic.cs create mode 100644 Confectionery/ConfectioneryBusinessLogic/BusinessLogics/WorkModeling.cs create mode 100644 Confectionery/ConfectioneryContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 Confectionery/ConfectioneryContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 Confectionery/ConfectioneryContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs create mode 100644 Confectionery/ConfectioneryDataBaseImplement/Implements/ImplementerStorage.cs create mode 100644 Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171040_AddImplementer.Designer.cs create mode 100644 Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171040_AddImplementer.cs create mode 100644 Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171237_FixOrders.Designer.cs create mode 100644 Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171237_FixOrders.cs create mode 100644 Confectionery/ConfectioneryDataBaseImplement/Models/Implementer.cs create mode 100644 Confectionery/ConfectioneryDataModels/Models/IImplementerModel.cs create mode 100644 Confectionery/ConfectioneryFileImplements/Implements/ImplementerStorage.cs create mode 100644 Confectionery/ConfectioneryFileImplements/Models/Implementer.cs create mode 100644 Confectionery/ConfectioneryListImplement/Implements/ImplementerStorage.cs create mode 100644 Confectionery/ConfectioneryListImplement/Models/Implementer.cs create mode 100644 Confectionery/ConfectioneryRestApi/Controllers/ImplementerController.cs diff --git a/Confectionery/Confectionery/FormImplementer.Designer.cs b/Confectionery/Confectionery/FormImplementer.Designer.cs new file mode 100644 index 0000000..6fabef2 --- /dev/null +++ b/Confectionery/Confectionery/FormImplementer.Designer.cs @@ -0,0 +1,163 @@ +namespace Confectionery +{ + partial class FormImplementer + { + /// + /// 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.textBoxWorkExperience = new System.Windows.Forms.TextBox(); + this.textBoxFIO = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.labelName = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxQualification = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // textBoxWorkExperience + // + this.textBoxWorkExperience.Location = new System.Drawing.Point(118, 76); + this.textBoxWorkExperience.Name = "textBoxWorkExperience"; + this.textBoxWorkExperience.Size = new System.Drawing.Size(191, 27); + this.textBoxWorkExperience.TabIndex = 11; + // + // textBoxFIO + // + this.textBoxFIO.Location = new System.Drawing.Point(118, 6); + this.textBoxFIO.Name = "textBoxFIO"; + this.textBoxFIO.Size = new System.Drawing.Size(330, 27); + this.textBoxFIO.TabIndex = 10; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 79); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(105, 20); + this.label1.TabIndex = 9; + this.label1.Text = "Опыт работы:"; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(64, 6); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(45, 20); + this.labelName.TabIndex = 8; + this.labelName.Text = "ФИО:"; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(354, 163); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(254, 163); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // textBoxPassword + // + this.textBoxPassword.Location = new System.Drawing.Point(118, 39); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.Size = new System.Drawing.Size(330, 27); + this.textBoxPassword.TabIndex = 13; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(44, 42); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(65, 20); + this.label2.TabIndex = 12; + this.label2.Text = "Пароль:"; + // + // textBoxQualification + // + this.textBoxQualification.Location = new System.Drawing.Point(118, 109); + this.textBoxQualification.Name = "textBoxQualification"; + this.textBoxQualification.Size = new System.Drawing.Size(191, 27); + this.textBoxQualification.TabIndex = 15; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(-2, 112); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(111, 20); + this.label3.TabIndex = 14; + this.label3.Text = "Квалификация"; + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(454, 202); + this.Controls.Add(this.textBoxQualification); + this.Controls.Add(this.label3); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.label2); + this.Controls.Add(this.textBoxWorkExperience); + this.Controls.Add(this.textBoxFIO); + this.Controls.Add(this.label1); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxWorkExperience; + private TextBox textBoxFIO; + private Label label1; + private Label labelName; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxPassword; + private Label label2; + private TextBox textBoxQualification; + private Label label3; + } +} \ No newline at end of file diff --git a/Confectionery/Confectionery/FormImplementer.cs b/Confectionery/Confectionery/FormImplementer.cs new file mode 100644 index 0000000..1af6b00 --- /dev/null +++ b/Confectionery/Confectionery/FormImplementer.cs @@ -0,0 +1,109 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +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 Confectionery +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ImplementerSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxFIO.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + textBoxWorkExperience.Text = view.WorkExperience.ToString(); + textBoxQualification.Text = view.Qualification.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxWorkExperience.Text)) + { + MessageBox.Show("Заполните опыт работы", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxQualification.Text)) + { + MessageBox.Show("Заполните опыт квалификацию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + Password = textBoxPassword.Text, + WorkExperience = Convert.ToInt32(textBoxWorkExperience.Text), + Qualification = Convert.ToInt32(textBoxQualification.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Confectionery/Confectionery/FormImplementer.resx b/Confectionery/Confectionery/FormImplementer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/Confectionery/FormImplementer.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/Confectionery/Confectionery/FormImplementers.Designer.cs b/Confectionery/Confectionery/FormImplementers.Designer.cs new file mode 100644 index 0000000..e9ce8c9 --- /dev/null +++ b/Confectionery/Confectionery/FormImplementers.Designer.cs @@ -0,0 +1,119 @@ +namespace Confectionery +{ + partial class FormImplementers + { + /// + /// 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.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(523, 185); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(94, 29); + this.buttonRef.TabIndex = 9; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(523, 127); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(94, 29); + this.buttonDel.TabIndex = 8; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(523, 70); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(94, 29); + this.buttonUpd.TabIndex = 7; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(523, 13); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 6; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(1, 1); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(489, 449); + this.dataGridView.TabIndex = 5; + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(628, 450); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormImplementers"; + this.Text = "Исполнители"; + this.Load += new System.EventHandler(this.FormImplementers_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Confectionery/Confectionery/FormImplementers.cs b/Confectionery/Confectionery/FormImplementers.cs new file mode 100644 index 0000000..883f787 --- /dev/null +++ b/Confectionery/Confectionery/FormImplementers.cs @@ -0,0 +1,110 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Confectionery +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementers_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["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + 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 ImplementerBindingModel { 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/Confectionery/Confectionery/FormImplementers.resx b/Confectionery/Confectionery/FormImplementers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/Confectionery/FormImplementers.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/Confectionery/Confectionery/FormMain.Designer.cs b/Confectionery/Confectionery/FormMain.Designer.cs index e74fc08..f11208c 100644 --- a/Confectionery/Confectionery/FormMain.Designer.cs +++ b/Confectionery/Confectionery/FormMain.Designer.cs @@ -33,14 +33,14 @@ this.ингредиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.IngredientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.IngredientPastriesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.OrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); - this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); - this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); this.menuStrip1.SuspendLayout(); @@ -52,7 +52,8 @@ this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem, - this.отчётыToolStripMenuItem}); + this.отчётыToolStripMenuItem, + this.запускРаботToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1703, 28); @@ -64,7 +65,8 @@ this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ингредиентыToolStripMenuItem, this.изделияToolStripMenuItem, - this.клиентыToolStripMenuItem}); + this.клиентыToolStripMenuItem, + this.исполнителиToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -90,6 +92,13 @@ this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); // + // исполнителиToolStripMenuItem + // + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(251, 26); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); + // // отчётыToolStripMenuItem // this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -121,6 +130,13 @@ this.OrdersToolStripMenuItem.Text = "Список заказов"; this.OrdersToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); // + // запускРаботToolStripMenuItem + // + this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(114, 24); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.BackgroundColor = System.Drawing.Color.White; @@ -144,29 +160,9 @@ this.buttonCreateOrder.UseVisualStyleBackColor = true; this.buttonCreateOrder.Click += new System.EventHandler(this.buttonCreateOrder_Click); // - // buttonTakeOrderInWork - // - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1461, 138); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(197, 29); - this.buttonTakeOrderInWork.TabIndex = 3; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.buttonTakeOrderInWork_Click); - // - // buttonOrderReady - // - this.buttonOrderReady.Location = new System.Drawing.Point(1461, 224); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(197, 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(1461, 309); + this.buttonIssuedOrder.Location = new System.Drawing.Point(1461, 198); this.buttonIssuedOrder.Name = "buttonIssuedOrder"; this.buttonIssuedOrder.Size = new System.Drawing.Size(197, 29); this.buttonIssuedOrder.TabIndex = 5; @@ -176,7 +172,7 @@ // // buttonRef // - this.buttonRef.Location = new System.Drawing.Point(1461, 382); + this.buttonRef.Location = new System.Drawing.Point(1461, 359); this.buttonRef.Name = "buttonRef"; this.buttonRef.Size = new System.Drawing.Size(197, 29); this.buttonRef.TabIndex = 6; @@ -191,8 +187,6 @@ this.ClientSize = new System.Drawing.Size(1703, 450); this.Controls.Add(this.buttonRef); this.Controls.Add(this.buttonIssuedOrder); - this.Controls.Add(this.buttonOrderReady); - this.Controls.Add(this.buttonTakeOrderInWork); this.Controls.Add(this.buttonCreateOrder); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip1); @@ -216,8 +210,6 @@ private ToolStripMenuItem изделияToolStripMenuItem; private DataGridView dataGridView; private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; private ToolStripMenuItem отчётыToolStripMenuItem; @@ -225,5 +217,7 @@ private ToolStripMenuItem IngredientPastriesToolStripMenuItem; private ToolStripMenuItem OrdersToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; } } \ No newline at end of file diff --git a/Confectionery/Confectionery/FormMain.cs b/Confectionery/Confectionery/FormMain.cs index fcca262..8c083db 100644 --- a/Confectionery/Confectionery/FormMain.cs +++ b/Confectionery/Confectionery/FormMain.cs @@ -19,13 +19,15 @@ namespace Confectionery private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; + private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) @@ -45,7 +47,9 @@ namespace Confectionery dataGridView.Columns["PastryId"].Visible = false; dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; } } catch (Exception ex) @@ -194,5 +198,20 @@ namespace Confectionery form.ShowDialog(); } } + + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + + private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } } } diff --git a/Confectionery/Confectionery/Program.cs b/Confectionery/Confectionery/Program.cs index 0edea73..f231258 100644 --- a/Confectionery/Confectionery/Program.cs +++ b/Confectionery/Confectionery/Program.cs @@ -41,11 +41,14 @@ namespace Confectionery services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -59,6 +62,8 @@ namespace Confectionery services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ImplementerLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..a83bd73 --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,126 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}. ImplementerFIO:{ImplementerFIO}. Password:{Password}", model?.Id, model?.ImplementerFIO, model?.Password); + var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{Id}. ImplementerFIO:{ImplementerFIO}. Password:{Password}", model.Id, model.ImplementerFIO, model.Password); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.Password)); + } + if (model.WorkExperience < 0) + { + throw new ArgumentNullException("Опыт работы не может быть меньше 0!", nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentNullException("Квалификация не может быть меньше 0!", nameof(model.Qualification)); + } + _logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}. Password:{Password}. Id:{Id}", model.ImplementerFIO, model.Password, model.Id); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже зарегестрирован"); + } + } + } +} diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs index f35b2ce..42c6155 100644 --- a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -17,6 +17,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + static readonly object _lock = new object(); public OrderLogic(ILogger logger, IOrderStorage orderStorage) { @@ -55,7 +56,6 @@ namespace ConfectioneryBusinessLogic.BusinessLogics throw new InvalidOperationException("Заказ должен быть переведен в статус готовности перед выдачей!"); } model.Status = OrderStatus.Выдан; - model.DateImplement = DateTime.Now; _orderStorage.Update(model); return true; } @@ -78,6 +78,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics throw new InvalidOperationException("Заказ должен быть переведен в статус выполнения перед готовностью!"); } model.Status = OrderStatus.Готов; + model.DateImplement = DateTime.Now; _orderStorage.Update(model); return true; } @@ -95,26 +96,46 @@ namespace ConfectioneryBusinessLogic.BusinessLogics return list; } - public bool TakeOrderInWork(OrderBindingModel model) + public OrderViewModel? ReadElement(OrderSearchModel? model) { - CheckModel(model, false); - var element = _orderStorage.GetElement(new OrderSearchModel + if (model == null) { - Id = model.Id - }); + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ImplementerId:{ImplementerId}. OrderStatus:{OrderStatus}. Id:{Id}", model.ImplementerId, model.OrderStatus, model.Id); + var element = _orderStorage.GetElement(model); if (element == null) { - _logger.LogWarning("Read operation failed"); - return false; + _logger.LogWarning("ReadElement element not found"); + return null; } - if (element.Status != OrderStatus.Принят) + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + lock (_lock) { - _logger.LogWarning("Status change operation failed"); - throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!"); + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != OrderStatus.Принят) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!"); + } + model.Status = OrderStatus.Выполняется; + _orderStorage.Update(model); + return true; } - model.Status = OrderStatus.Выполняется; - _orderStorage.Update(model); - return true; } private void CheckModel(OrderBindingModel model, bool withParams = true) diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/WorkModeling.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..659b36f --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,151 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryBusinessLogic.BusinessLogics +{ + public class WorkModeling : IWorkProcess + { + private readonly ILogger _logger; + + private readonly Random _rnd; + + private IOrderLogic? _orderLogic; + + public WorkModeling(ILogger logger) + { + _logger = logger; + _rnd = new Random(1000); + } + + public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic) + { + _orderLogic = orderLogic; + var implementers = implementerLogic.ReadList(null); + if (implementers == null) + { + _logger.LogWarning("DoWork. Implementers is null"); + return; + } + var orders = _orderLogic.ReadList(new OrderSearchModel { OrderStatus = OrderStatus.Принят }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + /// + /// Иммитация работы исполнителя + /// + /// + /// + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List? orders) + { + if (_orderLogic == null || implementer == null || orders == null) + { + return; + } + await RunOrderInWork(implementer); + if (orders == null || orders.Count == 0) + return; + + await Task.Run(async () => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // делаем работу + await Task.Delay(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id + }); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + // отдыхаем + await Task.Delay(implementer.Qualification * _rnd.Next(10, 100)); + } + }); + } + + /// + /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) + /// + /// + /// + private async Task RunOrderInWork(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementer.Id, + OrderStatus = OrderStatus.Выполняется + })); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + // доделываем работу + await Task.Delay(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + // отдыхаем + await Task.Delay(implementer.Qualification * _rnd.Next(10, 100)); + } + // заказа может не быть, просто игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/Confectionery/ConfectioneryContracts/BindingModels/ImplementerBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..285af99 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,18 @@ +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + public string ImplementerFIO { get; set; } = String.Empty; + public string Password { get; set; } = String.Empty; + public int WorkExperience { get; set; } + public int Qualification { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs index d51f207..d753eee 100644 --- a/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs +++ b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs @@ -18,5 +18,6 @@ namespace ConfectioneryContracts.BindingModels public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } + public int? ImplementerId { get; set; } } } diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IImplementerLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..8100c97 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,20 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? model); + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + bool Create(ImplementerBindingModel model); + bool Update(ImplementerBindingModel model); + bool Delete(ImplementerBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs index 7a91377..04ae242 100644 --- a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace ConfectioneryContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel? model); bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IWorkProcess.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..02ef2a0 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + /// + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/Confectionery/ConfectioneryContracts/SearchModels/ImplementerSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..3b73401 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + public string? ImplementerFIO { get; set; } + public string? Password { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs index 5f8a475..3749b2e 100644 --- a/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs +++ b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using ConfectioneryDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,5 +13,7 @@ namespace ConfectioneryContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public OrderStatus? OrderStatus { get; set; } } } diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IImplementerStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..4c759fd --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContracts +{ + public interface IImplementerStorage + { + List GetFullList(); + List GetFilteredList(ImplementerSearchModel model); + ImplementerViewModel? GetElement(ImplementerSearchModel model); + ImplementerViewModel? Insert(ImplementerBindingModel model); + ImplementerViewModel? Update(ImplementerBindingModel model); + ImplementerViewModel? Delete(ImplementerBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..4c4d896 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,23 @@ +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + [DisplayName("ФИО")] + public string ImplementerFIO { get; set; } = String.Empty; + [DisplayName("Пароль")] + public string Password { get; set; } = String.Empty; + [DisplayName("Опыт работы")] + public int WorkExperience { get; set; } + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs index 3c8f27f..5695edf 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs @@ -16,6 +16,9 @@ namespace ConfectioneryContracts.ViewModels public int PastryId { get; set; } [DisplayName("Кондитерское изделие")] public string PastryName { get; set; } = string.Empty; + public int? ImplementerId { get; set; } + [DisplayName("Исполнитель")] + public string? ImplementerFIO { get; set; } public int ClientId { get; set; } [DisplayName("ФИО клиента")] public string ClientFIO { get; set; } = string.Empty; diff --git a/Confectionery/ConfectioneryDataBaseImplement/ConfectioneryDatabase.cs b/Confectionery/ConfectioneryDataBaseImplement/ConfectioneryDatabase.cs index a386ef0..ed42a64 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/ConfectioneryDatabase.cs +++ b/Confectionery/ConfectioneryDataBaseImplement/ConfectioneryDatabase.cs @@ -24,5 +24,6 @@ namespace ConfectioneryDataBaseImplement public virtual DbSet PastryIngredients { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/Confectionery/ConfectioneryDataBaseImplement/Implements/ImplementerStorage.cs b/Confectionery/ConfectioneryDataBaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..028cd29 --- /dev/null +++ b/Confectionery/ConfectioneryDataBaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,96 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataBaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataBaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public List GetFullList() + { + using var context = new ConfectioneryDatabase(); + return context.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue) + { + return new(); + } + if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) + { + using var context = new ConfectioneryDatabase(); + return context.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + using var context = new ConfectioneryDatabase(); + return context.Implementers + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + using var context = new ConfectioneryDatabase(); + return context.Implementers + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password) + && x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + using var context = new ConfectioneryDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return newImplementer.GetViewModel; + } + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new ConfectioneryDatabase(); + var component = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new ConfectioneryDatabase(); + var element = context.Implementers.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Implementers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/Confectionery/ConfectioneryDataBaseImplement/Implements/OrderStorage.cs b/Confectionery/ConfectioneryDataBaseImplement/Implements/OrderStorage.cs index 9da3068..c87b380 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/Implements/OrderStorage.cs +++ b/Confectionery/ConfectioneryDataBaseImplement/Implements/OrderStorage.cs @@ -17,20 +17,28 @@ namespace ConfectioneryDataBaseImplement.Implements public List GetFullList() { using var context = new ConfectioneryDatabase(); - return context.Orders.Include(x => x.Client) + return context.Orders.Include(x => x.Client).Include(x => x.Implementer) .Select(x => AccessPastryStorage(x.GetViewModel, context)) .ToList(); } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && !model.OrderStatus.HasValue) { return new(); } + if (model.OrderStatus.HasValue) + { + using var context = new ConfectioneryDatabase(); + return context.Orders.Include(x => x.Client).Include(x => x.Implementer) + .Where(x => x.Status == model.OrderStatus) + .Select(x => AccessPastryStorage(x.GetViewModel, context)) + .ToList(); + } if (model.ClientId.HasValue) { using var context = new ConfectioneryDatabase(); - return context.Orders.Include(x => x.Client) + return context.Orders.Include(x => x.Client).Include(x => x.Implementer) .Where(x => x.ClientId == model.ClientId) .Select(x => AccessPastryStorage(x.GetViewModel, context)) .ToList(); @@ -38,7 +46,7 @@ namespace ConfectioneryDataBaseImplement.Implements else if (!model.DateFrom.HasValue || !model.DateTo.HasValue) { using var context = new ConfectioneryDatabase(); - return context.Orders.Include(x => x.Client) + return context.Orders.Include(x => x.Client).Include(x => x.Implementer) .Where(x => x.Id == model.Id) .Select(x => AccessPastryStorage(x.GetViewModel, context)) .ToList(); @@ -46,7 +54,7 @@ namespace ConfectioneryDataBaseImplement.Implements else { using var context = new ConfectioneryDatabase(); - return context.Orders.Include(x => x.Client) + return context.Orders.Include(x => x.Client).Include(x => x.Implementer) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => AccessPastryStorage(x.GetViewModel, context)) .ToList(); @@ -54,14 +62,24 @@ namespace ConfectioneryDataBaseImplement.Implements } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue && !model.OrderStatus.HasValue) { return new(); } using var context = new ConfectioneryDatabase(); - return AccessPastryStorage(context.Orders.Include(x => x.Client) - .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) - ?.GetViewModel, context); + if (!model.Id.HasValue) + { + return AccessPastryStorage(context.Orders.Include(x => x.Client).Include(x => x.Implementer) + .FirstOrDefault(x => model.ImplementerId.HasValue && model.OrderStatus.HasValue + && x.Status == model.OrderStatus && x.ImplementerId == model.ImplementerId) + ?.GetViewModel, context); + } + else + { + return AccessPastryStorage(context.Orders.Include(x => x.Client).Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel, context); + } } public OrderViewModel? Insert(OrderBindingModel model) { @@ -83,7 +101,7 @@ namespace ConfectioneryDataBaseImplement.Implements { return null; } - order.Update(model); + order.Update(context, model); context.SaveChanges(); return AccessPastryStorage(order.GetViewModel, context); } diff --git a/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171040_AddImplementer.Designer.cs b/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171040_AddImplementer.Designer.cs new file mode 100644 index 0000000..b5a5879 --- /dev/null +++ b/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171040_AddImplementer.Designer.cs @@ -0,0 +1,250 @@ +// +using System; +using ConfectioneryDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ConfectioneryDataBaseImplement.Migrations +{ + [DbContext(typeof(ConfectioneryDatabase))] + [Migration("20230427171040_AddImplementer")] + partial class AddImplementer + { + /// + 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("ConfectioneryDataBaseImplement.Models.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("ConfectioneryDataBaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Ingredient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("IngredientName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Ingredients"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.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("ImplementerId") + .HasColumnType("int"); + + b.Property("PastryId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("PastryId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Pastry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PastryName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Pastrys"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.PastryIngredient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("IngredientId") + .HasColumnType("int"); + + b.Property("PastryId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IngredientId"); + + b.HasIndex("PastryId"); + + b.ToTable("PastryIngredients"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Order", b => + { + b.HasOne("ConfectioneryDataBaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ConfectioneryDataBaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", null) + .WithMany("Orders") + .HasForeignKey("PastryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.PastryIngredient", b => + { + b.HasOne("ConfectioneryDataBaseImplement.Models.Ingredient", "Ingredient") + .WithMany("PastryIgredients") + .HasForeignKey("IngredientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", "Pastry") + .WithMany("Ingredients") + .HasForeignKey("PastryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ingredient"); + + b.Navigation("Pastry"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Ingredient", b => + { + b.Navigation("PastryIgredients"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Pastry", b => + { + b.Navigation("Ingredients"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171040_AddImplementer.cs b/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171040_AddImplementer.cs new file mode 100644 index 0000000..03bf2e4 --- /dev/null +++ b/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171040_AddImplementer.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ConfectioneryDataBaseImplement.Migrations +{ + /// + public partial class AddImplementer : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ImplementerId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ImplementerId", + table: "Orders"); + } + } +} diff --git a/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171237_FixOrders.Designer.cs b/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171237_FixOrders.Designer.cs new file mode 100644 index 0000000..b941604 --- /dev/null +++ b/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171237_FixOrders.Designer.cs @@ -0,0 +1,250 @@ +// +using System; +using ConfectioneryDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ConfectioneryDataBaseImplement.Migrations +{ + [DbContext(typeof(ConfectioneryDatabase))] + [Migration("20230427171237_FixOrders")] + partial class FixOrders + { + /// + 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("ConfectioneryDataBaseImplement.Models.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("ConfectioneryDataBaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Ingredient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("IngredientName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Ingredients"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.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("ImplementerId") + .HasColumnType("int"); + + b.Property("PastryId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("PastryId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Pastry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PastryName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Pastrys"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.PastryIngredient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("IngredientId") + .HasColumnType("int"); + + b.Property("PastryId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IngredientId"); + + b.HasIndex("PastryId"); + + b.ToTable("PastryIngredients"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Order", b => + { + b.HasOne("ConfectioneryDataBaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ConfectioneryDataBaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", null) + .WithMany("Orders") + .HasForeignKey("PastryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.PastryIngredient", b => + { + b.HasOne("ConfectioneryDataBaseImplement.Models.Ingredient", "Ingredient") + .WithMany("PastryIgredients") + .HasForeignKey("IngredientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", "Pastry") + .WithMany("Ingredients") + .HasForeignKey("PastryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ingredient"); + + b.Navigation("Pastry"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Ingredient", b => + { + b.Navigation("PastryIgredients"); + }); + + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Pastry", b => + { + b.Navigation("Ingredients"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171237_FixOrders.cs b/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171237_FixOrders.cs new file mode 100644 index 0000000..2c8515a --- /dev/null +++ b/Confectionery/ConfectioneryDataBaseImplement/Migrations/20230427171237_FixOrders.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ConfectioneryDataBaseImplement.Migrations +{ + /// + public partial class FixOrders : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Confectionery/ConfectioneryDataBaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs b/Confectionery/ConfectioneryDataBaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs index fa5df38..7639016 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs +++ b/Confectionery/ConfectioneryDataBaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs @@ -47,6 +47,33 @@ namespace ConfectioneryDataBaseImplement.Migrations b.ToTable("Clients"); }); + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Ingredient", b => { b.Property("Id") @@ -87,6 +114,9 @@ namespace ConfectioneryDataBaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("PastryId") .HasColumnType("int"); @@ -100,6 +130,8 @@ namespace ConfectioneryDataBaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("PastryId"); b.ToTable("Orders"); @@ -159,6 +191,10 @@ namespace ConfectioneryDataBaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("ConfectioneryDataBaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("ConfectioneryDataBaseImplement.Models.Pastry", null) .WithMany("Orders") .HasForeignKey("PastryId") @@ -166,6 +202,8 @@ namespace ConfectioneryDataBaseImplement.Migrations .IsRequired(); b.Navigation("Client"); + + b.Navigation("Implementer"); }); modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.PastryIngredient", b => @@ -187,6 +225,11 @@ namespace ConfectioneryDataBaseImplement.Migrations b.Navigation("Pastry"); }); + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("ConfectioneryDataBaseImplement.Models.Ingredient", b => { b.Navigation("PastryIgredients"); diff --git a/Confectionery/ConfectioneryDataBaseImplement/Models/Implementer.cs b/Confectionery/ConfectioneryDataBaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..f23f6b3 --- /dev/null +++ b/Confectionery/ConfectioneryDataBaseImplement/Models/Implementer.cs @@ -0,0 +1,63 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataBaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + [Required] + public string ImplementerFIO { get; set; } = string.Empty; + [Required] + public string Password { get; set; } = string.Empty; + [Required] + public int WorkExperience { get; set; } + [Required] + public int Qualification { get; set; } + [ForeignKey("ImplementerId")] + public virtual List Orders { get; set; } = new List(); + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification, + }; + } + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification, + }; + } +} diff --git a/Confectionery/ConfectioneryDataBaseImplement/Models/Order.cs b/Confectionery/ConfectioneryDataBaseImplement/Models/Order.cs index 91d172e..2940516 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/Models/Order.cs +++ b/Confectionery/ConfectioneryDataBaseImplement/Models/Order.cs @@ -19,6 +19,8 @@ namespace ConfectioneryDataBaseImplement.Models [Required] public int ClientId { get; set; } public virtual Client Client { get; set; } = new(); + public int? ImplementerId { get; set; } + public virtual Implementer? Implementer { get; set; } = new(); [Required] public int Count { get; private set; } [Required] @@ -44,16 +46,20 @@ namespace ConfectioneryDataBaseImplement.Models Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement + DateImplement = model.DateImplement, + ImplementerId = model.ImplementerId, + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null, }; } - public void Update(OrderBindingModel? model) + public void Update(ConfectioneryDatabase context, OrderBindingModel? model) { if (model == null) { return; } Status = model.Status; + if (model.ImplementerId.HasValue) ImplementerId = model.ImplementerId; + if (model.ImplementerId.HasValue) Implementer = context.Implementers.First(x => x.Id == model.ImplementerId); if (model.DateImplement.HasValue) DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() @@ -66,7 +72,9 @@ namespace ConfectioneryDataBaseImplement.Models Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement + DateImplement = DateImplement, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer?.ImplementerFIO }; } } diff --git a/Confectionery/ConfectioneryDataModels/Models/IImplementerModel.cs b/Confectionery/ConfectioneryDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..1258e44 --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Models/IImplementerModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs b/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs index 97b3332..44be794 100644 --- a/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs +++ b/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs @@ -16,6 +16,7 @@ namespace ConfectioneryDataModels.Models OrderStatus Status { get; } DateTime DateCreate { get; } DateTime? DateImplement { get; } + int? ImplementerId { get; } } } diff --git a/Confectionery/ConfectioneryFileImplements/DataFileSingleton.cs b/Confectionery/ConfectioneryFileImplements/DataFileSingleton.cs index 275de43..81f60ec 100644 --- a/Confectionery/ConfectioneryFileImplements/DataFileSingleton.cs +++ b/Confectionery/ConfectioneryFileImplements/DataFileSingleton.cs @@ -16,10 +16,12 @@ namespace ConfectioneryFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string PastryFileName = "Pastry.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Client.xml"; public List Ingredients { get; private set; } public List Orders { get; private set; } public List Pastries { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -32,12 +34,14 @@ namespace ConfectioneryFileImplement public void SavePastries() => SaveData(Pastries, PastryFileName, "Pastries", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { Ingredients = LoadData(IngredientFileName, "Ingredient", x => Ingredient.Create(x)!)!; Pastries = LoadData(PastryFileName, "Pastry", x => Pastry.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/Confectionery/ConfectioneryFileImplements/Implements/ImplementerStorage.cs b/Confectionery/ConfectioneryFileImplements/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..c23ef61 --- /dev/null +++ b/Confectionery/ConfectioneryFileImplements/Implements/ImplementerStorage.cs @@ -0,0 +1,86 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + return source.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + return source.Implementers + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password) + && x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var ingredient = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (ingredient == null) + { + return null; + } + ingredient.Update(model); + source.SaveImplementers(); + return ingredient.GetViewModel; + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/Confectionery/ConfectioneryFileImplements/Implements/OrderStorage.cs b/Confectionery/ConfectioneryFileImplements/Implements/OrderStorage.cs index b03dc16..6ec6839 100644 --- a/Confectionery/ConfectioneryFileImplements/Implements/OrderStorage.cs +++ b/Confectionery/ConfectioneryFileImplements/Implements/OrderStorage.cs @@ -27,10 +27,17 @@ namespace ConfectioneryFileImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue || !model.DateFrom.HasValue || !model.DateTo.HasValue) + if (!model.Id.HasValue || !model.DateFrom.HasValue || !model.DateTo.HasValue || !model.OrderStatus.HasValue) { return new(); } + if (model.OrderStatus.HasValue) + { + return source.Orders + .Where(x => x.ImplementerId == model.ImplementerId) + .Select(x => AccessPastryStorage(x.GetViewModel)) + .ToList(); + } if (!model.DateFrom.HasValue || !model.DateTo.HasValue) { return source.Orders @@ -49,13 +56,23 @@ namespace ConfectioneryFileImplement.Implements public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue && !model.OrderStatus.HasValue) { return null; } - return AccessPastryStorage(source.Orders - .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) - ?.GetViewModel); + if (!model.Id.HasValue) + { + return AccessPastryStorage(source.Orders + .FirstOrDefault(x => model.ImplementerId.HasValue && model.OrderStatus.HasValue + && x.ImplementerId == model.ImplementerId && x.Status == model.OrderStatus) + ?.GetViewModel); + } + else + { + return AccessPastryStorage(source.Orders + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel); + } } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/Confectionery/ConfectioneryFileImplements/Models/Implementer.cs b/Confectionery/ConfectioneryFileImplements/Models/Implementer.cs new file mode 100644 index 0000000..95bed1b --- /dev/null +++ b/Confectionery/ConfectioneryFileImplements/Models/Implementer.cs @@ -0,0 +1,81 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace ConfectioneryFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification, + }; + } + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Attribute("ImplementerFIO")!.Value, + Password = element.Attribute("Password")!.Value, + WorkExperience = Convert.ToInt32(element.Attribute("WorkExperience")!.Value), + Qualification = Convert.ToInt32(element.Attribute("Qualification")!.Value), + }; + } + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("WorkExperience", WorkExperience), + new XElement("Qualification", Qualification)); + } +} diff --git a/Confectionery/ConfectioneryFileImplements/Models/Order.cs b/Confectionery/ConfectioneryFileImplements/Models/Order.cs index 6ce05a1..2db58fa 100644 --- a/Confectionery/ConfectioneryFileImplements/Models/Order.cs +++ b/Confectionery/ConfectioneryFileImplements/Models/Order.cs @@ -16,6 +16,7 @@ namespace ConfectioneryFileImplement.Models public int Id { get; private set; } public int PastryId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } @@ -39,7 +40,8 @@ namespace ConfectioneryFileImplement.Models Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement + DateImplement = model.DateImplement, + ImplementerId = model.ImplementerId }; } @@ -57,7 +59,8 @@ namespace ConfectioneryFileImplement.Models Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus) Convert.ToInt32(element.Element("Status")!.Value), DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), - DateImplement = Convert.ToDateTime(String.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : element.Element("DateImplement")!.Value) + DateImplement = Convert.ToDateTime(String.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : element.Element("DateImplement")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), }; } @@ -68,6 +71,7 @@ namespace ConfectioneryFileImplement.Models return; } Status = model.Status; + ImplementerId = model.ImplementerId; if (model.DateImplement.HasValue) DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() @@ -78,7 +82,8 @@ namespace ConfectioneryFileImplement.Models Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement + DateImplement = DateImplement, + ImplementerId = ImplementerId }; public XElement GetXElement => new("Order", new XAttribute("Id", Id), @@ -87,6 +92,7 @@ namespace ConfectioneryFileImplement.Models new XElement("Sum", Sum.ToString()), new XElement("Status", ((int)Status).ToString()), new XElement("DateCreate", DateCreate.ToString()), + new XElement("ImplementerId", ImplementerId.ToString()), new XElement("DateImplement", DateImplement.ToString())); } } diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs index fdd563f..e93a94f 100644 --- a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs +++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs @@ -15,12 +15,14 @@ namespace ConfectioneryListImplement public List Orders { get; set; } public List Pastries { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Ingredients = new List(); Orders = new List(); Pastries = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/Confectionery/ConfectioneryListImplement/Implements/ImplementerStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..a1d6516 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,112 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return result; + } + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + foreach (var implementer in _source.Implementers) + { + if ((!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password) + && implementer.ImplementerFIO == model.ImplementerFIO && implementer.Password == model.Password) || + (model.Id.HasValue && implementer.Id == model.Id)) + { + return implementer.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + _source.Implementers.Add(newImplementer); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + return implementer.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs index a5faf0f..01885dc 100644 --- a/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs +++ b/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs @@ -32,11 +32,21 @@ namespace ConfectioneryListImplement.Implements public List GetFilteredList(OrderSearchModel model) { var result = new List(); - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.OrderStatus.HasValue) { return result; } - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + if (model.ImplementerId.HasValue && model.OrderStatus.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.Status == model.OrderStatus) + { + result.Add(AccessPastryStorage(order.GetViewModel)); + } + } + } + else if (!model.DateFrom.HasValue || !model.DateTo.HasValue) { foreach (var order in _source.Orders) { @@ -61,15 +71,29 @@ namespace ConfectioneryListImplement.Implements public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue && !model.OrderStatus.HasValue) { return null; } - foreach (var order in _source.Orders) + if (!model.Id.HasValue) { - if (model.Id.HasValue && order.Id == model.Id) + foreach (var order in _source.Orders) { - return AccessPastryStorage(order.GetViewModel); + if (model.ImplementerId.HasValue && model.OrderStatus.HasValue + && order.ImplementerId == model.ImplementerId && order.Status == model.OrderStatus) + { + return AccessPastryStorage(order.GetViewModel); + } + } + } + else + { + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return AccessPastryStorage(order.GetViewModel); + } } } return null; diff --git a/Confectionery/ConfectioneryListImplement/Models/Implementer.cs b/Confectionery/ConfectioneryListImplement/Models/Implementer.cs new file mode 100644 index 0000000..9ed947c --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Implementer.cs @@ -0,0 +1,58 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id {get; private set;} + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification, + }; + } + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/Confectionery/ConfectioneryListImplement/Models/Order.cs b/Confectionery/ConfectioneryListImplement/Models/Order.cs index 1ecada8..7cec4ca 100644 --- a/Confectionery/ConfectioneryListImplement/Models/Order.cs +++ b/Confectionery/ConfectioneryListImplement/Models/Order.cs @@ -17,6 +17,7 @@ namespace ConfectioneryListImplement.Models public int Id {get; private set;} public int PastryId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } @@ -40,7 +41,7 @@ namespace ConfectioneryListImplement.Models Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement + DateImplement = model.DateImplement, }; } public void Update(OrderBindingModel? model) @@ -50,6 +51,7 @@ namespace ConfectioneryListImplement.Models return; } Status = model.Status; + ImplementerId = model.ImplementerId; if (model.DateImplement.HasValue) DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() diff --git a/Confectionery/ConfectioneryRestApi/Controllers/ImplementerController.cs b/Confectionery/ConfectioneryRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..bbf0505 --- /dev/null +++ b/Confectionery/ConfectioneryRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,107 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace ConfectioneryRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + + private readonly IOrderLogic _order; + + private readonly IImplementerLogic _logic; + + public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка авторизации сотрудника"); + throw; + } + } + + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + OrderStatus = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + throw; + } + } + + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id); + throw; + } + } + + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id); + throw; + } + } + } +} diff --git a/Confectionery/ConfectioneryRestApi/Program.cs b/Confectionery/ConfectioneryRestApi/Program.cs index c549db0..5f2e382 100644 --- a/Confectionery/ConfectioneryRestApi/Program.cs +++ b/Confectionery/ConfectioneryRestApi/Program.cs @@ -11,10 +11,12 @@ builder.Logging.AddLog4Net("log4net.config"); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer();