diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Enums/OrderStatus.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Enums/OrderStatus.cs index fed7b40..21e22a3 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Enums/OrderStatus.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Enums/OrderStatus.cs @@ -6,6 +6,7 @@ Принят = 0, Выполняется = 1, Готов = 2, - Выдан = 3 - } + Ожидает = 3, + Выдан = 4 + } } \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IImplementerModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..cccdddc --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IImplementerModel.cs @@ -0,0 +1,17 @@ +using JewelryShopDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IOrderModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IOrderModel.cs index d0fd099..601e0cb 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IOrderModel.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryShopDataModels/Models/IOrderModel.cs @@ -8,6 +8,7 @@ namespace JewelryStoreDataModels.Models int JewelId { get; } int Count { get; } double Sum { get; } + int? ImplementerId { get; } OrderStatus Status { get; } DateTime DateCreate { get; } DateTime? DateImplement { get; } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormClients.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormClients.Designer.cs index 845072c..27694c7 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormClients.Designer.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormClients.Designer.cs @@ -74,7 +74,7 @@ this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.dataGridView); this.Name = "FormClients"; - this.Text = "Клиенты"; + this.Text = "FormClient"; ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementer.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementer.Designer.cs new file mode 100644 index 0000000..a5a7929 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementer.Designer.cs @@ -0,0 +1,167 @@ +namespace JewelryStore +{ + 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.labelFIO = new System.Windows.Forms.Label(); + this.textBoxFIO = new System.Windows.Forms.TextBox(); + this.labelPassword = new System.Windows.Forms.Label(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.labelWorkExperience = new System.Windows.Forms.Label(); + this.numericUpDownWorkExperience = new System.Windows.Forms.NumericUpDown(); + this.labelQualification = new System.Windows.Forms.Label(); + this.numericUpDownQualification = new System.Windows.Forms.NumericUpDown(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).BeginInit(); + this.SuspendLayout(); + // + // labelFIO + // + this.labelFIO.AutoSize = true; + this.labelFIO.Location = new System.Drawing.Point(12, 21); + this.labelFIO.Name = "labelFIO"; + this.labelFIO.Size = new System.Drawing.Size(56, 25); + this.labelFIO.TabIndex = 0; + this.labelFIO.Text = "ФИО:"; + // + // textBoxFIO + // + this.textBoxFIO.Location = new System.Drawing.Point(96, 18); + this.textBoxFIO.Name = "textBoxFIO"; + this.textBoxFIO.Size = new System.Drawing.Size(355, 31); + this.textBoxFIO.TabIndex = 1; + // + // labelPassword + // + this.labelPassword.AutoSize = true; + this.labelPassword.Location = new System.Drawing.Point(12, 71); + this.labelPassword.Name = "labelPassword"; + this.labelPassword.Size = new System.Drawing.Size(78, 25); + this.labelPassword.TabIndex = 2; + this.labelPassword.Text = "Пароль:"; + // + // textBoxPassword + // + this.textBoxPassword.Location = new System.Drawing.Point(96, 68); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.Size = new System.Drawing.Size(355, 31); + this.textBoxPassword.TabIndex = 3; + // + // labelWorkExperience + // + this.labelWorkExperience.AutoSize = true; + this.labelWorkExperience.Location = new System.Drawing.Point(12, 119); + this.labelWorkExperience.Name = "labelWorkExperience"; + this.labelWorkExperience.Size = new System.Drawing.Size(126, 25); + this.labelWorkExperience.TabIndex = 4; + this.labelWorkExperience.Text = "Опыт работы:"; + // + // numericUpDownWorkExperience + // + this.numericUpDownWorkExperience.Location = new System.Drawing.Point(152, 117); + this.numericUpDownWorkExperience.Name = "numericUpDownWorkExperience"; + this.numericUpDownWorkExperience.Size = new System.Drawing.Size(299, 31); + this.numericUpDownWorkExperience.TabIndex = 5; + // + // labelQualification + // + this.labelQualification.AutoSize = true; + this.labelQualification.Location = new System.Drawing.Point(12, 169); + this.labelQualification.Name = "labelQualification"; + this.labelQualification.Size = new System.Drawing.Size(134, 25); + this.labelQualification.TabIndex = 6; + this.labelQualification.Text = "Квалификация:"; + // + // numericUpDownQualification + // + this.numericUpDownQualification.Location = new System.Drawing.Point(152, 163); + this.numericUpDownQualification.Name = "numericUpDownQualification"; + this.numericUpDownQualification.Size = new System.Drawing.Size(299, 31); + this.numericUpDownQualification.TabIndex = 7; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(204, 218); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + this.buttonSave.TabIndex = 8; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(339, 218); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 9; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(471, 271); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.numericUpDownQualification); + this.Controls.Add(this.labelQualification); + this.Controls.Add(this.numericUpDownWorkExperience); + this.Controls.Add(this.labelWorkExperience); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.labelPassword); + this.Controls.Add(this.textBoxFIO); + this.Controls.Add(this.labelFIO); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelFIO; + private TextBox textBoxFIO; + private Label labelPassword; + private TextBox textBoxPassword; + private Label labelWorkExperience; + private NumericUpDown numericUpDownWorkExperience; + private Label labelQualification; + private NumericUpDown numericUpDownQualification; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementer.cs new file mode 100644 index 0000000..ba443ce --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementer.cs @@ -0,0 +1,103 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.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 JewelryStore +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logicI; + private int? _id; + public int Id { set { _id = value; } } + + public FormImplementer(ILogger logger, IImplementerLogic logicI) + { + InitializeComponent(); + _logger = logger; + _logicI = logicI; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + MessageBox.Show("Заполните фио", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + Password = textBoxPassword.Text, + Qualification = (int)numericUpDownQualification.Value, + WorkExperience = (int)numericUpDownWorkExperience.Value, + }; + var operationResult = _id.HasValue ? _logicI.Update(model) : _logicI.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(); + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logicI.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFIO.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + numericUpDownQualification.Value = view.Qualification; + numericUpDownWorkExperience.Value = view.WorkExperience; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementer.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementers.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementers.Designer.cs new file mode 100644 index 0000000..14cd4f0 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementers.Designer.cs @@ -0,0 +1,116 @@ +namespace JewelryStore +{ + 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonRefresh = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Window; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(633, 432); + this.dataGridView.TabIndex = 0; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(689, 264); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(164, 34); + this.buttonUpdate.TabIndex = 8; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(689, 193); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(164, 34); + this.buttonDelete.TabIndex = 7; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(689, 122); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(164, 34); + this.buttonRefresh.TabIndex = 6; + this.buttonRefresh.Text = "Изменить"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(689, 53); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(164, 34); + this.buttonAdd.TabIndex = 5; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(891, 450); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonRefresh); + 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 DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementers.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementers.cs new file mode 100644 index 0000000..04c5fae --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementers.cs @@ -0,0 +1,121 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.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 JewelryStore +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logicI; + + public FormImplementers(ILogger logger, IImplementerLogic logicI) + { + InitializeComponent(); + _logger = logger; + _logicI = logicI; + } + + private void LoadData() + { + try + { + var list = _logicI.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 ButtonRefresh_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 ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + + _logger.LogInformation("Удаление исполнителя"); + + try + { + if (!_logicI.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 ButtonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementers.resx b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormImplementers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/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/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs index 2346b90..87cf920 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.Designer.cs @@ -36,10 +36,9 @@ 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.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.buttonRefresh = new System.Windows.Forms.Button(); this.пополнениеМагазинаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -53,7 +52,7 @@ this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.СправочникиToolStripMenuItem, this.отчетыToolStripMenuItem, - this.клиентыToolStripMenuItem}); + this.запускРаботToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1121, 33); @@ -115,6 +114,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(136, 29); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.ЗапускРаботToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Window; @@ -136,29 +142,9 @@ this.buttonCreateOrder.UseVisualStyleBackColor = true; this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); // - // buttonTakeOrderInWork - // - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(884, 150); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(210, 34); - 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(884, 221); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(210, 34); - 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(884, 292); + this.buttonIssuedOrder.Location = new System.Drawing.Point(884, 160); this.buttonIssuedOrder.Name = "buttonIssuedOrder"; this.buttonIssuedOrder.Size = new System.Drawing.Size(210, 34); this.buttonIssuedOrder.TabIndex = 5; @@ -168,7 +154,7 @@ // // buttonRefresh // - this.buttonRefresh.Location = new System.Drawing.Point(884, 361); + this.buttonRefresh.Location = new System.Drawing.Point(884, 242); this.buttonRefresh.Name = "buttonRefresh"; this.buttonRefresh.Size = new System.Drawing.Size(210, 34); this.buttonRefresh.TabIndex = 6; @@ -190,8 +176,6 @@ this.ClientSize = new System.Drawing.Size(1121, 450); this.Controls.Add(this.buttonRefresh); this.Controls.Add(this.buttonIssuedOrder); - this.Controls.Add(this.buttonOrderReady); - this.Controls.Add(this.buttonTakeOrderInWork); this.Controls.Add(this.buttonCreateOrder); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip); @@ -215,14 +199,13 @@ private ToolStripMenuItem ИзделияToolStripMenuItem; private DataGridView dataGridView; private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRefresh; private ToolStripMenuItem отчетыToolStripMenuItem; private ToolStripMenuItem списокИзделийToolStripMenuItem; private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; - private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; } } \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs index 6bebb72..946c33a 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/FormMain.cs @@ -14,14 +14,15 @@ namespace JewelryStore 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, IWorkProcess workProcess, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) @@ -39,6 +40,7 @@ namespace JewelryStore dataGridView.DataSource = list; dataGridView.Columns["JewelId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs index 0e71b88..7271730 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStore/Program.cs @@ -40,22 +40,28 @@ namespace JewelryStore 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(); 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(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/ImplementerLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..89e87e1 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,128 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesModels; +using JewelryStoreContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.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. ImplementerFIO:{ImplementerFIO}.Password:{Password}.Id:{ Id}", model?.ImplementerFIO, model?.Password?.Length, model?.Id); + 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. ImplementerFIO:{ImplementerFIO}.Password:{Password}.Id:{ Id}", model?.ImplementerFIO, model?.Password?.Length, model?.Id); + 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("Квалификация должна быть положительной", nameof(model.Qualification)); + } + _logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}.Password:{Password}.WorkExperience:{WorkExperience}.Qualification:{Qualification}.Id: { Id}", + model.ImplementerFIO, model.Password, model.WorkExperience, model.Qualification, model.Id); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs index 74ea89c..51a7098 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs @@ -1,149 +1,194 @@ -using JewelryStoreContracts.BindingModels; +using JewelryStoreDataModels.Enums; +using Microsoft.Extensions.Logging; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.StoragesContracts; -using JewelryStoreContracts.StoragesModels; using JewelryStoreContracts.ViewModels; using JewelryStoreDataModels.Enums; -using Microsoft.Extensions.Logging; namespace JewelryStoreBusinessLogic.BusinessLogics { - public class OrderLogic : IOrderLogic - { - private readonly ILogger _logger; - private readonly IOrderStorage _orderStorage; - private readonly IStoreStorage _shopStorage; + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + static readonly object _locker = new object(); + private readonly IShopStorage _shopStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage, IStoreStorage shopStorage) - { - _logger = logger; - _orderStorage = orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage) + { + _logger = logger; + _orderStorage = orderStorage; _shopStorage = shopStorage; } - public bool CreateOrder(OrderBindingModel model) - { - CheckModel(model); - if (model.Status != OrderStatus.Неизвестен) return false; - model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - - public bool DeliveryOrder(OrderBindingModel model) - { - var order = _orderStorage.GetElement(new OrderSearchModel + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) { - Id = model.Id, + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}", + model.ClientId, model.Status, model.ImplementerId, model.DateFrom, model.DateTo, model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}", + model?.ClientId, model?.Status, model?.ImplementerId, model?.DateFrom, model?.DateTo, model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + lock (_locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + lock (_locker) + { + model = FillOrderBindingModel(model); + if (model.Status != OrderStatus.Готов && model.Status != OrderStatus.Ожидает) + { + _logger.LogWarning("Changing status operation faled: Current-{Status}:required-Выдан.", model.Status); + throw new InvalidOperationException($"Невозможно приствоить статус выдан заказу с текущим статусом {model.Status}"); + } + if (!_shopStorage.RestockingShops(new SupplyBindingModel + { + JewelId = model.JewelId, + Count = model.Count + })) + { + if (model.Status == OrderStatus.Готов || model.Status == OrderStatus.Ожидает) + { + model.Status = OrderStatus.Ожидает; + return UpdateOrder(model); + } + } + model.Status = OrderStatus.Выдан; + return UpdateOrder(model); + } + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Count <= 0) + { + throw new ArgumentException("Колличество украшения в заказе не может быть меньше 1", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentException("Стоимость заказа на может быть меньше 1", nameof(model.Sum)); + } + if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) + { + throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}"); + } + _logger.LogInformation("Jewel. JewelId:{JewelId}.Count:{Count}.Sum:{Sum}Id:{Id}", + model.JewelId, model.Count, model.Sum, model.Id); + } + private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus) + { + model = FillOrderBindingModel(model); + + if (requiredStatus - model.Status == 1) + { + model.Status = requiredStatus; + if (model.Status == OrderStatus.Готов) + model.DateImplement = DateTime.Now; + return UpdateOrder(model); + } + _logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus); + throw new InvalidOperationException($"Невозможно приствоить статус {requiredStatus} заказу с текущим статусом {model.Status}"); + } + + private OrderBindingModel FillOrderBindingModel(OrderBindingModel model) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel() + { + Id = model.Id }); - if (order == null) + if (element == null) { - throw new ArgumentNullException(nameof(order)); + throw new InvalidOperationException(nameof(element)); } - if (!_shopStorage.RestockingShops(new SupplyBindingModel + model.Id = element.Id; + model.DateCreate = element.DateCreate; + model.JewelId = element.JewelId; + model.DateImplement = element.DateImplement; + model.ClientId = element.ClientId; + model.Status = element.Status; + model.Count = element.Count; + model.Sum = element.Sum; + if (!model.ImplementerId.HasValue) { - JewelId = order.JewelId, - Count = order.Count - })) - { - throw new ArgumentException("Недостаточно места"); + model.ImplementerId = element.ImplementerId; } + return model; + } - model.Status = OrderStatus.Выдан; - model.DateImplement = DateTime.Now; - _orderStorage.Update(model); - return true; - } - - public bool FinishOrder(OrderBindingModel model) - { - 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; - } - - public List? ReadList(OrderSearchModel? model) - { - _logger.LogInformation("ReadList. Id:{Id}", model?.Id); - var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - - public bool TakeOrderInWork(OrderBindingModel model) - { - 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; - } - - private void CheckModel(OrderBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.Sum <= 0) - { - throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); - } - if (model.Count <= 0) - { - throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); - } - _logger.LogInformation("Order. Sum:{Sum}. Id:{Id}", model.Sum, model.Id); - var element = _orderStorage.GetElement(new OrderSearchModel - { - Id = model.Id - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Заказ с таким ID уже существует"); - } - } - } -} \ No newline at end of file + private bool UpdateOrder(OrderBindingModel model) + { + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + _logger.LogWarning("Update operation sucsess"); + return true; + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..ac3eb35 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,186 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Enums; +using Microsoft.Extensions.Logging; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Enums; + +namespace JewelryStoreBusinessLogic.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 { Status = OrderStatus.Выдан }); + int count = _orderLogic.ReadList(null).Count; + if (orders == null || count == orders.Count) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + orders = _orderLogic.ReadList(null); + _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) + { + return; + } + await DeliverWaitingOrder(implementer); + await RunOrderInWork(implementer); + + await Task.Run(() => + { + 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 + }); + // делаем работу + Thread.Sleep(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 + }); + _orderLogic.DeliveryOrder(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; + } + // отдыхаем + Thread.Sleep(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, + Status = OrderStatus.Выполняется + })); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + // доделываем работу + Thread.Sleep(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 + }); + _orderLogic.DeliveryOrder(new OrderBindingModel { Id = runOrder.Id }); + // отдыхаем + Thread.Sleep(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; + } + } + + private async Task DeliverWaitingOrder(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + var waitingOrders = await Task.Run(() => _orderLogic.ReadList(new OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Ожидает + })); + if (waitingOrders == null || waitingOrders.Count == 0) + { + return; + } + _logger.LogInformation("DeliverWaitingOrder. Find some waitig order for implementer:{id}.Count:{count}", implementer.Id, waitingOrders.Count); + foreach (var waitingOrder in waitingOrders) + { + try + { + _logger.LogInformation("DeliverWaitingOrder. Trying to deliver order id:{id}", waitingOrder.Id); + var res = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = waitingOrder.Id + }); + } + catch (ArgumentException ex) + { + _logger.LogWarning(ex, "DeliverWaitingOrder. Fault"); + } + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try deliver order"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreClientApp/Controllers/HomeController.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreClientApp/Controllers/HomeController.cs index 83bdc36..998a6d0 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreClientApp/Controllers/HomeController.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreClientApp/Controllers/HomeController.cs @@ -142,9 +142,9 @@ namespace JewelryStoreClientApp.Controllers [HttpPost] public double Calc(int count, int jewel) { - var jew = APIClient.GetRequest($"api/main/getjewel?jewelId={jewel}" + var prod = APIClient.GetRequest($"api/main/getjewel?jewelId={jewel}" ); - return count * (jew?.Price ?? 1); + return count * (prod?.Price ?? 1); } } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreClientApp/Views/Home/Create.cshtml b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreClientApp/Views/Home/Create.cshtml index c5e5c5a..b448a8c 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreClientApp/Views/Home/Create.cshtml +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreClientApp/Views/Home/Create.cshtml @@ -45,4 +45,4 @@ function check() { }); }; } - + \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreClientApp/Views/Home/Index.cshtml b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreClientApp/Views/Home/Index.cshtml index 188284f..e657f98 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreClientApp/Views/Home/Index.cshtml +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreClientApp/Views/Home/Index.cshtml @@ -1,4 +1,4 @@ -@using JewelryStoreContracts.ViewModels +@using JewelryStoreContracts.ViewModels @model List @{ ViewData["Title"] = "Home Page"; @@ -10,60 +10,60 @@ @{ if (Model == null) { -

Авторизируйтесь

+

Авторизируйтесь

return; } -

- Создать заказ -

- - - - - - - - - - - - - @foreach (var item in Model) - { - - - - - - - - - } - -
- Номер - - Изделие - - Дата создания - - Количество - - Сумма - - Статус -
- @Html.DisplayFor(modelItem => item.Id) - - @Html.DisplayFor(modelItem => item.JewelName) - - @Html.DisplayFor(modelItem => item.DateCreate) - - @Html.DisplayFor(modelItem => item.Count) - - @Html.DisplayFor(modelItem => item.Sum) - - @Html.DisplayFor(modelItem => item.Status) -
+

+ Создать заказ +

+ + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + + } + +
+ Номер + + Изделие + + Дата создания + + Количество + + Сумма + + Статус +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.JewelName) + + @Html.DisplayFor(modelItem => item.DateCreate) + + @Html.DisplayFor(modelItem => item.Count) + + @Html.DisplayFor(modelItem => item.Sum) + + @Html.DisplayFor(modelItem => item.Status) +
} - + \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/ImplementerBindingModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..5d9c8e3 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,22 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/OrderBindingModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/OrderBindingModel.cs index a1a6090..29296a4 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/OrderBindingModel.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BindingModels/OrderBindingModel.cs @@ -8,6 +8,7 @@ namespace JewelryStoreContracts.BindingModels public int Id { get; set; } public int JewelId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IImplementerLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..342b189 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,24 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs index e6afa1a..b852ac6 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -7,6 +7,7 @@ namespace JewelryStoreContracts.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/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..c74ede3 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/ImplementerSearchModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..72d4a52 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/OrderSearchModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/OrderSearchModel.cs index 32c0797..afbc0e7 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/OrderSearchModel.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,6 @@ -namespace JewelryStoreContracts.SearchModels +using JewelryStoreDataModels.Enums; + +namespace JewelryStoreContracts.SearchModels { public class OrderSearchModel { @@ -8,5 +10,8 @@ public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + + public int? ImplementerId { get; set; } + public List? Statuses { get; set; } } } \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IImplementerStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IImplementerStorage.cs new file mode 100644 index 0000000..65414cc --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/StoragesModels/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.StoragesModels +{ + 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/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/ImplementerViewModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..f84e6f7 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,27 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/OrderViewModel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/OrderViewModel.cs index 4bb9565..2d87c4b 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/OrderViewModel.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreContracts/ViewModels/OrderViewModel.cs @@ -10,6 +10,7 @@ namespace JewelryStoreContracts.ViewModels public int Id { get; set; } public int JewelId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } [DisplayName("Изделие")] public string JewelName { get; set; } = string.Empty; @@ -27,5 +28,8 @@ namespace JewelryStoreContracts.ViewModels [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; + + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..82cfb95 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,84 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public List GetFullList() + { + using var context = new JewelryStoreDatabase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + using var context = new JewelryStoreDatabase(); + return context.Implementers.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)).Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue) + { + return null; + } + using var context = new JewelryStoreDatabase(); + return context.Implementers.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO && (!string.IsNullOrEmpty(model.Password) ? x.Password == model.Password : true)) || + (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 JewelryStoreDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new JewelryStoreDatabase(); + var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + context.SaveChanges(); + return implementer.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new JewelryStoreDatabase(); + var implementer = context.Implementers.FirstOrDefault(rec => rec.Id == model.Id); + if (implementer != null) + { + context.Implementers.Remove(implementer); + context.SaveChanges(); + return implementer.GetViewModel; + } + return null; + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs index d61d97e..defc615 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs @@ -17,37 +17,34 @@ namespace JewelryStoreDatabaseImplement.Implements public List GetFullList() { using var context = new JewelryStoreDatabase(); - return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); - } - public List GetFilteredList(OrderSearchModel model) - { - if (!model.DateFrom.HasValue || !model.DateTo.HasValue ||!model.Id.HasValue) - { - return new(); - } - using var context = new JewelryStoreDatabase(); - if (model.DateFrom.HasValue) - { - return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) - .Select(x => x.GetViewModel).ToList(); - } - else if (model.ClientId.HasValue) - { - return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Where(x => x.ClientId == model.ClientId) - .Select(x => x.GetViewModel).ToList(); - } - return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); - } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return new(); - } - using var context = new JewelryStoreDatabase(); - return AccessJewelStorage(context.Orders.Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel, context); - } - public OrderViewModel? Insert(OrderBindingModel model) + return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Include(y => y.Implementer).Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(OrderSearchModel model) + { + using var context = new JewelryStoreDatabase(); + if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue) + { + return new(); + } + return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Include(x => x.Implementer).Where(x => + (model.DateFrom.HasValue && model.DateTo.HasValue && x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) || + (model.ClientId.HasValue && x.ClientId == model.ClientId) || + (model.Status.HasValue && x.Status == model.Status)) + .Select(x => x.GetViewModel).ToList(); + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue)) + { + return new(); + } + using var context = new JewelryStoreDatabase(); + return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => + (model.Id.HasValue && x.Id == model.Id) || + (model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && x.Status == model.Status)) + ?.GetViewModel; + } + public OrderViewModel? Insert(OrderBindingModel model) { var newOrder = Order.Create(model); if (newOrder == null) @@ -57,24 +54,24 @@ namespace JewelryStoreDatabaseImplement.Implements using var context = new JewelryStoreDatabase(); context.Orders.Add(newOrder); context.SaveChanges(); - return AccessJewelStorage(context.Orders.Include(x => x.Jewel).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel, context); + return AccessJewelStorage(context.Orders.Include(x => x.Jewel).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel, context); } public OrderViewModel? Update(OrderBindingModel model) { using var context = new JewelryStoreDatabase(); - var order = context.Orders.Include(x => x.Jewel).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - order.Update(model); - context.SaveChanges(); - return AccessJewelStorage(order.GetViewModel, context); - } + var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(context, model); + context.SaveChanges(); + return order.GetViewModel; + } public OrderViewModel? Delete(OrderBindingModel model) { using var context = new JewelryStoreDatabase(); - var element = context.Orders.Include(x => x.Jewel).Include(x => x.Client).FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Orders.Include(x => x.Jewel).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Orders.Remove(element); diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/JewelryStoreDatabase.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/JewelryStoreDatabase.cs index 3faa4d1..9f93f61 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/JewelryStoreDatabase.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/JewelryStoreDatabase.cs @@ -25,6 +25,7 @@ namespace JewelryStoreDatabaseImplement public virtual DbSet Orders { set; get; } public virtual DbSet Shops { get; set; } public virtual DbSet ShopJewels { get; set; } + public virtual DbSet Implementers { set; get; } } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Migrations/20230513055059_AddImplementer.Designer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Migrations/20230513055059_AddImplementer.Designer.cs new file mode 100644 index 0000000..edecbf5 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Migrations/20230513055059_AddImplementer.Designer.cs @@ -0,0 +1,257 @@ +// +using System; +using JewelryStoreDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace JewelryStoreDatabaseImplement.Migrations +{ + [DbContext(typeof(JewelryStoreDatabase))] + [Migration("20230513055059_AddImplementer")] + partial class AddImplementer + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.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("JewelryStoreDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.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("JewelryStoreDatabaseImplement.Models.Jewel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("JewelName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Jewels"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.JewelComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("JewelId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("JewelId"); + + b.ToTable("JewelComponents"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.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("JewelId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("JewelId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.JewelComponent", b => + { + b.HasOne("JewelryStoreDatabaseImplement.Models.Component", "Component") + .WithMany("JewelComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel") + .WithMany("Components") + .HasForeignKey("JewelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Jewel"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b => + { + b.HasOne("JewelryStoreDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("JewelryStoreDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel") + .WithMany("Orders") + .HasForeignKey("JewelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Jewel"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Component", b => + { + b.Navigation("JewelComponents"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Migrations/20230513055059_AddImplementer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Migrations/20230513055059_AddImplementer.cs new file mode 100644 index 0000000..ff22146 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Migrations/20230513055059_AddImplementer.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace JewelryStoreDatabaseImplement.Migrations +{ + /// + public partial class implementors : 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/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDatabaseModelSnapshot.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDatabaseModelSnapshot.cs index deaa3dd..87b737e 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDatabaseModelSnapshot.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDatabaseModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; -using JewelryStoreDatabaseImplement; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using JewelryStoreDatabaseImplement; #nullable disable @@ -67,6 +67,33 @@ namespace JewelryStoreDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.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("JewelryStoreDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -87,6 +114,9 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("JewelId") .HasColumnType("int"); @@ -100,6 +130,8 @@ namespace JewelryStoreDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("JewelId"); b.ToTable("Orders"); @@ -212,6 +244,10 @@ namespace JewelryStoreDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("JewelryStoreDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); + b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel") .WithMany("Orders") .HasForeignKey("JewelId") @@ -220,6 +256,8 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Jewel"); }); @@ -271,6 +309,11 @@ namespace JewelryStoreDatabaseImplement.Migrations b.Navigation("JewelComponents"); }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); + modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => { b.Navigation("Components"); diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Implementer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..eb6fd12 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,71 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + + [Required] + public string Password { get; private set; } = string.Empty; + + [Required] + public int WorkExperience { get; private set; } + + [Required] + public int Qualification { get; private set; } + + public int Id { get; private set; } + + [ForeignKey("ImplementerId")] + public virtual List Orders { get; private set; } = new(); + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience + }; + } +} + diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Order.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Order.cs index ed397be..f06dab0 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Order.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreDatabaseImplement/Models/Order.cs @@ -14,70 +14,81 @@ namespace JewelryStoreDatabaseImplement.Models { public class Order : IOrderModel { - public int Id { get; private set; } - [Required] - public int JewelId { get; set; } - [Required] - public int Count { get; set; } - [Required] - public double Sum { get; set; } - [Required] - public OrderStatus Status { get; set; } - [Required] - public int ClientId { get; set; } - [Required] - public DateTime DateCreate { get; set; } - public DateTime? DateImplement { get; set; } - public Jewel Jewel { get; set; } - public Client Client { get; set; } + public int Id { get; private set; } - public static Order? Create(OrderBindingModel? model) - { - if (model == null) - { - return null; - } - return new Order() - { - Id = model.Id, - JewelId = model.JewelId, - ClientId = model.ClientId, - Count = model.Count, - Sum = model.Sum, - Status = model.Status, - DateCreate = model.DateCreate, - DateImplement = model.DateImplement - }; - } - public void Update(OrderBindingModel? model) - { - if (model == null) - { - return; - } - Status = model.Status; - if (model.DateImplement.HasValue) DateImplement = model.DateImplement; - } - public OrderViewModel GetViewModel - { - get - { - using var context = new JewelryStoreDatabase(); - return new OrderViewModel - { - Id = Id, - JewelId = JewelId, - ClientId = ClientId, - ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, - JewelName = context.Jewels.FirstOrDefault(x => x.Id == JewelId)?.JewelName ?? string.Empty, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement - }; - } + [Required] + public int ClientId { get; private set; } - } - } + public virtual Client Client { get; private set; } = new(); + + [Required] + public int JewelId { get; private set; } + + public virtual Jewel Jewel { get; set; } = new(); + + public int? ImplementerId { get; private set; } + + public virtual Implementer? Implementer { get; set; } = new(); + + [Required] + public int Count { get; private set; } + + [Required] + public double Sum { get; private set; } + + [Required] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + [Required] + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public static Order Create(JewelryStoreDatabase context, OrderBindingModel model) + { + return new Order() + { + Id = model.Id, + ClientId = model.ClientId, + Client = context.Clients.First(x => x.Id == model.ClientId), + JewelId = model.JewelId, + Jewel = context.Jewels.First(x => x.Id == model.JewelId), + ImplementerId = model.ImplementerId, + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + + public void Update(JewelryStoreDatabase context, OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + ClientId = ClientId, + ClientFIO = Client.ClientFIO, + JewelId = JewelId, + JewelName = Jewel.JewelName, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/DataFileSingleton.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/DataFileSingleton.cs index 8f3de86..bf7c14e 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/DataFileSingleton.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/DataFileSingleton.cs @@ -11,11 +11,13 @@ namespace JewelryStoreFileImplement private readonly string JewelFileName = "Jewel.xml"; private readonly string ClientFileName = "Client.xml"; private readonly string ShopFileName = "Shop.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Jewels { get; private set; } public List Clients { get; private set; } public List Shops { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { @@ -34,6 +36,7 @@ namespace JewelryStoreFileImplement public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement); public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { @@ -42,6 +45,7 @@ namespace JewelryStoreFileImplement Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/Implements/ImplementerStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..ead8aed --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,99 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreFileImplement.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 (model == null) + { + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + if (model.ImplementerFIO != null) + { + return _source.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (model.Id.HasValue) + { + return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + if (model.ImplementerFIO != null && model.Password != null) + { + return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel; + } + if (model.ImplementerFIO != null) + { + return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + } + return null; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; + var res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + _source.Implementers.Remove(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/Implements/OrderStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/Implements/OrderStorage.cs index 6515a8f..87f64f6 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/Implements/OrderStorage.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/Implements/OrderStorage.cs @@ -1,4 +1,5 @@ -using JewelryStoreContracts.BindingModels; +using DocumentFormat.OpenXml.Bibliography; +using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.StoragesContracts; using JewelryStoreContracts.ViewModels; @@ -13,96 +14,122 @@ namespace JewelryStoreFileImplement.Implements { public class OrderStorage : IOrderStorage { - private readonly DataFileSingleton _source; - public OrderStorage() - { - _source = DataFileSingleton.GetInstance(); - } - public List GetFullList() - { - return _source.Orders.Select(x => SAddJewelName(x.GetViewModel)).ToList(); - } - public List GetFilteredList(OrderSearchModel model) - { - if (model.DateFrom.HasValue) - { - return _source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => GetViewModel(x)).ToList(); - } - if (model.ClientId.HasValue && !model.Id.HasValue) - { - return _source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); - } - if (model.Id.HasValue) - { - return _source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList(); - } - return new(); - } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - return SAddJewelName(_source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel); - } - public OrderViewModel? Insert(OrderBindingModel model) - { - model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 1; - var newOrder = Order.Create(model); - if (newOrder == null) - { - return null; - } - _source.Orders.Add(newOrder); - _source.SaveOrders(); - return SAddJewelName(newOrder.GetViewModel); - } - public OrderViewModel? Update(OrderBindingModel model) - { - var order = _source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - order.Update(model); - _source.SaveOrders(); - return SAddJewelName(order.GetViewModel); - } - public OrderViewModel? Delete(OrderBindingModel model) - { - var element = _source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (element != null) - { - _source.Orders.Remove(element); - _source.SaveOrders(); - return SAddJewelName(element.GetViewModel); - } - return null; - } + private readonly DataFileSingleton source; - public OrderViewModel SAddJewelName(OrderViewModel fullModel) - { - string? jewelName = _source.Jewels.FirstOrDefault(x => x.Id == fullModel?.JewelId)?.JewelName; - if (jewelName != null) fullModel.JewelName = jewelName; - return fullModel; - } + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } - private OrderViewModel GetViewModel(Order order) - { - var viewModel = order.GetViewModel; + public List GetFullList() => source.Orders.Select(x => AttachJewelName(x.GetViewModel)).ToList(); + + public List GetFilteredList(OrderSearchModel model) + { + if (model.DateFrom.HasValue) + { + return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => GetViewModel(x)).ToList(); + } + + if (model.ClientId.HasValue && !model.Id.HasValue) + { + return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); + } + + if (!model.ImplementerId.HasValue && !model.Id.HasValue) + { + return source.Orders.Where(x => x.ImplementerId == model.ImplementerId).Select(x => x.GetViewModel).ToList(); + + } + + if (model.Id.HasValue) + { + return source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList(); + } + return new(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (model.ImplementerId.HasValue) + { + return source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel; + } + if (!model.Id.HasValue) + { + return new(); + } + return AttachJewelName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel); + } + + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + + var Jewel = source.Jewels.FirstOrDefault(x => x.Id == order.JewelId); + var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId); + + if (Jewel != null) + { + viewModel.JewelName = Jewel.JewelName; + } + if (client != null) + { + viewModel.ClientFIO = client.ClientFIO; + } + return viewModel; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return AttachJewelName(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return AttachJewelName(order.GetViewModel); + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order != null) + { + source.Orders.Remove(order); + source.SaveOrders(); + return AttachJewelName(order.GetViewModel); + } + return null; + } + + private OrderViewModel? AttachJewelName(OrderViewModel? model) + { + if (model == null) + { + return null; + } + var Jewel = source.Jewels.FirstOrDefault(x => x.Id == model.JewelId); + if (Jewel != null) + { + model.JewelName = Jewel.JewelName; + } + return model; + } + } - var jewel = _source.Jewels.FirstOrDefault(x => x.Id == order.JewelId); - var client = _source.Clients.FirstOrDefault(x => x.Id == order.ClientId); - if (jewel != null) - { - viewModel.JewelName = jewel.JewelName; - } - if (client != null) - { - viewModel.ClientFIO = client.ClientFIO; - } - return viewModel; - } - } } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj index 8995315..ff6099f 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/Models/Implementer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..e6b305f --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/Models/Implementer.cs @@ -0,0 +1,86 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace JewelryStoreFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public int Id { get; private set; } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + }; + } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("Password", Password), + new XElement("FIO", ImplementerFIO), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/Models/Order.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/Models/Order.cs index 5239547..373e56d 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/Models/Order.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreFileImplement/Models/Order.cs @@ -15,6 +15,7 @@ namespace JewelryStoreFileImplement.Models { public int JewelId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -33,6 +34,7 @@ namespace JewelryStoreFileImplement.Models Id = model.Id, JewelId = model.JewelId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -53,6 +55,7 @@ namespace JewelryStoreFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), JewelId = Convert.ToInt32(element.Element("JewelId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), @@ -80,6 +83,7 @@ namespace JewelryStoreFileImplement.Models Id = Id, JewelId = JewelId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, @@ -91,6 +95,7 @@ namespace JewelryStoreFileImplement.Models new XAttribute("Id", Id), new XElement("JewelId", JewelId), new XElement("ClientId", ClientId.ToString()), + new XElement("ImplementerId", ImplementerId.ToString()), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/DataListSingleton.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/DataListSingleton.cs index 896f93f..364e5b9 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/DataListSingleton.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/DataListSingleton.cs @@ -9,14 +9,16 @@ namespace JewelryStoreListImplement public List Orders { get; set; } public List Jewels { get; set; } public List Stores { get; set; } + public List Implementers { get; set; } - private DataListSingleton() + private DataListSingleton() { Components = new List(); Orders = new List(); Jewels = new List(); - Stores = new List(); - } + Stores = new List(); + Implementers = new List(); + } public static DataListSingleton GetInstance() { diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/ImplementerStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..abcc623 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,123 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + 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; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var x in _source.Implementers) + { + if (model.Id.HasValue && x.Id == model.Id) + { + return x.GetViewModel; + } + if (model.ImplementerFIO != null && model.Password != null && x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password)) + { + return x.GetViewModel; + } + if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO)) + { + return x.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + + List result = new(); + if (model.ImplementerFIO != null) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Equals(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + + 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 res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + } + return res?.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; + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs index 6f53bfc..15eba32 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs @@ -8,155 +8,168 @@ namespace JewelryStoreListImplement.Implements { public class OrderStorage : IOrderStorage { - private readonly DataListSingleton _source; + private readonly DataListSingleton _source; - public OrderStorage() - { - _source = DataListSingleton.GetInstance(); - } + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } - public List GetFullList() - { - var result = new List(); - foreach (var order in _source.Orders) - { - result.Add(AccessJewelStorage(order.GetViewModel)); - } - return result; - } + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(AttachJewelName(order.GetViewModel)); + } + return result; + } - public List GetFilteredList(OrderSearchModel model) - { - var result = new List(); - if (model.DateFrom.HasValue) - { - return result; - foreach (var order in _source.Orders) - { - if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) - { - result.Add(GetViewModel(order)); - } - } - } - else if (model.ClientId.HasValue && !model.Id.HasValue) - { - foreach (var order in _source.Orders) - { - if (order.ClientId == model.ClientId) - { - result.Add(GetViewModel(order)); - } - } - } - else if (model.Id.HasValue) - { - foreach (var order in _source.Orders) - { - if (order.Id == model.Id) - { - result.Add(GetViewModel(order)); - } - } - } - return result; - } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model.DateFrom.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.ClientId.HasValue && !model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ClientId == model.ClientId) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.ImplementerId.HasValue && !model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ImplementerId == model.ImplementerId) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(GetViewModel(order)); + } + } + } + return result; + } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - foreach (var order in _source.Orders) - { - if (model.Id.HasValue && order.Id == model.Id) - { - return AccessJewelStorage(order.GetViewModel); - } - } - return null; - } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var package in _source.Jewels) + { + if (package.Id == order.JewelId) + { + viewModel.JewelName = package.JewelName; + break; + } + } + foreach (var client in _source.Clients) + { + if (client.Id == order.ClientId) + { + viewModel.ClientFIO = client.ClientFIO; + break; + } + } + return viewModel; + } - public OrderViewModel? Insert(OrderBindingModel model) - { - model.Id = 1; - foreach (var order in _source.Orders) - { - if (model.Id <= order.Id) - { - model.Id = order.Id + 1; - } - } - var newOrder = Order.Create(model); - if (newOrder == null) - { - return null; - } - _source.Orders.Add(newOrder); - return AccessJewelStorage(newOrder.GetViewModel); - } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return AttachJewelName(order.GetViewModel); + } + else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId) + { + return GetViewModel(order); + } + } + return null; + } - public OrderViewModel? Update(OrderBindingModel model) - { - foreach (var order in _source.Orders) - { - if (order.Id == model.Id) - { - order.Update(model); - return AccessJewelStorage(order.GetViewModel); - } - } - return null; - } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return AttachJewelName(newOrder.GetViewModel); + } - public OrderViewModel? Delete(OrderBindingModel model) - { - for (int i = 0; i < _source.Orders.Count; ++i) - { - if (_source.Orders[i].Id == model.Id) - { - var element = _source.Orders[i]; - _source.Orders.RemoveAt(i); - return AccessJewelStorage(element.GetViewModel); - } - } - return null; - } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AttachJewelName(order.GetViewModel); + } + } + return null; + } - public OrderViewModel AccessJewelStorage(OrderViewModel model) - { - foreach (var jewel in _source.Jewels) - { - if (jewel.Id == model.JewelId) - { - model.JewelName = jewel.JewelName; - break; - } - } - return model; - } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return AttachJewelName(element.GetViewModel); + } + } + return null; + } - private OrderViewModel GetViewModel(Order order) - { - var viewModel = order.GetViewModel; - foreach (var jewel in _source.Jewels) - { - if (jewel.Id == order.JewelId) - { - viewModel.JewelName = jewel.JewelName; - break; - } - } - foreach (var client in _source.Clients) - { - if (client.Id == order.ClientId) - { - viewModel.ClientFIO = client.ClientFIO; - break; - } - } - return viewModel; - } - } -} \ No newline at end of file + private OrderViewModel AttachJewelName(OrderViewModel model) + { + foreach (var Jewel in _source.Jewels) + { + if (Jewel.Id == model.JewelId) + { + model.JewelName = Jewel.JewelName; + return model; + } + } + return model; + } + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Implementer.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Implementer.cs new file mode 100644 index 0000000..51ee23a --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Implementer.cs @@ -0,0 +1,61 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Models +{ + public class Implementer : IImplementerModel + { + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public int Id { get; private set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience + }; + } +} diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Order.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Order.cs index 189031e..5690f09 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Order.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreListImplement/Models/Order.cs @@ -10,6 +10,7 @@ namespace JewelryStoreListImplement.Models public int Id { get; private set; } public int JewelId { 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; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -27,6 +28,7 @@ namespace JewelryStoreListImplement.Models Id = model.Id, JewelId = model.JewelId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -57,7 +59,8 @@ namespace JewelryStoreListImplement.Models Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement + DateImplement = DateImplement, + ImplementerId = ImplementerId }; } } \ No newline at end of file diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreRestApi/Controllers/ImplementerController.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..60e8ca0 --- /dev/null +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,103 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace JewelryStoreRestApi.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 + { + Statuses = new() { 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/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreRestApi/Program.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreRestApi/Program.cs index 447f0e9..9f468a3 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreRestApi/Program.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreRestApi/Program.cs @@ -16,10 +16,13 @@ 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.AddTransient(); +builder.Services.AddTransient(); + builder.Services.AddControllers();