diff --git a/FlowerShop/FlowerShop/FormImplementer.Designer.cs b/FlowerShop/FlowerShop/FormImplementer.Designer.cs new file mode 100644 index 0000000..ab28672 --- /dev/null +++ b/FlowerShop/FlowerShop/FormImplementer.Designer.cs @@ -0,0 +1,167 @@ +namespace FlowerShop +{ + 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.labelPassword = new System.Windows.Forms.Label(); + this.labelWorkExp = new System.Windows.Forms.Label(); + this.labelQualification = new System.Windows.Forms.Label(); + this.textBoxFIO = new System.Windows.Forms.TextBox(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.numericUpDownWorkExp = new System.Windows.Forms.NumericUpDown(); + 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.numericUpDownWorkExp)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).BeginInit(); + this.SuspendLayout(); + // + // labelFIO + // + this.labelFIO.AutoSize = true; + this.labelFIO.Location = new System.Drawing.Point(24, 47); + this.labelFIO.Name = "labelFIO"; + this.labelFIO.Size = new System.Drawing.Size(49, 20); + this.labelFIO.TabIndex = 0; + this.labelFIO.Text = "ФИО: "; + // + // labelPassword + // + this.labelPassword.AutoSize = true; + this.labelPassword.Location = new System.Drawing.Point(24, 92); + this.labelPassword.Name = "labelPassword"; + this.labelPassword.Size = new System.Drawing.Size(65, 20); + this.labelPassword.TabIndex = 1; + this.labelPassword.Text = "Пароль:"; + // + // labelWorkExp + // + this.labelWorkExp.AutoSize = true; + this.labelWorkExp.Location = new System.Drawing.Point(24, 134); + this.labelWorkExp.Name = "labelWorkExp"; + this.labelWorkExp.Size = new System.Drawing.Size(102, 20); + this.labelWorkExp.TabIndex = 2; + this.labelWorkExp.Text = "Стаж работы:"; + // + // labelQualification + // + this.labelQualification.AutoSize = true; + this.labelQualification.Location = new System.Drawing.Point(24, 177); + this.labelQualification.Name = "labelQualification"; + this.labelQualification.Size = new System.Drawing.Size(114, 20); + this.labelQualification.TabIndex = 3; + this.labelQualification.Text = "Квалификация:"; + // + // textBoxFIO + // + this.textBoxFIO.Location = new System.Drawing.Point(155, 47); + this.textBoxFIO.Name = "textBoxFIO"; + this.textBoxFIO.Size = new System.Drawing.Size(371, 27); + this.textBoxFIO.TabIndex = 4; + // + // textBoxPassword + // + this.textBoxPassword.Location = new System.Drawing.Point(155, 85); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.Size = new System.Drawing.Size(182, 27); + this.textBoxPassword.TabIndex = 5; + // + // numericUpDownWorkExp + // + this.numericUpDownWorkExp.Location = new System.Drawing.Point(155, 132); + this.numericUpDownWorkExp.Name = "numericUpDownWorkExp"; + this.numericUpDownWorkExp.Size = new System.Drawing.Size(182, 27); + this.numericUpDownWorkExp.TabIndex = 6; + // + // numericUpDownQualification + // + this.numericUpDownQualification.Location = new System.Drawing.Point(155, 175); + this.numericUpDownQualification.Name = "numericUpDownQualification"; + this.numericUpDownQualification.Size = new System.Drawing.Size(182, 27); + this.numericUpDownQualification.TabIndex = 7; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(324, 233); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(103, 29); + 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(433, 233); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(106, 29); + 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(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(551, 274); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.numericUpDownQualification); + this.Controls.Add(this.numericUpDownWorkExp); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.textBoxFIO); + this.Controls.Add(this.labelQualification); + this.Controls.Add(this.labelWorkExp); + this.Controls.Add(this.labelPassword); + this.Controls.Add(this.labelFIO); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExp)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelFIO; + private Label labelPassword; + private Label labelWorkExp; + private Label labelQualification; + private TextBox textBoxFIO; + private TextBox textBoxPassword; + private NumericUpDown numericUpDownWorkExp; + private NumericUpDown numericUpDownQualification; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormImplementer.cs b/FlowerShop/FlowerShop/FormImplementer.cs new file mode 100644 index 0000000..7a4aa1b --- /dev/null +++ b/FlowerShop/FlowerShop/FormImplementer.cs @@ -0,0 +1,98 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace FlowerShop +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение информации исполнителя"); + + var view = _logic.ReadElement(new ImplementerSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxFIO.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + numericUpDownQualification.Value = view.Qualification; + numericUpDownWorkExp.Value = view.WorkExperience; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(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)numericUpDownWorkExp.Value, + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormImplementer.resx b/FlowerShop/FlowerShop/FormImplementer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FlowerShop/FlowerShop/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/FlowerShop/FlowerShop/FormImplementers.Designer.cs b/FlowerShop/FlowerShop/FormImplementers.Designer.cs new file mode 100644 index 0000000..3037ba7 --- /dev/null +++ b/FlowerShop/FlowerShop/FormImplementers.Designer.cs @@ -0,0 +1,121 @@ +namespace FlowerShop +{ + 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.buttonCreate = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonRefresh = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonCreate + // + this.buttonCreate.Location = new System.Drawing.Point(584, 9); + this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(106, 34); + this.buttonCreate.TabIndex = 0; + this.buttonCreate.Text = "Добавить"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(584, 47); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(106, 34); + this.buttonEdit.TabIndex = 1; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(584, 85); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(106, 34); + this.buttonDelete.TabIndex = 2; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(584, 123); + this.buttonRefresh.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(106, 34); + this.buttonRefresh.TabIndex = 3; + this.buttonRefresh.Text = "Обновить"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(10, 9); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(568, 320); + this.dataGridView.TabIndex = 4; + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonRefresh); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonCreate); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormImplementers"; + this.Text = "Исполнители"; + this.Load += new System.EventHandler(this.FormImplementers_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonCreate; + private Button buttonEdit; + private Button buttonDelete; + private Button buttonRefresh; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormImplementers.cs b/FlowerShop/FlowerShop/FormImplementers.cs new file mode 100644 index 0000000..e8d5f44 --- /dev/null +++ b/FlowerShop/FlowerShop/FormImplementers.cs @@ -0,0 +1,106 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace FlowerShop +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCreate_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 buttonEdit_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 (!_logic.Delete(new ImplementerBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormImplementers.resx b/FlowerShop/FlowerShop/FormImplementers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FlowerShop/FlowerShop/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/FlowerShop/FlowerShop/FormMain.Designer.cs b/FlowerShop/FlowerShop/FormMain.Designer.cs index c141cfa..ffd2393 100644 --- a/FlowerShop/FlowerShop/FormMain.Designer.cs +++ b/FlowerShop/FlowerShop/FormMain.Designer.cs @@ -28,36 +28,25 @@ /// private void InitializeComponent() { - this.buttonReady = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreate = new System.Windows.Forms.Button(); - this.buttonToWork = new System.Windows.Forms.Button(); this.buttonPut = new System.Windows.Forms.Button(); this.buttonRefresh = new System.Windows.Forms.Button(); this.menuStrip = new System.Windows.Forms.MenuStrip(); this.guidesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.bouquetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.implementersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.listOfBouquetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.componentsByBouquetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.listOfOrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.doWorksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip.SuspendLayout(); this.SuspendLayout(); // - // buttonReady - // - this.buttonReady.Location = new System.Drawing.Point(891, 99); - this.buttonReady.Margin = new System.Windows.Forms.Padding(2); - this.buttonReady.Name = "buttonReady"; - this.buttonReady.Size = new System.Drawing.Size(150, 30); - this.buttonReady.TabIndex = 3; - this.buttonReady.Text = "Заказ готов"; - this.buttonReady.UseVisualStyleBackColor = true; - this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click); - // // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -66,12 +55,12 @@ this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 62; this.dataGridView.RowTemplate.Height = 33; - this.dataGridView.Size = new System.Drawing.Size(859, 359); + this.dataGridView.Size = new System.Drawing.Size(1093, 535); this.dataGridView.TabIndex = 0; // // buttonCreate // - this.buttonCreate.Location = new System.Drawing.Point(891, 31); + this.buttonCreate.Location = new System.Drawing.Point(1115, 31); this.buttonCreate.Margin = new System.Windows.Forms.Padding(2); this.buttonCreate.Name = "buttonCreate"; this.buttonCreate.Size = new System.Drawing.Size(150, 30); @@ -80,20 +69,9 @@ this.buttonCreate.UseVisualStyleBackColor = true; this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); // - // buttonToWork - // - this.buttonToWork.Location = new System.Drawing.Point(891, 65); - this.buttonToWork.Margin = new System.Windows.Forms.Padding(2); - this.buttonToWork.Name = "buttonToWork"; - this.buttonToWork.Size = new System.Drawing.Size(150, 30); - this.buttonToWork.TabIndex = 2; - this.buttonToWork.Text = "Отдать на выполнение"; - this.buttonToWork.UseVisualStyleBackColor = true; - this.buttonToWork.Click += new System.EventHandler(this.buttonToWork_Click); - // // buttonPut // - this.buttonPut.Location = new System.Drawing.Point(891, 133); + this.buttonPut.Location = new System.Drawing.Point(1115, 65); this.buttonPut.Margin = new System.Windows.Forms.Padding(2); this.buttonPut.Name = "buttonPut"; this.buttonPut.Size = new System.Drawing.Size(150, 30); @@ -104,7 +82,7 @@ // // buttonRefresh // - this.buttonRefresh.Location = new System.Drawing.Point(891, 167); + this.buttonRefresh.Location = new System.Drawing.Point(1115, 99); this.buttonRefresh.Margin = new System.Windows.Forms.Padding(2); this.buttonRefresh.Name = "buttonRefresh"; this.buttonRefresh.Size = new System.Drawing.Size(150, 30); @@ -118,11 +96,12 @@ this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.guidesToolStripMenuItem, - this.reportsToolStripMenuItem}); + this.reportsToolStripMenuItem, + this.doWorksToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Padding = new System.Windows.Forms.Padding(4, 1, 0, 1); - this.menuStrip.Size = new System.Drawing.Size(1071, 24); + this.menuStrip.Size = new System.Drawing.Size(1276, 24); this.menuStrip.TabIndex = 6; this.menuStrip.Text = "menuStrip1"; // @@ -131,7 +110,8 @@ this.guidesToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.componentsToolStripMenuItem, this.bouquetsToolStripMenuItem, - this.clientsToolStripMenuItem}); + this.clientsToolStripMenuItem, + this.implementersToolStripMenuItem}); this.guidesToolStripMenuItem.Name = "guidesToolStripMenuItem"; this.guidesToolStripMenuItem.Size = new System.Drawing.Size(94, 22); this.guidesToolStripMenuItem.Text = "Справочники"; @@ -139,17 +119,31 @@ // componentsToolStripMenuItem // this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; - this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.componentsToolStripMenuItem.Size = new System.Drawing.Size(149, 22); this.componentsToolStripMenuItem.Text = "Компоненты"; this.componentsToolStripMenuItem.Click += new System.EventHandler(this.componentsToolStripMenuItem_Click); // // bouquetsToolStripMenuItem // this.bouquetsToolStripMenuItem.Name = "bouquetsToolStripMenuItem"; - this.bouquetsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.bouquetsToolStripMenuItem.Size = new System.Drawing.Size(149, 22); this.bouquetsToolStripMenuItem.Text = "Букеты"; this.bouquetsToolStripMenuItem.Click += new System.EventHandler(this.bouquetsToolStripMenuItem_Click); // + // clientsToolStripMenuItem + // + this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; + this.clientsToolStripMenuItem.Size = new System.Drawing.Size(149, 22); + this.clientsToolStripMenuItem.Text = "Клиенты"; + this.clientsToolStripMenuItem.Click += new System.EventHandler(this.clientsToolStripMenuItem_Click); + // + // implementersToolStripMenuItem + // + this.implementersToolStripMenuItem.Name = "implementersToolStripMenuItem"; + this.implementersToolStripMenuItem.Size = new System.Drawing.Size(149, 22); + this.implementersToolStripMenuItem.Text = "Исполнители"; + this.implementersToolStripMenuItem.Click += new System.EventHandler(this.implementersToolStripMenuItem_Click); + // // reportsToolStripMenuItem // this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -181,22 +175,20 @@ this.listOfOrdersToolStripMenuItem.Text = "Список заказов"; this.listOfOrdersToolStripMenuItem.Click += new System.EventHandler(this.listOfOrdersToolStripMenuItem_Click); // - // clientsToolStripMenuItem + // doWorksToolStripMenuItem // - this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; - this.clientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.clientsToolStripMenuItem.Text = "Клиенты"; - this.clientsToolStripMenuItem.Click += new System.EventHandler(this.clientsToolStripMenuItem_Click); + this.doWorksToolStripMenuItem.Name = "doWorksToolStripMenuItem"; + this.doWorksToolStripMenuItem.Size = new System.Drawing.Size(92, 22); + this.doWorksToolStripMenuItem.Text = "Запуск работ"; + this.doWorksToolStripMenuItem.Click += new System.EventHandler(this.doWorksToolStripMenuItem_Click); // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1071, 401); + this.ClientSize = new System.Drawing.Size(1276, 577); this.Controls.Add(this.buttonRefresh); this.Controls.Add(this.buttonPut); - this.Controls.Add(this.buttonReady); - this.Controls.Add(this.buttonToWork); this.Controls.Add(this.buttonCreate); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip); @@ -217,18 +209,18 @@ private DataGridView dataGridView; private Button buttonCreate; - private Button buttonToWork; private Button buttonPut; private Button buttonRefresh; private MenuStrip menuStrip; private ToolStripMenuItem guidesToolStripMenuItem; private ToolStripMenuItem componentsToolStripMenuItem; private ToolStripMenuItem bouquetsToolStripMenuItem; - private Button buttonReady; private ToolStripMenuItem reportsToolStripMenuItem; private ToolStripMenuItem listOfBouquetsToolStripMenuItem; private ToolStripMenuItem componentsByBouquetsToolStripMenuItem; private ToolStripMenuItem listOfOrdersToolStripMenuItem; private ToolStripMenuItem clientsToolStripMenuItem; + private ToolStripMenuItem implementersToolStripMenuItem; + private ToolStripMenuItem doWorksToolStripMenuItem; } } \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormMain.cs b/FlowerShop/FlowerShop/FormMain.cs index 2add79f..b18c88a 100644 --- a/FlowerShop/FlowerShop/FormMain.cs +++ b/FlowerShop/FlowerShop/FormMain.cs @@ -10,13 +10,15 @@ namespace FlowerShop private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; + private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void MainForm_Load(object sender, EventArgs e) @@ -36,6 +38,7 @@ namespace FlowerShop dataGridView.DataSource = list; dataGridView.Columns["BouquetId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; } } catch (Exception ex) @@ -194,5 +197,20 @@ namespace FlowerShop form.ShowDialog(); } } + + private void doWorksToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void implementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } } } diff --git a/FlowerShop/FlowerShop/Program.cs b/FlowerShop/FlowerShop/Program.cs index e64366c..cc15ad6 100644 --- a/FlowerShop/FlowerShop/Program.cs +++ b/FlowerShop/FlowerShop/Program.cs @@ -35,12 +35,15 @@ namespace FlowerShop 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(); @@ -56,6 +59,8 @@ namespace FlowerShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ImplementerLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..807e5d5 --- /dev/null +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,143 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace FlowerShopBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + 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; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. FIO:{FIO}.Id:{ Id}", model.ImplementerFIO, 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 List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. FIO:{FIO}.Id:{ Id} ", model?.ImplementerFIO, 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; + } + + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (model.WorkExperience < 0) + { + throw new ArgumentException("Стаж работы не может быть меньше нуля", nameof(model.WorkExperience)); + } + + if (model.Qualification < 0) + { + throw new ArgumentException("Квалификация не должна быть меньше нуля", nameof(model.Qualification)); + } + + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.ImplementerFIO)); + } + + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); + } + + _logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFIO); + + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs index 2d5c903..966baba 100644 --- a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -33,6 +33,28 @@ namespace FlowerShopBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count: {Count}", list.Count); return list; } + + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. Id:{ Id}", 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 bool CreateOrder(OrderBindingModel model) { CheckModel(model); @@ -53,51 +75,76 @@ namespace FlowerShopBusinessLogic.BusinessLogics return true; } + public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); + CheckModel(model, false); + + if (_orderStorage.GetElement(new OrderSearchModel { Id=model.Id })?.Status != OrderStatus.Принят) + { + _logger.LogWarning("Invalid order status"); + return false; + } + + model.Status = OrderStatus.Выполняется; + + if (!model.ImplementerId.HasValue) + { + _logger.LogWarning("There must be implementer to take order in work"); + return false; + } + + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + } + + return true; } public bool FinishOrder(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Готов); - } - public bool DeliveryOrder(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Выдан); - } - public bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus) - { - var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); - if (viewModel == null) + CheckModel(model, false); + + if (_orderStorage.GetElement(new OrderSearchModel { Id = model.Id })?.Status != OrderStatus.Выполняется) { - throw new ArgumentNullException(nameof(model)); - } - if (viewModel.Status + 1 != newStatus) - { - _logger.LogWarning("Change status operation failed"); + _logger.LogWarning("Invalid order status"); return false; } - model.Status = newStatus; - model.BouquetId = viewModel.BouquetId; - model.Count = viewModel.Count; - model.Sum = viewModel.Sum; - model.DateCreate = viewModel.DateCreate; - if (model.Status == OrderStatus.Готов) - { - model.DateImplement = DateTime.Now; - } - else - { - model.DateImplement = viewModel.DateImplement; - } - CheckModel(model, false); + + model.Status = OrderStatus.Готов; + model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) { - _logger.LogWarning("Change status operation failed"); - return false; + _logger.LogWarning("Update operation failed"); } + return true; } + + public bool DeliveryOrder(OrderBindingModel model) + { + CheckModel(model, false); + + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + + if (order?.Status != OrderStatus.Готов) + { + _logger.LogWarning("Invalid order status"); + return false; + } + + model.Status = OrderStatus.Выдан; + model.DateImplement = order.DateImplement; + + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + } + + return true; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) @@ -110,22 +157,18 @@ namespace FlowerShopBusinessLogic.BusinessLogics return; } - if (model.BouquetId < 0) - { - throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.BouquetId)); - } - - if (model.Count <= 0) - { - throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); - } - if (model.Sum <= 0) { - throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + throw new ArgumentNullException("Стоимость должна быть больше 0", nameof(model.Sum)); } - _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. BouquetId: { BouquetId}", model.Id, model.Sum, model.BouquetId); + _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. BouquetId: {BouquetId}", model.Id, model.Sum, model.BouquetId); + + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element != null && element.Id == model.Id) + { + throw new InvalidOperationException("Заказ с таким идентификатором уже есть"); + } } } } diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/WorkModeling.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..b611876 --- /dev/null +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,137 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace FlowerShopBusinessLogic.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 { Statuses = new() { OrderStatus.Принят, OrderStatus.Выполняется } }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + + await RunOrderInWork(implementer, orders); + + await Task.Run(async () => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + + var notOccupied = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + + if (notOccupied) + { + await Task.Delay(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + + _logger.LogDebug("DoWork. Worker {Id} finish order { Order}", implementer.Id, order.Id); + + _orderLogic.FinishOrder(new OrderBindingModel { Id = order.Id, ImplementerId = implementer.Id }); + + await Task.Delay(implementer.Qualification * _rnd.Next(10, 100)); + } + } + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + }); + } + + private async Task RunOrderInWork(ImplementerViewModel implementer, List allOrders) + { + if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0) + { + return; + } + + try + { + var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется)); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + + await Task.Delay(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id, + ImplementerId = implementer.Id, + }); + + await Task.Delay(implementer.Qualification * _rnd.Next(10, 100)); + } + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/FlowerShop/FlowerShopContracts/BindingModels/ImplementerBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..66de7ad --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,17 @@ +using FlowerShopDataModels.Models; + +namespace FlowerShopContracts.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/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs index 541a607..91d2eaf 100644 --- a/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs +++ b/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs @@ -8,6 +8,7 @@ namespace FlowerShopContracts.BindingModels public int Id { get; set; } public int BouquetId { 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/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IImplementerLogic.cs b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..d9b91de --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,19 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.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/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs index 0449bf8..e1c9d08 100644 --- a/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -7,6 +7,7 @@ namespace FlowerShopContracts.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/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IWorkProcess.cs b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..a928f27 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,7 @@ +namespace FlowerShopContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/FlowerShop/FlowerShopContracts/SearchModels/ImplementerSearchModel.cs b/FlowerShop/FlowerShopContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..e5a2807 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,11 @@ +namespace FlowerShopContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/FlowerShop/FlowerShopContracts/SearchModels/OrderSearchModel.cs b/FlowerShop/FlowerShopContracts/SearchModels/OrderSearchModel.cs index b4a01e5..4d8780e 100644 --- a/FlowerShop/FlowerShopContracts/SearchModels/OrderSearchModel.cs +++ b/FlowerShop/FlowerShopContracts/SearchModels/OrderSearchModel.cs @@ -1,9 +1,13 @@ -namespace FlowerShopContracts.SearchModels +using FlowerShopDataModels.Enums; + +namespace FlowerShopContracts.SearchModels { public class OrderSearchModel { public int? Id { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public List? Statuses { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } } diff --git a/FlowerShop/FlowerShopContracts/StoragesContracts/IImplementerStorage.cs b/FlowerShop/FlowerShopContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..10de42c --- /dev/null +++ b/FlowerShop/FlowerShopContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.StoragesContracts +{ + public interface IImplementerStorage + { + List GetFullList(); + + List GetFilteredList(ImplementerSearchModel model); + + ImplementerViewModel? GetElement(ImplementerSearchModel model); + + ImplementerViewModel? Insert(ImplementerBindingModel model); + + ImplementerViewModel? Update(ImplementerBindingModel model); + + ImplementerViewModel? Delete(ImplementerBindingModel model); + } +} diff --git a/FlowerShop/FlowerShopContracts/ViewModels/ImplementerViewModel.cs b/FlowerShop/FlowerShopContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..ef2e876 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,22 @@ +using FlowerShopDataModels.Models; +using System.ComponentModel; + +namespace FlowerShopContracts.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/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs b/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs index 0a39f17..27abdd1 100644 --- a/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs +++ b/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs @@ -14,6 +14,10 @@ namespace FlowerShopContracts.ViewModels [DisplayName("ФИО клиента")] public string ClientFIO { get; set; } = string.Empty; + public int? ImplementerId { get; set; } + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + [DisplayName("Букет")] public string BouquetName { get; set; } = string.Empty; [DisplayName("Количество")] diff --git a/FlowerShop/FlowerShopDataModels/Models/IImplementerModel.cs b/FlowerShop/FlowerShopDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..11a5654 --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/Models/IImplementerModel.cs @@ -0,0 +1,10 @@ +namespace FlowerShopDataModels.Models +{ + public class IImplementerModel + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs b/FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs index de8f0d9..bc8b876 100644 --- a/FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs +++ b/FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs @@ -6,6 +6,7 @@ namespace FlowerShopDataModels.Models { int BouquetId { get; } int ClientId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/FlowerShop/FlowerShopDatabaseImplement/FlowerShopDatabase.cs b/FlowerShop/FlowerShopDatabaseImplement/FlowerShopDatabase.cs index 7f83c65..b5ea191 100644 --- a/FlowerShop/FlowerShopDatabaseImplement/FlowerShopDatabase.cs +++ b/FlowerShop/FlowerShopDatabaseImplement/FlowerShopDatabase.cs @@ -19,5 +19,6 @@ namespace FlowerShopDatabaseImplement public virtual DbSet BouquetComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/FlowerShop/FlowerShopDatabaseImplement/Implements/ImplementerStorage.cs b/FlowerShop/FlowerShopDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..5f0a229 --- /dev/null +++ b/FlowerShop/FlowerShopDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,98 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopDatabaseImplement.Models; + +namespace FlowerShopDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new FlowerShopDatabase(); + + if (model.Id.HasValue) + { + return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + + if (model.ImplementerFIO != null && model.Password != null) + { + return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel; + } + + if (model.ImplementerFIO != null) + { + return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + } + + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.ImplementerFIO != null) + { + using var context = new FlowerShopDatabase(); + return context.Implementers.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)).Select(x => x.GetViewModel).ToList(); + } + + return new(); + } + + public List GetFullList() + { + using var context = new FlowerShopDatabase(); + + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new FlowerShopDatabase(); + + var res = Implementer.Create(model); + if (res != null) + { + context.Implementers.Add(res); + context.SaveChanges(); + } + + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new FlowerShopDatabase(); + + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + + return res?.GetViewModel; + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new FlowerShopDatabase(); + + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + context.Implementers.Remove(res); + context.SaveChanges(); + } + + return res?.GetViewModel; + } + + } +} diff --git a/FlowerShop/FlowerShopDatabaseImplement/Implements/OrderStorage.cs b/FlowerShop/FlowerShopDatabaseImplement/Implements/OrderStorage.cs index 1f64535..becee7b 100644 --- a/FlowerShop/FlowerShopDatabaseImplement/Implements/OrderStorage.cs +++ b/FlowerShop/FlowerShopDatabaseImplement/Implements/OrderStorage.cs @@ -17,12 +17,17 @@ namespace FlowerShopDatabaseImplement.Implements } using var context = new FlowerShopDatabase(); - return context.Orders.Include(x => x.Bouquet).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Orders.Include(x => x.Bouquet) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => (model.Statuses == null || model.Statuses != null && model.Statuses.Contains(x.Status)) && + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId || + model.Id.HasValue && x.Id == model.Id)?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && model.Statuses == null) { return new(); } @@ -31,16 +36,21 @@ namespace FlowerShopDatabaseImplement.Implements if (model.ClientId.HasValue) { - return context.Orders.Include(x => x.Client).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); + return context.Orders.Include(x => x.Client).Include(x => x.Implementer).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); } - return context.Orders.Include(x => x.Bouquet).Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); + if (model.Statuses != null) + { + return context.Orders.Include(x => x.Client).Include(x => x.Implementer).Where(x => model.Statuses.Contains(x.Status)).Select(x => x.GetViewModel).ToList(); + } + + return context.Orders.Include(x => x.Bouquet).Include(x => x.Implementer).Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); } public List GetFullList() { using var context = new FlowerShopDatabase(); - return context.Orders.Include(x => x.Bouquet).Select(x => x.GetViewModel).ToList(); + return context.Orders.Include(x => x.Bouquet).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) @@ -72,14 +82,14 @@ namespace FlowerShopDatabaseImplement.Implements order.Update(model); context.SaveChanges(); - return context.Orders.Include(x => x.Bouquet).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return context.Orders.Include(x => x.Bouquet).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } public OrderViewModel? Delete(OrderBindingModel model) { using var context = new FlowerShopDatabase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Orders.Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id); if (element != null) { context.Orders.Remove(element); diff --git a/FlowerShop/FlowerShopDatabaseImplement/Migrations/20230429141057_ImplementerAdd.Designer.cs b/FlowerShop/FlowerShopDatabaseImplement/Migrations/20230429141057_ImplementerAdd.Designer.cs new file mode 100644 index 0000000..0d016ac --- /dev/null +++ b/FlowerShop/FlowerShopDatabaseImplement/Migrations/20230429141057_ImplementerAdd.Designer.cs @@ -0,0 +1,257 @@ +// +using System; +using FlowerShopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FlowerShopDatabaseImplement.Migrations +{ + [DbContext(typeof(FlowerShopDatabase))] + [Migration("20230429141057_ImplementerAdd")] + partial class ImplementerAdd + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Bouquet", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BouquetName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Bouquets"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.BouquetComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BouquetId") + .HasColumnType("int"); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("BouquetId"); + + b.HasIndex("ComponentId"); + + b.ToTable("BouquetComponents"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.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("FlowerShopDatabaseImplement.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("FlowerShopDatabaseImplement.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("FlowerShopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BouquetId") + .HasColumnType("int"); + + 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("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("BouquetId"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.BouquetComponent", b => + { + b.HasOne("FlowerShopDatabaseImplement.Models.Bouquet", "Bouquet") + .WithMany("Components") + .HasForeignKey("BouquetId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FlowerShopDatabaseImplement.Models.Component", "Component") + .WithMany("BouquetComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Bouquet"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b => + { + b.HasOne("FlowerShopDatabaseImplement.Models.Bouquet", "Bouquet") + .WithMany("Orders") + .HasForeignKey("BouquetId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FlowerShopDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FlowerShopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.Navigation("Bouquet"); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Bouquet", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b => + { + b.Navigation("BouquetComponents"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FlowerShop/FlowerShopDatabaseImplement/Migrations/20230429141057_ImplementerAdd.cs b/FlowerShop/FlowerShopDatabaseImplement/Migrations/20230429141057_ImplementerAdd.cs new file mode 100644 index 0000000..7b3ac88 --- /dev/null +++ b/FlowerShop/FlowerShopDatabaseImplement/Migrations/20230429141057_ImplementerAdd.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FlowerShopDatabaseImplement.Migrations +{ + /// + public partial class ImplementerAdd : 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/FlowerShop/FlowerShopDatabaseImplement/Migrations/FlowerShopDatabaseModelSnapshot.cs b/FlowerShop/FlowerShopDatabaseImplement/Migrations/FlowerShopDatabaseModelSnapshot.cs index 0005745..a7b940b 100644 --- a/FlowerShop/FlowerShopDatabaseImplement/Migrations/FlowerShopDatabaseModelSnapshot.cs +++ b/FlowerShop/FlowerShopDatabaseImplement/Migrations/FlowerShopDatabaseModelSnapshot.cs @@ -17,7 +17,7 @@ namespace FlowerShopDatabaseImplement.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("ProductVersion", "7.0.3") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); @@ -113,6 +113,33 @@ namespace FlowerShopDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("FlowerShopDatabaseImplement.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("FlowerShopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -136,6 +163,9 @@ namespace FlowerShopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("Status") .HasColumnType("int"); @@ -148,6 +178,8 @@ namespace FlowerShopDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.ToTable("Orders"); }); @@ -184,9 +216,15 @@ namespace FlowerShopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("FlowerShopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.Navigation("Bouquet"); b.Navigation("Client"); + + b.Navigation("Implementer"); }); modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Bouquet", b => @@ -205,6 +243,11 @@ namespace FlowerShopDatabaseImplement.Migrations { b.Navigation("BouquetComponents"); }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); #pragma warning restore 612, 618 } } diff --git a/FlowerShop/FlowerShopDatabaseImplement/Models/Implementer.cs b/FlowerShop/FlowerShopDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..8543d47 --- /dev/null +++ b/FlowerShop/FlowerShopDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,62 @@ +using FlowerShopDataModels.Models; +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.ViewModels; +using System.ComponentModel.DataAnnotations.Schema; + +namespace FlowerShopDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + 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; } + + [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, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + Qualification = model.Qualification, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + Qualification = model.Qualification; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + Qualification = Qualification, + WorkExperience = WorkExperience, + }; + } +} diff --git a/FlowerShop/FlowerShopDatabaseImplement/Models/Order.cs b/FlowerShop/FlowerShopDatabaseImplement/Models/Order.cs index 978c92c..1c2e136 100644 --- a/FlowerShop/FlowerShopDatabaseImplement/Models/Order.cs +++ b/FlowerShop/FlowerShopDatabaseImplement/Models/Order.cs @@ -17,6 +17,8 @@ namespace FlowerShopDatabaseImplement.Models [Required] public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } + [Required] public int Count { get; private set; } @@ -33,6 +35,7 @@ namespace FlowerShopDatabaseImplement.Models public virtual Bouquet Bouquet { get; set; } public virtual Client Client { get; set; } + public virtual Implementer? Implementer { get; private set; } public static Order? Create(OrderBindingModel? model) { @@ -45,6 +48,7 @@ namespace FlowerShopDatabaseImplement.Models { BouquetId = model.BouquetId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -63,6 +67,7 @@ namespace FlowerShopDatabaseImplement.Models Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel { get { @@ -71,6 +76,7 @@ namespace FlowerShopDatabaseImplement.Models { BouquetId = BouquetId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, DateCreate = DateCreate, @@ -78,7 +84,8 @@ namespace FlowerShopDatabaseImplement.Models Id = Id, Status = Status, BouquetName = context.Bouquets.FirstOrDefault(x => x.Id == BouquetId)?.BouquetName ?? string.Empty, - ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty + ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, + ImplementerFIO = context.Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty }; } } diff --git a/FlowerShop/FlowerShopFileImplement/DataFileSingleton.cs b/FlowerShop/FlowerShopFileImplement/DataFileSingleton.cs index 032c37b..3688e56 100644 --- a/FlowerShop/FlowerShopFileImplement/DataFileSingleton.cs +++ b/FlowerShop/FlowerShopFileImplement/DataFileSingleton.cs @@ -10,6 +10,7 @@ namespace FlowerShopFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string BouquetFileName = "Bouquet.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Components { get; private set; } @@ -19,6 +20,8 @@ namespace FlowerShopFileImplement public List Clients { get; private set; } + public List Implementers { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) @@ -33,6 +36,7 @@ namespace FlowerShopFileImplement public void SaveBouquets() => SaveData(Bouquets, BouquetFileName, "Bouquets", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Orders, ImplementerFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { @@ -40,6 +44,7 @@ namespace FlowerShopFileImplement Bouquets = LoadData(BouquetFileName, "Bouquet", x => Bouquet.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Impleneter", x => Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/FlowerShop/FlowerShopFileImplement/Implements/ImplementerStorage.cs b/FlowerShop/FlowerShopFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..b9c0549 --- /dev/null +++ b/FlowerShop/FlowerShopFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,103 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton _source; + + public ImplementerStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + 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 List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.ImplementerFIO != null) + { + return _source.Implementers.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public List GetFullList() + { + return _source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + 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/FlowerShop/FlowerShopFileImplement/Implements/OrderStorage.cs b/FlowerShop/FlowerShopFileImplement/Implements/OrderStorage.cs index c1aa144..5a66f47 100644 --- a/FlowerShop/FlowerShopFileImplement/Implements/OrderStorage.cs +++ b/FlowerShop/FlowerShopFileImplement/Implements/OrderStorage.cs @@ -17,6 +17,16 @@ namespace FlowerShopFileImplement.Implements public OrderViewModel? GetElement(OrderSearchModel model) { + if (model.ImplementerId.HasValue && model.Statuses != null) + { + return AttachInfo(source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && model.Statuses.Contains(x.Status))?.GetViewModel); + } + + if (model.ImplementerId.HasValue) + { + return AttachInfo(source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel); + } + if (!model.Id.HasValue) { return null; @@ -27,22 +37,27 @@ namespace FlowerShopFileImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && model.Statuses == null) { return new(); } if (model.ClientId.HasValue) { - return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); + return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => AttachInfo(x.GetViewModel)).ToList(); } - return source.Orders.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); + if (model.Statuses != null) + { + return source.Orders.Where(x => model.Statuses.Contains(x.Status)).Select(x => AttachInfo(x.GetViewModel)).ToList(); + } + + return source.Orders.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo).Select(x => AttachInfo(x.GetViewModel)).ToList(); } public List GetFullList() { - return source.Orders.Select(x => x.GetViewModel).ToList(); + return source.Orders.Select(x => AttachInfo(x.GetViewModel)).ToList(); } public OrderViewModel? Update(OrderBindingModel model) @@ -72,7 +87,7 @@ namespace FlowerShopFileImplement.Implements source.Orders.Add(newOrder); source.SaveOrders(); - return newOrder.GetViewModel; + return AttachInfo(newOrder.GetViewModel); } public OrderViewModel? Delete(OrderBindingModel model) @@ -86,7 +101,7 @@ namespace FlowerShopFileImplement.Implements source.Orders.Remove(order); source.SaveOrders(); - return order.GetViewModel; + return AttachInfo(order.GetViewModel); } private OrderViewModel AttachInfo(OrderViewModel? model) diff --git a/FlowerShop/FlowerShopFileImplement/Models/Implementer.cs b/FlowerShop/FlowerShopFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..706023a --- /dev/null +++ b/FlowerShop/FlowerShopFileImplement/Models/Implementer.cs @@ -0,0 +1,88 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace FlowerShopFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + 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 static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.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, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + Qualification = model.Qualification, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + Qualification = model.Qualification; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + Qualification = Qualification, + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("FIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); + } +} diff --git a/FlowerShop/FlowerShopFileImplement/Models/Order.cs b/FlowerShop/FlowerShopFileImplement/Models/Order.cs index 033c3dd..5d31587 100644 --- a/FlowerShop/FlowerShopFileImplement/Models/Order.cs +++ b/FlowerShop/FlowerShopFileImplement/Models/Order.cs @@ -12,6 +12,8 @@ namespace FlowerShopFileImplement.Models public int ClientId { get; set; } + public int? ImplementerId { get; set; } + public int Count { get; private set; } public double Sum { get; private set; } @@ -35,6 +37,7 @@ namespace FlowerShopFileImplement.Models { BouquetId = model.BouquetId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -56,6 +59,7 @@ namespace FlowerShopFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), BouquetId = Convert.ToInt32(element.Element("BouquetId")!.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), @@ -71,19 +75,17 @@ namespace FlowerShopFileImplement.Models return; } - BouquetId = model.BouquetId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; - Id = model.Id; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { BouquetId = BouquetId, ClientId = ClientId, + ImplementerId = ImplementerId, + ImplementerFIO = DataFileSingleton.GetInstance().Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty, Count = Count, Sum = Sum, DateCreate = DateCreate, @@ -97,6 +99,7 @@ namespace FlowerShopFileImplement.Models new XAttribute("Id", Id), new XElement("BouquetId", BouquetId.ToString()), new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/FlowerShop/FlowerShopListImplement/DataListSingleton.cs b/FlowerShop/FlowerShopListImplement/DataListSingleton.cs index f0b5668..0c54fdb 100644 --- a/FlowerShop/FlowerShopListImplement/DataListSingleton.cs +++ b/FlowerShop/FlowerShopListImplement/DataListSingleton.cs @@ -9,6 +9,7 @@ namespace FlowerShopListImplement public List Orders { get; set; } public List Bouquets { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { @@ -16,6 +17,7 @@ namespace FlowerShopListImplement Orders = new List(); Bouquets = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() diff --git a/FlowerShop/FlowerShopListImplement/Implements/ImplementerStorage.cs b/FlowerShop/FlowerShopListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..92b9052 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,126 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopListImplement.Models; + +namespace FlowerShopListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + 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(); + } + + List list = new(); + + if (model.ImplementerFIO != null) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + list.Add(implementer.GetViewModel); + } + } + } + + return list; + } + + 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; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs b/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs index e31d5fd..68d772d 100644 --- a/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs +++ b/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs @@ -53,6 +53,28 @@ namespace FlowerShopListImplement.Implements } } + if (model.ImplementerId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ImplementerId == model.ImplementerId) + { + result.Add(AttachInfo(order.GetViewModel)); + } + } + } + + if (model.Statuses != null) + { + foreach (var order in _source.Orders) + { + if (model.Statuses.Contains(order.Status)) + { + result.Add(AttachInfo(order.GetViewModel)); + } + } + } + return result; } @@ -69,6 +91,14 @@ namespace FlowerShopListImplement.Implements { return AttachInfo(order.GetViewModel); } + else if (model.ImplementerId.HasValue && model.Statuses != null && order.ImplementerId == model.ImplementerId && model.Statuses.Contains(order.Status)) + { + return AttachInfo(order.GetViewModel); + } + else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId) + { + return AttachInfo(order.GetViewModel); + } } return null; diff --git a/FlowerShop/FlowerShopListImplement/Models/Implementer.cs b/FlowerShop/FlowerShopListImplement/Models/Implementer.cs new file mode 100644 index 0000000..2ab1bd7 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Models/Implementer.cs @@ -0,0 +1,56 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; + +namespace FlowerShopListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + 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 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, + }; + } +} diff --git a/FlowerShop/FlowerShopListImplement/Models/Order.cs b/FlowerShop/FlowerShopListImplement/Models/Order.cs index 2be5f53..2c1e95b 100644 --- a/FlowerShop/FlowerShopListImplement/Models/Order.cs +++ b/FlowerShop/FlowerShopListImplement/Models/Order.cs @@ -10,6 +10,7 @@ namespace FlowerShopListImplement.Models public int Id { get; private set; } public int BouquetId { 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; } @@ -28,6 +29,7 @@ namespace FlowerShopListImplement.Models Id = model.Id, BouquetId = model.BouquetId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -45,6 +47,7 @@ namespace FlowerShopListImplement.Models Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -52,6 +55,8 @@ namespace FlowerShopListImplement.Models Id = Id, BouquetId = BouquetId, ClientId = ClientId, + ImplementerId = ImplementerId, + ImplementerFIO = DataListSingleton.GetInstance().Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty, Count = Count, Sum = Sum, Status = Status, diff --git a/FlowerShop/FlowerShopRestApi/Controllers/ImplementerController.cs b/FlowerShop/FlowerShopRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..fd25ec5 --- /dev/null +++ b/FlowerShop/FlowerShopRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,107 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace FlowerShopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + private readonly IImplementerLogic _implementerLogic; + + public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger) + { + _logger = logger; + _orderLogic = order; + _implementerLogic = logic; + } + + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _implementerLogic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during auth"); + throw; + } + } + + [HttpGet] + public List? GetNewOrders() + { + try + { + return _orderLogic.ReadList(new OrderSearchModel + { + Statuses = new() { OrderStatus.Принят } + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during reciving new orders"); + throw; + } + } + + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during reciving current order"); + + throw; + } + } + + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _orderLogic.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during changing status of order №{Id} into work", model.Id); + throw; + } + } + + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _orderLogic.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during finishing order with №{ Id}", model.Id); + throw; + } + } + + } +}