diff --git a/SoftwareInstallation/SoftwareInstallation/FormImplementer.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormImplementer.Designer.cs
new file mode 100644
index 0000000..3a0469f
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/FormImplementer.Designer.cs
@@ -0,0 +1,173 @@
+namespace SoftwareInstallationView
+{
+ 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()
+ {
+ textBoxFio = new TextBox();
+ textBoxPassword = new TextBox();
+ labelFIO = new Label();
+ labelPassword = new Label();
+ qualificationNumericUpDown = new NumericUpDown();
+ workExpNumericUpDown = new NumericUpDown();
+ labelWorkExperience = new Label();
+ labelQualification = new Label();
+ buttonCancel = new Button();
+ buttonSave = new Button();
+ ((System.ComponentModel.ISupportInitialize)qualificationNumericUpDown).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)workExpNumericUpDown).BeginInit();
+ SuspendLayout();
+ //
+ // textBoxFio
+ //
+ textBoxFio.Location = new Point(128, 16);
+ textBoxFio.Margin = new Padding(3, 4, 3, 4);
+ textBoxFio.Name = "textBoxFio";
+ textBoxFio.Size = new Size(194, 27);
+ textBoxFio.TabIndex = 0;
+ //
+ // textBoxPassword
+ //
+ textBoxPassword.Location = new Point(128, 65);
+ textBoxPassword.Margin = new Padding(3, 4, 3, 4);
+ textBoxPassword.Name = "textBoxPassword";
+ textBoxPassword.Size = new Size(194, 27);
+ textBoxPassword.TabIndex = 1;
+ //
+ // labelFIO
+ //
+ labelFIO.AutoSize = true;
+ labelFIO.Location = new Point(14, 20);
+ labelFIO.Name = "labelFIO";
+ labelFIO.Size = new Size(49, 20);
+ labelFIO.TabIndex = 2;
+ labelFIO.Text = "ФИО: ";
+ //
+ // labelPassword
+ //
+ labelPassword.AutoSize = true;
+ labelPassword.Location = new Point(14, 69);
+ labelPassword.Name = "labelPassword";
+ labelPassword.Size = new Size(69, 20);
+ labelPassword.TabIndex = 3;
+ labelPassword.Text = "Пароль: ";
+ //
+ // qualificationNumericUpDown
+ //
+ qualificationNumericUpDown.Location = new Point(132, 175);
+ qualificationNumericUpDown.Margin = new Padding(3, 4, 3, 4);
+ qualificationNumericUpDown.Name = "qualificationNumericUpDown";
+ qualificationNumericUpDown.Size = new Size(194, 27);
+ qualificationNumericUpDown.TabIndex = 4;
+ //
+ // workExpNumericUpDown
+ //
+ workExpNumericUpDown.Location = new Point(133, 120);
+ workExpNumericUpDown.Margin = new Padding(3, 4, 3, 4);
+ workExpNumericUpDown.Name = "workExpNumericUpDown";
+ workExpNumericUpDown.Size = new Size(194, 27);
+ workExpNumericUpDown.TabIndex = 5;
+ //
+ // labelWorkExperience
+ //
+ labelWorkExperience.AutoSize = true;
+ labelWorkExperience.Location = new Point(14, 123);
+ labelWorkExperience.Name = "labelWorkExperience";
+ labelWorkExperience.Size = new Size(109, 20);
+ labelWorkExperience.TabIndex = 6;
+ labelWorkExperience.Text = "Опыт работы: ";
+ //
+ // labelQualification
+ //
+ labelQualification.AutoSize = true;
+ labelQualification.Location = new Point(14, 177);
+ labelQualification.Name = "labelQualification";
+ labelQualification.Size = new Size(118, 20);
+ labelQualification.TabIndex = 7;
+ labelQualification.Text = "Квалификация: ";
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(211, 225);
+ buttonCancel.Margin = new Padding(3, 4, 3, 4);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(111, 39);
+ buttonCancel.TabIndex = 8;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += ButtonCancel_Click;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(94, 225);
+ buttonSave.Margin = new Padding(3, 4, 3, 4);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(111, 39);
+ buttonSave.TabIndex = 9;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += ButtonSave_Click;
+ //
+ // FormImplementer
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(350, 285);
+ Controls.Add(buttonSave);
+ Controls.Add(buttonCancel);
+ Controls.Add(labelQualification);
+ Controls.Add(labelWorkExperience);
+ Controls.Add(workExpNumericUpDown);
+ Controls.Add(qualificationNumericUpDown);
+ Controls.Add(labelPassword);
+ Controls.Add(labelFIO);
+ Controls.Add(textBoxPassword);
+ Controls.Add(textBoxFio);
+ Margin = new Padding(3, 4, 3, 4);
+ Name = "FormImplementer";
+ Text = "Исполнитель";
+ Load += FormImplementer_Load;
+ ((System.ComponentModel.ISupportInitialize)qualificationNumericUpDown).EndInit();
+ ((System.ComponentModel.ISupportInitialize)workExpNumericUpDown).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private TextBox textBoxFio;
+ private TextBox textBoxPassword;
+ private Label labelFIO;
+ private Label labelPassword;
+ private NumericUpDown qualificationNumericUpDown;
+ private NumericUpDown workExpNumericUpDown;
+ private Label labelWorkExperience;
+ private Label labelQualification;
+ private Button buttonCancel;
+ private Button buttonSave;
+ }
+}
\ No newline at end of file
diff --git a/SoftwareInstallation/SoftwareInstallation/FormImplementer.cs b/SoftwareInstallation/SoftwareInstallation/FormImplementer.cs
new file mode 100644
index 0000000..190e9ac
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/FormImplementer.cs
@@ -0,0 +1,106 @@
+using Microsoft.Extensions.Logging;
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.BusinessLogicContracts;
+using SoftwareInstallationContracts.SearchModels;
+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 SoftwareInstallationView
+{
+ 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 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)qualificationNumericUpDown.Value,
+ WorkExperience = (int)workExpNumericUpDown.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();
+ }
+
+ 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;
+ qualificationNumericUpDown.Value = view.Qualification;
+ workExpNumericUpDown.Value = view.WorkExperience;
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения исполнителя");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallation/FormImplementer.resx b/SoftwareInstallation/SoftwareInstallation/FormImplementer.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/FormImplementer.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/SoftwareInstallation/SoftwareInstallation/FormImplementers.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormImplementers.Designer.cs
new file mode 100644
index 0000000..385c62f
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/FormImplementers.Designer.cs
@@ -0,0 +1,120 @@
+namespace SoftwareInstallationView
+{
+ 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()
+ {
+ dataGridView = new DataGridView();
+ buttonAdd = new Button();
+ buttonChange = new Button();
+ buttonDelete = new Button();
+ buttonUpdate = new Button();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // dataGridView
+ //
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(1, 1);
+ dataGridView.Margin = new Padding(3, 4, 3, 4);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 25;
+ dataGridView.Size = new Size(722, 597);
+ dataGridView.TabIndex = 0;
+ //
+ // buttonAdd
+ //
+ buttonAdd.Location = new Point(730, 16);
+ buttonAdd.Margin = new Padding(3, 4, 3, 4);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(112, 60);
+ buttonAdd.TabIndex = 1;
+ buttonAdd.Text = "Добавить";
+ buttonAdd.UseVisualStyleBackColor = true;
+ buttonAdd.Click += AddButton_Click;
+ //
+ // buttonChange
+ //
+ buttonChange.Location = new Point(730, 84);
+ buttonChange.Margin = new Padding(3, 4, 3, 4);
+ buttonChange.Name = "buttonChange";
+ buttonChange.Size = new Size(112, 60);
+ buttonChange.TabIndex = 2;
+ buttonChange.Text = "Изменить";
+ buttonChange.UseVisualStyleBackColor = true;
+ buttonChange.Click += ChangeButton_Click;
+ //
+ // buttonDelete
+ //
+ buttonDelete.Location = new Point(730, 152);
+ buttonDelete.Margin = new Padding(3, 4, 3, 4);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(112, 60);
+ buttonDelete.TabIndex = 3;
+ buttonDelete.Text = "Удалить";
+ buttonDelete.UseVisualStyleBackColor = true;
+ buttonDelete.Click += DeleteButton_Click;
+ //
+ // buttonUpdate
+ //
+ buttonUpdate.Location = new Point(730, 220);
+ buttonUpdate.Margin = new Padding(3, 4, 3, 4);
+ buttonUpdate.Name = "buttonUpdate";
+ buttonUpdate.Size = new Size(112, 60);
+ buttonUpdate.TabIndex = 4;
+ buttonUpdate.Text = "Обновить";
+ buttonUpdate.UseVisualStyleBackColor = true;
+ buttonUpdate.Click += UpdateButton_Click;
+ //
+ // FormImplementers
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(856, 600);
+ Controls.Add(buttonUpdate);
+ Controls.Add(buttonDelete);
+ Controls.Add(buttonChange);
+ Controls.Add(buttonAdd);
+ Controls.Add(dataGridView);
+ Margin = new Padding(3, 4, 3, 4);
+ Name = "FormImplementers";
+ Text = "Исполнители";
+ Load += FormImplementers_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonAdd;
+ private Button buttonChange;
+ private Button buttonDelete;
+ private Button buttonUpdate;
+ }
+}
\ No newline at end of file
diff --git a/SoftwareInstallation/SoftwareInstallation/FormImplementers.cs b/SoftwareInstallation/SoftwareInstallation/FormImplementers.cs
new file mode 100644
index 0000000..16a3f1e
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/FormImplementers.cs
@@ -0,0 +1,121 @@
+using Microsoft.Extensions.Logging;
+using SoftwareInstallation;
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.BusinessLogicContracts;
+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 SoftwareInstallationView
+{
+ 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 AddButton_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 ChangeButton_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 DeleteButton_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 UpdateButton_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ 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);
+ }
+ }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallation/FormImplementers.resx b/SoftwareInstallation/SoftwareInstallation/FormImplementers.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/FormImplementers.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs
index 2ea8dd7..c9c62c6 100644
--- a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs
+++ b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs
@@ -42,6 +42,8 @@
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRefresh = new Button();
+ запускРаботToolStripMenuItem = new ToolStripMenuItem();
+ исполнителиToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@@ -49,7 +51,7 @@
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(20, 20);
- menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem });
+ menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, запускРаботToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Padding = new Padding(7, 3, 0, 3);
@@ -59,7 +61,7 @@
//
// справочникиToolStripMenuItem
//
- справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem });
+ справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, исполнителиToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(117, 24);
справочникиToolStripMenuItem.Text = "Справочники";
@@ -67,14 +69,14 @@
// компонентыToolStripMenuItem
//
компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
- компонентыToolStripMenuItem.Size = new Size(182, 26);
+ компонентыToolStripMenuItem.Size = new Size(224, 26);
компонентыToolStripMenuItem.Text = "Компоненты";
компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
//
// изделияToolStripMenuItem
//
изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
- изделияToolStripMenuItem.Size = new Size(182, 26);
+ изделияToolStripMenuItem.Size = new Size(224, 26);
изделияToolStripMenuItem.Text = "Изделия";
изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click;
//
@@ -182,6 +184,20 @@
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRef_Click;
//
+ // запускРаботToolStripMenuItem
+ //
+ запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem";
+ запускРаботToolStripMenuItem.Size = new Size(114, 24);
+ запускРаботToolStripMenuItem.Text = "Запуск работ";
+ запускРаботToolStripMenuItem.Click += ЗапускРаботToolStripMenuItem_Click;
+ //
+ // исполнителиToolStripMenuItem
+ //
+ исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem";
+ исполнителиToolStripMenuItem.Size = new Size(224, 26);
+ исполнителиToolStripMenuItem.Text = "Исполнители";
+ исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click;
+ //
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
@@ -222,5 +238,7 @@
private ToolStripMenuItem списокИзделийToolStripMenuItem;
private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem;
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
+ private ToolStripMenuItem исполнителиToolStripMenuItem;
+ private ToolStripMenuItem запускРаботToolStripMenuItem;
}
}
\ No newline at end of file
diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.cs
index 91501eb..d5d4fa5 100644
--- a/SoftwareInstallation/SoftwareInstallation/FormMain.cs
+++ b/SoftwareInstallation/SoftwareInstallation/FormMain.cs
@@ -20,11 +20,13 @@ namespace SoftwareInstallationView
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
- public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic)
+ private readonly IWorkProcess _workProcess;
+ public FormMain(ILogger logger, IWorkProcess workProcess, IOrderLogic orderLogic, IReportLogic reportLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
+ _workProcess = workProcess;
_reportLogic = reportLogic;
LoadData();
}
@@ -45,6 +47,7 @@ namespace SoftwareInstallationView
dataGridView.DataSource = list;
dataGridView.Columns["PackageId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
+ dataGridView.Columns["ImplementerId"].Visible = false;
}
_logger.LogInformation("Загрузка заказов");
@@ -73,6 +76,16 @@ namespace SoftwareInstallationView
form.ShowDialog();
}
}
+ private void ЗапускРаботToolStripMenuItem_Click(object sender, EventArgs
+e)
+ {
+
+ _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic
+ )) as IImplementerLogic)!, _orderLogic);
+ MessageBox.Show("Процесс обработки запущен", "Сообщение",
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+
private void списокИзделийToolStripMenuItem_Click(object sender, EventArgs e)
{
@@ -106,6 +119,23 @@ namespace SoftwareInstallationView
form.ShowDialog();
}
}
+
+ private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
+ MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+
+ private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
+
+ if (service is FormImplementers form)
+ {
+ form.ShowDialog();
+ }
+ }
+
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
diff --git a/SoftwareInstallation/SoftwareInstallation/Program.cs b/SoftwareInstallation/SoftwareInstallation/Program.cs
index 09e1174..0e6fbf8 100644
--- a/SoftwareInstallation/SoftwareInstallation/Program.cs
+++ b/SoftwareInstallation/SoftwareInstallation/Program.cs
@@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
+using SoftwareInstallationBusinessLogic.BusinessLogic;
using SoftwareInstallationBusinessLogic.BusinessLogics;
using SoftwareInstallationBusinessLogic.OfficePackage;
using SoftwareInstallationBusinessLogic.OfficePackage.Implements;
@@ -43,8 +44,11 @@ namespace SoftwareInstallation
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -60,6 +64,8 @@ namespace SoftwareInstallation
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/ImplementerLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/ImplementerLogic.cs
new file mode 100644
index 0000000..a8c5b23
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/ImplementerLogic.cs
@@ -0,0 +1,129 @@
+using Microsoft.Extensions.Logging;
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.BusinessLogicContracts;
+using SoftwareInstallationContracts.SearchModels;
+using SoftwareInstallationContracts.StoragesContracts;
+using SoftwareInstallationContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationBusinessLogic.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 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;
+ }
+
+ public bool Update(ImplementerBindingModel model)
+ {
+ CheckModel(model);
+ if (_implementerStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update 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 (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/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs
index b92300b..dde1f67 100644
--- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs
+++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -1,4 +1,5 @@
-using Microsoft.Extensions.Logging;
+using DocumentFormat.OpenXml.EMMA;
+using Microsoft.Extensions.Logging;
using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.BusinessLogicContracts;
using SoftwareInstallationContracts.SearchModels;
@@ -17,6 +18,7 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
+ static readonly object locker = new object();
public OrderLogic(ILogger logger, IOrderStorage orderStorage)
{
@@ -65,6 +67,9 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
if (model.Status == OrderStatus.Выдан)
model.DateImplement = DateTime.Now;
+ if (viewModel.ImplementerId.HasValue)
+ model.ImplementerId = viewModel.ImplementerId;
+
model.Sum = viewModel.Sum;
model.Count = viewModel.Count;
model.PackageId = viewModel.PackageId;
@@ -82,7 +87,10 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
public bool TakeOrderInWork(OrderBindingModel model)
{
- return StatusUpdate(model, OrderStatus.Выполняется);
+ lock (locker)
+ {
+ return StatusUpdate(model, OrderStatus.Выполняется);
+ }
}
public bool FinishOrder(OrderBindingModel model)
@@ -140,6 +148,28 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
_logger.LogInformation("Order. OrderId:{Id}.Sum:{Sum}. PackageId: {PackageId}", model.Id, model.Sum, model.PackageId);
}
+
+ 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;
+ }
}
}
diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/ReportLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/ReportLogic.cs
index 77c8655..f88dcf6 100644
--- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/ReportLogic.cs
+++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/ReportLogic.cs
@@ -30,6 +30,29 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
}
public List GetPackageComponent()
{
+ /*var components = _componentStorage.GetFullList();
+ var packages = _packageStorage.GetFullList();
+ var list = new List();
+ foreach (var package in packages)
+ {
+ var record = new ReportPackageComponentViewModel
+ {
+ PackageName = package.PackageName,
+ Components = new List>(),
+ TotalCount = 0
+ };
+ foreach (var package in packages)
+ {
+ if (package.PackageComponents.ContainsKey(component.Id))
+ {
+ record.Packages.Add(new Tuple(package.PackageName, package.PackageComponents[component.Id].Item2));
+ record.TotalCount += package.PackageComponents[component.Id].Item2;
+ }
+ }
+ list.Add(record);
+ }
+ return list;*/
+
return _packageStorage.GetFullList().Select(x => new ReportPackageComponentViewModel
{
PackageName = x.PackageName,
diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/WorkModeling.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/WorkModeling.cs
new file mode 100644
index 0000000..b5e99ee
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/WorkModeling.cs
@@ -0,0 +1,141 @@
+using Microsoft.Extensions.Logging;
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.BusinessLogicContracts;
+using SoftwareInstallationContracts.SearchModels;
+using SoftwareInstallationContracts.ViewModels;
+using SoftwareInstallationDataModels.Enums;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationBusinessLogic.BusinessLogic
+{
+ 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.Принят }
+ });
+ 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 Task.Run(() =>
+ {
+ foreach (var order in orders)
+ {
+ try
+ {
+ RunOrderInWork(implementer);
+ _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
+ });
+
+ 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 RunOrderInWork(ImplementerViewModel implementer)
+ {
+ if (_orderLogic == null || implementer == null)
+ {
+ return;
+ }
+ try
+ {
+ var runOrder = await Task.Run(() => _orderLogic.ReadElement(new
+ OrderSearchModel
+ {
+ ImplementerId = implementer.Id,
+ Statuses = new() { 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
+ });
+ // отдыхаем
+ 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;
+ }
+ }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs
new file mode 100644
index 0000000..b2c44fa
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs
@@ -0,0 +1,22 @@
+using SoftwareInstallationDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationContracts.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/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs
index 69b88c1..d222e10 100644
--- a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs
+++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs
@@ -13,6 +13,7 @@ namespace SoftwareInstallationContracts.BindingModels
public int Id { get; set; }
public int PackageId { 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/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IImplementerLogic.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IImplementerLogic.cs
new file mode 100644
index 0000000..de2dbf7
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IImplementerLogic.cs
@@ -0,0 +1,24 @@
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.SearchModels;
+using SoftwareInstallationContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationContracts.BusinessLogicContracts
+{
+ 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/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IOrderLogic.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IOrderLogic.cs
index 3657b81..16db405 100644
--- a/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IOrderLogic.cs
+++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IOrderLogic.cs
@@ -12,6 +12,7 @@ namespace SoftwareInstallationContracts.BusinessLogicContracts
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/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IWorkProcess.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IWorkProcess.cs
new file mode 100644
index 0000000..b1549a5
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IWorkProcess.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationContracts.BusinessLogicContracts
+{
+ public interface IWorkProcess
+ {
+ ///
+ /// Запуск работ
+ ///
+ void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs
new file mode 100644
index 0000000..8a42b72
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationContracts.SearchModels
+{
+ public class ImplementerSearchModel
+ {
+ public int? Id { get; set; }
+
+ public string? ImplementerFIO { get; set; }
+
+ public string? Password { get; set; }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs
index 59474fb..21c63b8 100644
--- a/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs
+++ b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs
@@ -1,4 +1,5 @@
-using System;
+using SoftwareInstallationDataModels.Enums;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -12,5 +13,7 @@ namespace SoftwareInstallationContracts.SearchModels
public int? ClientId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
+ public int? ImplementerId { get; set; }
+ public List? Statuses { get; set; }
}
}
diff --git a/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs
new file mode 100644
index 0000000..b48a403
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs
@@ -0,0 +1,26 @@
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.SearchModels;
+using SoftwareInstallationContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationContracts.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/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs
new file mode 100644
index 0000000..8e2f9e1
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs
@@ -0,0 +1,27 @@
+using SoftwareInstallationDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationContracts.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/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs
index 29880e5..17d1651 100644
--- a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs
+++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs
@@ -14,7 +14,10 @@ namespace SoftwareInstallationContracts.ViewModels
[DisplayName("Номер")]
public int Id { get; set; }
public int PackageId { get; set; }
+ public int? ImplementerId { get; set; }
public int ClientId { get; set; }
+ [DisplayName("ФИО исполнителя")]
+ public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Клиент")]
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Изделие")]
diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/Models/IImplementerModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IImplementerModel.cs
new file mode 100644
index 0000000..475a33d
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IImplementerModel.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationDataModels.Models
+{
+ public interface IImplementerModel : IId
+ {
+ string ImplementerFIO { get; }
+ string Password { get; }
+ int WorkExperience { get; }
+ int Qualification { get; }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/Models/IOrderModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IOrderModel.cs
index deff785..3448bce 100644
--- a/SoftwareInstallation/SoftwareInstallationDataModels/Models/IOrderModel.cs
+++ b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IOrderModel.cs
@@ -11,6 +11,7 @@ namespace SoftwareInstallationDataModels.Models
{
int PackageId { get; }
int ClientId { get; }
+ int? ImplementerId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }
diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implements/ImplementerStorage.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implements/ImplementerStorage.cs
new file mode 100644
index 0000000..2931b54
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implements/ImplementerStorage.cs
@@ -0,0 +1,122 @@
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.SearchModels;
+using SoftwareInstallationContracts.StoragesContracts;
+using SoftwareInstallationContracts.ViewModels;
+using SoftwareInstallationDatabaseImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationDatabaseImplement.Implements
+{
+ public class ImplementerStorage : IImplementerStorage
+ {
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ using var context = new SoftwareInstallationDatabase();
+
+ var res = context.Implementers
+ .FirstOrDefault(x => x.Id == model.Id);
+
+ if (res != null)
+ {
+ context.Implementers.Remove(res);
+ context.SaveChanges();
+ }
+
+ return res?.GetViewModel;
+ }
+
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ using var context = new SoftwareInstallationDatabase();
+
+ 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.Id.HasValue)
+ {
+ var res = GetElement(model);
+
+ return res != null ? new() { res } : new();
+ }
+
+ if (model.ImplementerFIO != null)
+ {
+ using var context = new SoftwareInstallationDatabase();
+
+ return context.Implementers
+ .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ return new();
+ }
+
+ public List GetFullList()
+ {
+ using var context = new SoftwareInstallationDatabase();
+
+ return context.Implementers
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public ImplementerViewModel? Insert(ImplementerBindingModel model)
+ {
+ using var context = new SoftwareInstallationDatabase();
+
+ 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 SoftwareInstallationDatabase();
+
+ var res = context.Implementers
+ .FirstOrDefault(x => x.Id == model.Id);
+
+ if (res != null)
+ {
+ res.Update(model);
+ context.SaveChanges();
+ }
+
+ return res?.GetViewModel;
+ }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs
index 2a58c48..be189ab 100644
--- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs
+++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs
@@ -40,16 +40,21 @@ namespace SoftwareInstallationDatabaseImplement.Implements
using var context = new SoftwareInstallationDatabase();
- return context.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
+ return context.Orders.Include(x => x.Package)
+ .Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List GetFilteredList(OrderSearchModel model)
{
using var context = new SoftwareInstallationDatabase();
- return context.Orders.Include(x => x.Package)
- .Include(x => x.Client).Where(x => ((!model.Id.HasValue || x.Id == model.Id) &&
- (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && (!model.DateTo.HasValue || x.DateCreate <= model.DateTo)
+ return context.Orders.Include(x => x.Package).Include(x => x.Implementer)
+ .Include(x => x.Client).Where(x => (
+ (!model.Id.HasValue || x.Id == model.Id) &&
+ (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && (!model.DateTo.HasValue || x.DateCreate <= model.DateTo)
+ &&
+ (model.Statuses == null || model.Statuses != null && model.Statuses.Contains(x.Status)) &&
+ (!model.ImplementerId.HasValue || x.ImplementerId == model.ImplementerId)
&& (!model.ClientId.HasValue || x.ClientId == model.ClientId)))
.Select(x => x.GetViewModel).ToList();
}
@@ -58,7 +63,7 @@ namespace SoftwareInstallationDatabaseImplement.Implements
{
using var context = new SoftwareInstallationDatabase();
- return context.Orders.Include(x => x.Client).Include(x => x.Package).Select(x => x.GetViewModel).ToList();
+ return context.Orders.Include(x => x.Client).Include(x => x.Package).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20240412193555_AddImplementer.Designer.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20240412193555_AddImplementer.Designer.cs
new file mode 100644
index 0000000..7611955
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20240412193555_AddImplementer.Designer.cs
@@ -0,0 +1,257 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using SoftwareInstallationDatabaseImplement;
+
+#nullable disable
+
+namespace SoftwareInstallationDatabaseImplement.Migrations
+{
+ [DbContext(typeof(SoftwareInstallationDatabase))]
+ [Migration("20240412193555_AddImplementer")]
+ partial class AddImplementer
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
+
+ modelBuilder.Entity("SoftwareInstallationDatabaseImplement.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("SoftwareInstallationDatabaseImplement.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("SoftwareInstallationDatabaseImplement.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("SoftwareInstallationDatabaseImplement.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("PackageId")
+ .HasColumnType("int");
+
+ b.Property("Status")
+ .HasColumnType("int");
+
+ b.Property("Sum")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ClientId");
+
+ b.HasIndex("ImplementerId");
+
+ b.HasIndex("PackageId");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Package", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("PackageName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Price")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.ToTable("Packages");
+ });
+
+ modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.PackageComponent", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ComponentId")
+ .HasColumnType("int");
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("PackageId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ComponentId");
+
+ b.HasIndex("PackageId");
+
+ b.ToTable("PackageComponents");
+ });
+
+ modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Order", b =>
+ {
+ b.HasOne("SoftwareInstallationDatabaseImplement.Models.Client", "Client")
+ .WithMany("Orders")
+ .HasForeignKey("ClientId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("SoftwareInstallationDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Orders")
+ .HasForeignKey("ImplementerId");
+
+ b.HasOne("SoftwareInstallationDatabaseImplement.Models.Package", "Package")
+ .WithMany("Orders")
+ .HasForeignKey("PackageId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Client");
+
+ b.Navigation("Implementer");
+
+ b.Navigation("Package");
+ });
+
+ modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.PackageComponent", b =>
+ {
+ b.HasOne("SoftwareInstallationDatabaseImplement.Models.Component", "Component")
+ .WithMany("PackageComponents")
+ .HasForeignKey("ComponentId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("SoftwareInstallationDatabaseImplement.Models.Package", "Package")
+ .WithMany("Components")
+ .HasForeignKey("PackageId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Component");
+
+ b.Navigation("Package");
+ });
+
+ modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Client", b =>
+ {
+ b.Navigation("Orders");
+ });
+
+ modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Component", b =>
+ {
+ b.Navigation("PackageComponents");
+ });
+
+ modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Orders");
+ });
+
+ modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Package", b =>
+ {
+ b.Navigation("Components");
+
+ b.Navigation("Orders");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20240412193555_AddImplementer.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20240412193555_AddImplementer.cs
new file mode 100644
index 0000000..56ad697
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20240412193555_AddImplementer.cs
@@ -0,0 +1,67 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace SoftwareInstallationDatabaseImplement.Migrations
+{
+ ///
+ public partial class AddImplementer : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddColumn(
+ name: "ImplementerId",
+ table: "Orders",
+ type: "int",
+ nullable: true);
+
+ migrationBuilder.CreateTable(
+ name: "Implementers",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false),
+ Password = table.Column(type: "nvarchar(max)", nullable: false),
+ WorkExperience = table.Column(type: "int", nullable: false),
+ Qualification = table.Column(type: "int", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Implementers", x => x.Id);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Orders_ImplementerId",
+ table: "Orders",
+ column: "ImplementerId");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Orders_Implementers_ImplementerId",
+ table: "Orders",
+ column: "ImplementerId",
+ principalTable: "Implementers",
+ principalColumn: "Id");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Orders_Implementers_ImplementerId",
+ table: "Orders");
+
+ migrationBuilder.DropTable(
+ name: "Implementers");
+
+ migrationBuilder.DropIndex(
+ name: "IX_Orders_ImplementerId",
+ table: "Orders");
+
+ migrationBuilder.DropColumn(
+ name: "ImplementerId",
+ table: "Orders");
+ }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDatabaseModelSnapshot.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDatabaseModelSnapshot.cs
index 3e02934..d719758 100644
--- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDatabaseModelSnapshot.cs
+++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDatabaseModelSnapshot.cs
@@ -67,6 +67,33 @@ namespace SoftwareInstallationDatabaseImplement.Migrations
b.ToTable("Components");
});
+ modelBuilder.Entity("SoftwareInstallationDatabaseImplement.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("SoftwareInstallationDatabaseImplement.Models.Order", b =>
{
b.Property("Id")
@@ -87,6 +114,9 @@ namespace SoftwareInstallationDatabaseImplement.Migrations
b.Property("DateImplement")
.HasColumnType("datetime2");
+ b.Property("ImplementerId")
+ .HasColumnType("int");
+
b.Property("PackageId")
.HasColumnType("int");
@@ -100,6 +130,8 @@ namespace SoftwareInstallationDatabaseImplement.Migrations
b.HasIndex("ClientId");
+ b.HasIndex("ImplementerId");
+
b.HasIndex("PackageId");
b.ToTable("Orders");
@@ -159,6 +191,10 @@ namespace SoftwareInstallationDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
+ b.HasOne("SoftwareInstallationDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Orders")
+ .HasForeignKey("ImplementerId");
+
b.HasOne("SoftwareInstallationDatabaseImplement.Models.Package", "Package")
.WithMany("Orders")
.HasForeignKey("PackageId")
@@ -167,6 +203,8 @@ namespace SoftwareInstallationDatabaseImplement.Migrations
b.Navigation("Client");
+ b.Navigation("Implementer");
+
b.Navigation("Package");
});
@@ -199,6 +237,11 @@ namespace SoftwareInstallationDatabaseImplement.Migrations
b.Navigation("PackageComponents");
});
+ modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Orders");
+ });
+
modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Package", b =>
{
b.Navigation("Components");
diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Implementer.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Implementer.cs
new file mode 100644
index 0000000..50a5124
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Implementer.cs
@@ -0,0 +1,70 @@
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.ViewModels;
+using SoftwareInstallationDataModels.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 SoftwareInstallationDatabaseImplement.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/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Order.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Order.cs
index 966dea8..fa98529 100644
--- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Order.cs
+++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Models/Order.cs
@@ -18,6 +18,7 @@ namespace SoftwareInstallationDatabaseImplement.Models
public int PackageId { get; private set; }
[Required]
public int ClientId { get; private set; }
+ public int? ImplementerId { get; private set; }
[Required]
public int Count { get; private set; }
@@ -35,6 +36,7 @@ namespace SoftwareInstallationDatabaseImplement.Models
public virtual Package Package { get; set; }
public virtual Client Client { get; private set; }
+ public Implementer? Implementer { get; set; }
public static Order? Create(OrderBindingModel? model)
{
@@ -47,6 +49,7 @@ namespace SoftwareInstallationDatabaseImplement.Models
{
Id = model.Id,
PackageId = model.PackageId,
+ ImplementerId = model.ImplementerId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@@ -64,6 +67,7 @@ namespace SoftwareInstallationDatabaseImplement.Models
}
Status = model.Status;
DateImplement = model.DateImplement;
+ ImplementerId = model.ImplementerId;
}
public OrderViewModel GetViewModel => new()
@@ -71,13 +75,15 @@ namespace SoftwareInstallationDatabaseImplement.Models
Id = Id,
PackageId = PackageId,
PackageName = Package?.PackageName,
+ ImplementerId = ImplementerId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
ClientId = ClientId,
- ClientFIO = Client?.ClientFIO
+ ClientFIO = Client?.ClientFIO,
+ ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty
};
}
}
diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs
index 44c2a83..c5ab7f7 100644
--- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs
+++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs
@@ -24,5 +24,6 @@ namespace SoftwareInstallationDatabaseImplement
public virtual DbSet PackageComponents { set; get; }
public virtual DbSet Orders { set; get; }
public virtual DbSet Clients { set; get; }
+ public virtual DbSet Implementers { set; get; }
}
}
diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs
index 70a0c44..e87f3aa 100644
--- a/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs
+++ b/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs
@@ -14,12 +14,14 @@ namespace SoftwareInstallationFileImplement
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string PackageFileName = "Package.xml";
- private readonly string ClientFileName = "Client.xml";
- public List Components { get; private set; }
+ private readonly string ClientFileName = "Client.xml";
+ private readonly string ImplementerFileName = "Implementer.xml";
+ public List Components { get; private set; }
public List Orders { get; private set; }
public List Packages { get; private set; }
- public List Clients { get; private set; }
- public static DataFileSingleton GetInstance()
+ public List Implementers { get; private set; }
+ public List Clients { get; private set; }
+ public static DataFileSingleton GetInstance()
{
if (instance == null)
{
@@ -30,19 +32,23 @@ namespace SoftwareInstallationFileImplement
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SavePackages() => SaveData(Packages, PackageFileName, "Packages", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
- public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
- private DataFileSingleton()
+ public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
+ public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
+ private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Packages = LoadData(PackageFileName, "Package", x => Package.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
- Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
- }
+ Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
+ Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
+
+ }
private static List? LoadData(string filename, string xmlNodeName, Func selectFunction)
{
if (File.Exists(filename))
{
- return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
+ return
+ XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
}
return new List();
}
diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/ImplementerStorage.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/ImplementerStorage.cs
new file mode 100644
index 0000000..b3fd03e
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/ImplementerStorage.cs
@@ -0,0 +1,82 @@
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.SearchModels;
+using SoftwareInstallationContracts.StoragesContracts;
+using SoftwareInstallationContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationFileImplement.Implements
+{
+ public class ImplementerStorage : IImplementerStorage
+ {
+ private readonly DataFileSingleton source;
+ public ImplementerStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ return source.Implementers
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public List GetFilteredList(ImplementerSearchModel
+ model)
+ {
+ if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password))
+ {
+ return new();
+ }
+ return source.Implementers
+ .Where(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO.Contains(model.ImplementerFIO)) &&
+ (string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password)))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ return source.Implementers
+ .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO == model.ImplementerFIO) &&
+ (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password))
+ ?.GetViewModel;
+ }
+ public ImplementerViewModel? Insert(ImplementerBindingModel model)
+ {
+ model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x =>
+ x.Id) + 1 : 1;
+ var newImplementer = Implementer.Create(model);
+ if (newImplementer == null)
+ {
+ return null;
+ }
+ source.Implementers.Add(newImplementer);
+ source.SaveImplementers();
+ return newImplementer.GetViewModel;
+ }
+ public ImplementerViewModel? Update(ImplementerBindingModel model)
+ {
+ var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id);
+ if (implementer == null)
+ {
+ return null;
+ }
+ implementer.Update(model);
+ source.SaveImplementers();
+ return implementer.GetViewModel;
+ }
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ var element = source.Implementers.FirstOrDefault(rec => rec.Id == model.Id);
+ if (element != null)
+ {
+ source.Implementers.Remove(element);
+ source.SaveImplementers();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/OrderStorage.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/OrderStorage.cs
index 9accc80..00a3feb 100644
--- a/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/OrderStorage.cs
+++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/OrderStorage.cs
@@ -6,7 +6,6 @@ using SoftwareInstallationFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@@ -38,6 +37,21 @@ namespace SoftwareInstallationFileImplement.Implements
public OrderViewModel? GetElement(OrderSearchModel model)
{
+ if (model.ImplementerId.HasValue && model.Statuses != null)
+ {
+ return source.Orders
+ .FirstOrDefault(x => x.ImplementerId == model.ImplementerId &&
+ model.Statuses.Contains(x.Status))
+ ?.GetViewModel;
+ }
+
+ if (model.ImplementerId.HasValue)
+ {
+ return source.Orders
+ .FirstOrDefault(x => x.ImplementerId == model.ImplementerId)
+ ?.GetViewModel;
+ }
+
if (!model.Id.HasValue)
{
return null;
@@ -48,21 +62,17 @@ namespace SoftwareInstallationFileImplement.Implements
public List GetFilteredList(OrderSearchModel model)
{
- return source.Orders.Where(x => (
- (!model.Id.HasValue || x.Id == model.Id) &&
- (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) &&
- (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) &&
- (!model.ClientId.HasValue || x.ClientId == model.ClientId)
- )
- )
- .Select(x => GetPackageName(x.GetViewModel))
- .Select(GetClientName)
- .ToList();
+ if (!model.Id.HasValue)
+ {
+ return new();
+ }
+
+ return source.Orders.Where(x => x.Id == model.Id).Select(x => GetPackageName(x.GetViewModel)).ToList();
}
public List GetFullList()
{
- return source.Orders.Select(x => GetPackageName(x.GetViewModel)).Select(GetClientName).ToList();
+ return source.Orders.Select(x => GetPackageName(x.GetViewModel)).ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
@@ -98,18 +108,9 @@ namespace SoftwareInstallationFileImplement.Implements
private OrderViewModel GetPackageName(OrderViewModel viewModel)
{
var package = source.Packages.FirstOrDefault(x => x.Id == viewModel.PackageId);
- if (package != null) {
- viewModel.PackageName = package.PackageName;
- }
- return viewModel;
- }
-
- private OrderViewModel GetClientName(OrderViewModel viewModel)
- {
- var client = source.Clients.FirstOrDefault(x => x.Id == viewModel.ClientId);
- if (client != null)
+ if (package != null)
{
- viewModel.ClientFIO = client.ClientFIO;
+ viewModel.PackageName = package.PackageName;
}
return viewModel;
}
diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Implementer.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Implementer.cs
new file mode 100644
index 0000000..c6b2d3e
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Implementer.cs
@@ -0,0 +1,78 @@
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.ViewModels;
+using SoftwareInstallationDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace SoftwareInstallationFileImplement.Models
+{
+ public class Implementer : IImplementerModel
+ {
+ public int Id { get; private set; }
+ public string ImplementerFIO { get; private set; } = string.Empty;
+ public string Password { get; set; } = string.Empty;
+ public int Qualification { get; set; } = 0;
+ public int WorkExperience { get; set; } = 0;
+ public static Implementer? Create(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Implementer()
+ {
+ Id = model.Id,
+ ImplementerFIO = model.ImplementerFIO,
+ Password = model.Password,
+ WorkExperience = model.WorkExperience,
+ Qualification = model.Qualification
+ };
+ }
+ public void Update(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ImplementerFIO = model.ImplementerFIO;
+ Password = model.Password;
+ WorkExperience = model.WorkExperience;
+ Qualification = model.Qualification;
+ }
+ public ImplementerViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ImplementerFIO = ImplementerFIO,
+ Password = Password,
+ WorkExperience = WorkExperience,
+ Qualification = Qualification
+ };
+ public static Implementer? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new Implementer()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ ImplementerFIO = element.Element("ImplementerFIO")!.Value,
+ Password = element.Element("Password")!.Value,
+ Qualification = Convert.ToInt32(element.Element("Qualification")!.Value),
+ WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value)
+ };
+ }
+
+ public XElement GetXElement => new("Implementer",
+ new XAttribute("Id", Id),
+ new XElement("ImplementerFIO", ImplementerFIO),
+ new XElement("Password", Password),
+ new XElement("Qualification", Qualification.ToString()),
+ new XElement("WorkExperience", WorkExperience.ToString())
+ );
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Order.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Order.cs
index 3dc73c6..433fa55 100644
--- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Order.cs
+++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Order.cs
@@ -15,6 +15,7 @@ namespace SoftwareInstallationFileImplement.Models
{
public int ClientId { get; private set; }
public int PackageId { 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.Неизвестен;
@@ -35,6 +36,7 @@ namespace SoftwareInstallationFileImplement.Models
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
+ ImplementerId = model.ImplementerId,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
@@ -53,6 +55,7 @@ namespace SoftwareInstallationFileImplement.Models
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
+ ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null)
};
@@ -81,6 +84,7 @@ namespace SoftwareInstallationFileImplement.Models
PackageId = PackageId,
ClientId = ClientId,
Count = Count,
+ ImplementerId = ImplementerId,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
@@ -91,6 +95,7 @@ namespace SoftwareInstallationFileImplement.Models
new XElement("PackageId", PackageId.ToString()),
new XElement("ClientId", ClientId.ToString()),
new XElement("Count", Count.ToString()),
+ new XElement("ImplementerId", ImplementerId.ToString()),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()),
new XElement("DateCreate", DateCreate.ToString()),
diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs b/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs
index fd99be3..18f20e3 100644
--- a/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs
+++ b/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs
@@ -13,14 +13,16 @@ namespace SoftwareInstallationListImplement
public List Components { get; set; }
public List Orders { get; set; }
public List Packages { get; set; }
- public List Clients { get; set; }
- private DataListSingleton()
+ public List Implementers { get; set; }
+ public List Clients { get; set; }
+ private DataListSingleton()
{
Components = new List();
Orders = new List();
Packages = new List();
- Clients = new List();
- }
+ Implementers = new List();
+ Clients = new List();
+ }
public static DataListSingleton GetInstance()
{
if (_instance == null)
diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Implements/ImplementerStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/ImplementerStorage.cs
new file mode 100644
index 0000000..1d93ef5
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/ImplementerStorage.cs
@@ -0,0 +1,131 @@
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.SearchModels;
+using SoftwareInstallationContracts.StoragesContracts;
+using SoftwareInstallationContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationListImplement.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;
+ }
+ }
+
+ return null;
+ /*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/SoftwareInstallation/SoftwareInstallationListImplement/Implements/OrderStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/OrderStorage.cs
index e33e1a9..36d5590 100644
--- a/SoftwareInstallation/SoftwareInstallationListImplement/Implements/OrderStorage.cs
+++ b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/OrderStorage.cs
@@ -54,26 +54,32 @@ namespace SoftwareInstallationListImplement.Implements
public List GetFilteredList(OrderSearchModel model)
{
var result = new List();
+
+ if (!model.Id.HasValue)
+ {
+ return result;
+ }
+
foreach (var order in _source.Orders)
{
- if ((!model.Id.HasValue || order.Id == model.Id) &&
- (!model.DateFrom.HasValue || order.DateCreate >= model.DateFrom) &&
- (!model.DateTo.HasValue || order.DateCreate <= model.DateTo) &&
- (!model.ClientId.HasValue || order.ClientId == model.ClientId)) ;
+ if (model.Id.HasValue && order.Id == model.Id)
{
- result.Add(GetClientName(GetViewModelName(order.GetViewModel)));
+ result.Add(GetViewModelName(order));
}
}
+
return result;
}
public List GetFullList()
{
var result = new List();
+
foreach (var order in _source.Orders)
{
- result.Add(GetClientName(GetViewModelName(order.GetViewModel)));
+ result.Add(GetViewModelName(order));
}
+
return result;
}
@@ -114,30 +120,18 @@ namespace SoftwareInstallationListImplement.Implements
return null;
}
- private OrderViewModel GetViewModelName(OrderViewModel viewModel)
+ private OrderViewModel GetViewModelName(Order model)
{
+ var res = model.GetViewModel;
foreach (var package in _source.Packages)
{
- if (package.Id == viewModel.PackageId)
+ if (package.Id == model.PackageId)
{
- viewModel.PackageName = package.PackageName;
+ res.PackageName = package.PackageName;
break;
}
}
- return viewModel;
- }
-
- private OrderViewModel GetClientName(OrderViewModel viewModel)
- {
- foreach (var client in _source.Clients)
- {
- if (client.Id == viewModel.ClientId)
- {
- viewModel.ClientFIO = client.ClientFIO;
- break;
- }
- }
- return viewModel;
+ return res;
}
}
}
diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Models/Implementer.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Implementer.cs
new file mode 100644
index 0000000..104f7bc
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Implementer.cs
@@ -0,0 +1,61 @@
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.ViewModels;
+using SoftwareInstallationDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationListImplement.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/SoftwareInstallation/SoftwareInstallationListImplement/Models/Order.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Order.cs
index 653fee2..08d5a17 100644
--- a/SoftwareInstallation/SoftwareInstallationListImplement/Models/Order.cs
+++ b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Order.cs
@@ -13,6 +13,7 @@ namespace SoftwareInstallationListImplement.Models
public class Order : IOrderModel
{
public int ClientId { get; private set; }
+ public int? ImplementerId { get; private set; }
public int PackageId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
diff --git a/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ImplementerController.cs b/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ImplementerController.cs
new file mode 100644
index 0000000..2f76594
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ImplementerController.cs
@@ -0,0 +1,104 @@
+using DocumentFormat.OpenXml.Office2010.Excel;
+using Microsoft.AspNetCore.Mvc;
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.BusinessLogicContracts;
+using SoftwareInstallationContracts.SearchModels;
+using SoftwareInstallationContracts.ViewModels;
+using SoftwareInstallationDataModels.Enums;
+
+namespace SoftwareInstallationRestApi.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/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs b/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs
index 1397d45..7c94324 100644
--- a/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs
+++ b/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs
@@ -11,9 +11,11 @@ builder.Logging.AddLog4Net("log4net.config");
builder.Services.AddTransient();
builder.Services.AddTransient();
builder.Services.AddTransient();
+builder.Services.AddTransient();
builder.Services.AddTransient();
builder.Services.AddTransient();
builder.Services.AddTransient();
+builder.Services.AddTransient();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at
https://aka.ms/aspnetcore/swashbuckle
diff --git a/SoftwareInstallation/SoftwareInstallationRestApi/WeatherForecast.cs b/SoftwareInstallation/SoftwareInstallationRestApi/WeatherForecast.cs
new file mode 100644
index 0000000..70ced41
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationRestApi/WeatherForecast.cs
@@ -0,0 +1,13 @@
+namespace SoftwareInstallationRestApi
+{
+ public class WeatherForecast
+ {
+ public DateOnly Date { get; set; }
+
+ public int TemperatureC { get; set; }
+
+ public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
+
+ public string? Summary { get; set; }
+ }
+}