diff --git a/Pizzeria/Pizzeria.sln b/Pizzeria/Pizzeria.sln
index 1f0c3f7..77691e4 100644
--- a/Pizzeria/Pizzeria.sln
+++ b/Pizzeria/Pizzeria.sln
@@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32319.34
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pizzeria", "Pizzeria\Pizzeria.csproj", "{7CFA6919-EC74-4A91-90C7-EBF76859A453}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pizzeria", "Pizzeria\Pizzeria.csproj", "{7CFA6919-EC74-4A91-90C7-EBF76859A453}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaDataModels", "PizzeriaDataModels\PizzeriaDataModels.csproj", "{16414F00-C4CA-48BF-9C63-C9D9D4AC137F}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaContracts", "PizzeriaContracts\PizzeriaContracts.csproj", "{A5812A19-F80D-4839-BC3F-EA81AAF6F05E}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaBusinessLogic", "PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj", "{B55806ED-5FDE-4A9F-B500-1DFBE8E50491}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{138A775B-55CA-4120-918F-6093C0B2B241}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +23,22 @@ Global
{7CFA6919-EC74-4A91-90C7-EBF76859A453}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7CFA6919-EC74-4A91-90C7-EBF76859A453}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7CFA6919-EC74-4A91-90C7-EBF76859A453}.Release|Any CPU.Build.0 = Release|Any CPU
+ {16414F00-C4CA-48BF-9C63-C9D9D4AC137F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {16414F00-C4CA-48BF-9C63-C9D9D4AC137F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {16414F00-C4CA-48BF-9C63-C9D9D4AC137F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {16414F00-C4CA-48BF-9C63-C9D9D4AC137F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A5812A19-F80D-4839-BC3F-EA81AAF6F05E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A5812A19-F80D-4839-BC3F-EA81AAF6F05E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A5812A19-F80D-4839-BC3F-EA81AAF6F05E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A5812A19-F80D-4839-BC3F-EA81AAF6F05E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B55806ED-5FDE-4A9F-B500-1DFBE8E50491}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B55806ED-5FDE-4A9F-B500-1DFBE8E50491}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B55806ED-5FDE-4A9F-B500-1DFBE8E50491}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B55806ED-5FDE-4A9F-B500-1DFBE8E50491}.Release|Any CPU.Build.0 = Release|Any CPU
+ {138A775B-55CA-4120-918F-6093C0B2B241}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {138A775B-55CA-4120-918F-6093C0B2B241}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {138A775B-55CA-4120-918F-6093C0B2B241}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {138A775B-55CA-4120-918F-6093C0B2B241}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Pizzeria/Pizzeria/Form1.Designer.cs b/Pizzeria/Pizzeria/Form1.Designer.cs
deleted file mode 100644
index 2308030..0000000
--- a/Pizzeria/Pizzeria/Form1.Designer.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-namespace Pizzeria
-{
- partial class Form1
- {
- ///
- /// 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.components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Text = "Form1";
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/Form1.cs b/Pizzeria/Pizzeria/Form1.cs
deleted file mode 100644
index 01e0e10..0000000
--- a/Pizzeria/Pizzeria/Form1.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Pizzeria
-{
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- }
-}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/Form1.resx b/Pizzeria/Pizzeria/Form1.resx
deleted file mode 100644
index 1af7de1..0000000
--- a/Pizzeria/Pizzeria/Form1.resx
+++ /dev/null
@@ -1,120 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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/Pizzeria/Pizzeria/FormComponent.Designer.cs b/Pizzeria/Pizzeria/FormComponent.Designer.cs
new file mode 100644
index 0000000..5782b6b
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormComponent.Designer.cs
@@ -0,0 +1,119 @@
+namespace Pizzeria
+{
+ partial class FormComponent
+ {
+ ///
+ /// 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.label1 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.textBoxCost = new System.Windows.Forms.TextBox();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(18, 35);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(80, 20);
+ this.label1.TabIndex = 0;
+ this.label1.Text = "Название:";
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(18, 68);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(48, 20);
+ this.label2.TabIndex = 1;
+ this.label2.Text = "Цена:";
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(113, 28);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(257, 27);
+ this.textBoxName.TabIndex = 2;
+ //
+ // textBoxCost
+ //
+ this.textBoxCost.Location = new System.Drawing.Point(113, 61);
+ this.textBoxCost.Name = "textBoxCost";
+ this.textBoxCost.Size = new System.Drawing.Size(179, 27);
+ this.textBoxCost.TabIndex = 3;
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(162, 106);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(94, 29);
+ this.buttonSave.TabIndex = 4;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(276, 106);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(94, 29);
+ this.buttonCancel.TabIndex = 5;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FormComponent
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(394, 155);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxCost);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.label1);
+ this.Name = "FormComponent";
+ this.Text = "Компонент";
+ this.Load += new System.EventHandler(this.FormComponent_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label label1;
+ private Label label2;
+ private TextBox textBoxName;
+ private TextBox textBoxCost;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormComponent.cs b/Pizzeria/Pizzeria/FormComponent.cs
new file mode 100644
index 0000000..15c82b8
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormComponent.cs
@@ -0,0 +1,87 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+
+namespace Pizzeria
+{
+ public partial class FormComponent : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IComponentLogic _logic;
+ private int? _id;
+ public int Id { set { _id = value; } }
+ public FormComponent(ILogger logger, IComponentLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void FormComponent_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ try
+ {
+ _logger.LogInformation("Получение компонента");
+ var view = _logic.ReadElement(new ComponentSearchModel
+ {
+ Id =
+ _id.Value
+ });
+ if (view != null)
+ {
+ textBoxName.Text = view.ComponentName;
+ textBoxCost.Text = view.Cost.ToString();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения компонента");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxName.Text))
+ {
+ MessageBox.Show("Заполните название", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение компонента");
+ try
+ {
+ var model = new ComponentBindingModel
+ {
+ Id = _id ?? 0,
+ ComponentName = textBoxName.Text,
+ Cost = Convert.ToDouble(textBoxCost.Text)
+ };
+ var operationResult = _id.HasValue ? _logic.Update(model) :
+ _logic.Create(model);
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение",
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения компонента");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/Pizzeria/Pizzeria/FormComponent.resx b/Pizzeria/Pizzeria/FormComponent.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormComponent.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/Pizzeria/Pizzeria/FormComponents.Designer.cs b/Pizzeria/Pizzeria/FormComponents.Designer.cs
new file mode 100644
index 0000000..ed957c1
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormComponents.Designer.cs
@@ -0,0 +1,123 @@
+namespace Pizzeria
+{
+ partial class FormComponents
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.button1 = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
+ this.button4 = new System.Windows.Forms.Button();
+ this.button5 = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(-1, 0);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(591, 484);
+ this.dataGridView.TabIndex = 0;
+ //
+ // button1
+ //
+ this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button1.Location = new System.Drawing.Point(622, 45);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(94, 29);
+ this.button1.TabIndex = 1;
+ this.button1.Text = "Добавить";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // button2
+ //
+ this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button2.Location = new System.Drawing.Point(622, 92);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(94, 29);
+ this.button2.TabIndex = 2;
+ this.button2.Text = "Изменить";
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // button4
+ //
+ this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button4.Location = new System.Drawing.Point(622, 186);
+ this.button4.Name = "button4";
+ this.button4.Size = new System.Drawing.Size(94, 29);
+ this.button4.TabIndex = 4;
+ this.button4.Text = "Обновить";
+ this.button4.UseVisualStyleBackColor = true;
+ this.button4.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // button5
+ //
+ this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button5.Location = new System.Drawing.Point(622, 139);
+ this.button5.Name = "button5";
+ this.button5.Size = new System.Drawing.Size(94, 29);
+ this.button5.TabIndex = 5;
+ this.button5.Text = "Удалить";
+ this.button5.UseVisualStyleBackColor = true;
+ this.button5.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // FormComponents
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(743, 485);
+ this.Controls.Add(this.button5);
+ this.Controls.Add(this.button4);
+ this.Controls.Add(this.button2);
+ this.Controls.Add(this.button1);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormComponents";
+ this.Text = "Компоненты";
+ this.Load += new System.EventHandler(this.FormComponents_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button button1;
+ private Button button2;
+ private Button button4;
+ private Button button5;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormComponents.cs b/Pizzeria/Pizzeria/FormComponents.cs
new file mode 100644
index 0000000..a07acaa
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormComponents.cs
@@ -0,0 +1,103 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+
+
+namespace Pizzeria
+{
+ public partial class FormComponents : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IComponentLogic _logic;
+ public FormComponents(ILogger logger, IComponentLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void FormComponents_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["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ }
+ _logger.LogInformation("Загрузка компонентов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки компонентов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
+ if (service is FormComponent form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ private void ButtonUpd_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
+ if (service is FormComponent form)
+ {
+ form.Id =
+ Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+ private void ButtonDel_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id =
+ Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Удаление компонента");
+ try
+ {
+ if (!_logic.Delete(new ComponentBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления компонента");
+ MessageBox.Show(ex.Message, "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/Pizzeria/Pizzeria/FormComponents.resx b/Pizzeria/Pizzeria/FormComponents.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormComponents.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/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs b/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs
new file mode 100644
index 0000000..a5ec838
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs
@@ -0,0 +1,146 @@
+namespace Pizzeria
+{
+ partial class FormCreateOrder
+ {
+ ///
+ /// 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.comboBoxPizza = new System.Windows.Forms.ComboBox();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label1 = new System.Windows.Forms.Label();
+ this.textBoxSum = new System.Windows.Forms.TextBox();
+ this.label3 = new System.Windows.Forms.Label();
+ this.SuspendLayout();
+ //
+ // comboBoxPizza
+ //
+ this.comboBoxPizza.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxPizza.FormattingEnabled = true;
+ this.comboBoxPizza.Location = new System.Drawing.Point(119, 34);
+ this.comboBoxPizza.Name = "comboBoxPizza";
+ this.comboBoxPizza.Size = new System.Drawing.Size(224, 28);
+ this.comboBoxPizza.TabIndex = 18;
+ this.comboBoxPizza.SelectedIndexChanged += new System.EventHandler(this.ComboBoxPizza_SelectedIndexChanged);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(249, 145);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(94, 29);
+ this.buttonCancel.TabIndex = 17;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(135, 145);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(94, 29);
+ this.buttonSave.TabIndex = 16;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(117, 68);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(225, 27);
+ this.textBoxCount.TabIndex = 15;
+ this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged);
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(22, 75);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(93, 20);
+ this.label2.TabIndex = 14;
+ this.label2.Text = "Количество:";
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(22, 42);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(71, 20);
+ this.label1.TabIndex = 13;
+ this.label1.Text = "Изделие:";
+ //
+ // textBoxSum
+ //
+ this.textBoxSum.Location = new System.Drawing.Point(118, 101);
+ this.textBoxSum.Name = "textBoxSum";
+ this.textBoxSum.ReadOnly = true;
+ this.textBoxSum.Size = new System.Drawing.Size(225, 27);
+ this.textBoxSum.TabIndex = 20;
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(23, 108);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(58, 20);
+ this.label3.TabIndex = 19;
+ this.label3.Text = "Сумма:";
+ //
+ // FormCreateOrder
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(379, 195);
+ this.Controls.Add(this.textBoxSum);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.comboBoxPizza);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.label1);
+ this.Name = "FormCreateOrder";
+ this.Text = "Заказ";
+ this.Load += new System.EventHandler(this.FormCreateOrder_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private ComboBox comboBoxPizza;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private TextBox textBoxCount;
+ private Label label2;
+ private Label label1;
+ private TextBox textBoxSum;
+ private Label label3;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormCreateOrder.cs b/Pizzeria/Pizzeria/FormCreateOrder.cs
new file mode 100644
index 0000000..fd16d95
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormCreateOrder.cs
@@ -0,0 +1,110 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+
+
+namespace Pizzeria
+{
+ public partial class FormCreateOrder : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IPizzaLogic _logicP;
+ private readonly IOrderLogic _logicO;
+ public FormCreateOrder(ILogger logger, IPizzaLogic logicP, IOrderLogic logicO)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicP = logicP;
+ _logicO = logicO;
+ }
+ private void FormCreateOrder_Load(object sender, EventArgs e)
+ {
+ _logger.LogInformation("Загрузка пицц для заказа");
+ List _list = _logicP.ReadList(null);
+ if (_list != null)
+ {
+ comboBoxPizza.DisplayMember = "PizzaName";
+ comboBoxPizza.ValueMember = "Id";
+ comboBoxPizza.DataSource = _list;
+ comboBoxPizza.SelectedItem = null;
+ }
+ }
+ private void CalcSum()
+ {
+ if (comboBoxPizza.SelectedValue != null &&
+ !string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ try
+ {
+ int id = Convert.ToInt32(comboBoxPizza.SelectedValue);
+ var pizza = _logicP.ReadElement(new PizzaSearchModel
+ {
+ Id = id
+ });
+ int count = Convert.ToInt32(textBoxCount.Text);
+ textBoxSum.Text = Math.Round(count * (pizza?.Price ?? 0), 2).ToString();
+ _logger.LogInformation("Расчет суммы заказа");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка расчета суммы заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void TextBoxCount_TextChanged(object sender, EventArgs e)
+ {
+ CalcSum();
+ }
+ private void ComboBoxPizza_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ CalcSum();
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxPizza.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите пиццу", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Создание заказа");
+ try
+ {
+ var operationResult = _logicO.CreateOrder(new OrderBindingModel
+ {
+ PizzaId = Convert.ToInt32(comboBoxPizza.SelectedValue),
+ Count = Convert.ToInt32(textBoxCount.Text),
+ Sum = Convert.ToDouble(textBoxSum.Text)
+ });
+ 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/Pizzeria/Pizzeria/FormCreateOrder.resx b/Pizzeria/Pizzeria/FormCreateOrder.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormCreateOrder.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/Pizzeria/Pizzeria/FormMain.Designer.cs b/Pizzeria/Pizzeria/FormMain.Designer.cs
new file mode 100644
index 0000000..1a753ee
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormMain.Designer.cs
@@ -0,0 +1,194 @@
+namespace Pizzeria
+{
+ partial class FormMain
+ {
+ ///
+ /// 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.components = new System.ComponentModel.Container();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.button5 = new System.Windows.Forms.Button();
+ this.button4 = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
+ this.button1 = new System.Windows.Forms.Button();
+ this.button3 = new System.Windows.Forms.Button();
+ this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
+ this.menuStrip1 = new System.Windows.Forms.MenuStrip();
+ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.menuStrip1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(0, 31);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(935, 408);
+ this.dataGridView.TabIndex = 0;
+ //
+ // button5
+ //
+ this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button5.Location = new System.Drawing.Point(987, 143);
+ this.button5.Name = "button5";
+ this.button5.Size = new System.Drawing.Size(209, 29);
+ this.button5.TabIndex = 9;
+ this.button5.Text = "Заказ готов";
+ this.button5.UseVisualStyleBackColor = true;
+ this.button5.Click += new System.EventHandler(this.ButtonOrderReady_Click);
+ //
+ // button4
+ //
+ this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button4.Location = new System.Drawing.Point(987, 190);
+ this.button4.Name = "button4";
+ this.button4.Size = new System.Drawing.Size(209, 29);
+ this.button4.TabIndex = 8;
+ this.button4.Text = "Заказ выдан";
+ this.button4.UseVisualStyleBackColor = true;
+ this.button4.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
+ //
+ // button2
+ //
+ this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button2.Location = new System.Drawing.Point(987, 96);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(209, 29);
+ this.button2.TabIndex = 7;
+ this.button2.Text = "Отдать на выполнение";
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
+ //
+ // button1
+ //
+ this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button1.Location = new System.Drawing.Point(987, 49);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(209, 29);
+ this.button1.TabIndex = 6;
+ this.button1.Text = "Создать заказ";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
+ //
+ // button3
+ //
+ this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button3.Location = new System.Drawing.Point(987, 236);
+ this.button3.Name = "button3";
+ this.button3.Size = new System.Drawing.Size(209, 29);
+ this.button3.TabIndex = 10;
+ this.button3.Text = "Обновить список";
+ this.button3.UseVisualStyleBackColor = true;
+ this.button3.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // contextMenuStrip
+ //
+ this.contextMenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
+ this.contextMenuStrip.Name = "contextMenuStrip";
+ this.contextMenuStrip.Size = new System.Drawing.Size(61, 4);
+ //
+ // menuStrip1
+ //
+ this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
+ this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.справочникиToolStripMenuItem});
+ this.menuStrip1.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip1.Name = "menuStrip1";
+ this.menuStrip1.Size = new System.Drawing.Size(1233, 28);
+ this.menuStrip1.TabIndex = 11;
+ this.menuStrip1.Text = "menuStrip1";
+ //
+ // справочникиToolStripMenuItem
+ //
+ this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.компонентыToolStripMenuItem,
+ this.изделияToolStripMenuItem});
+ this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
+ this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24);
+ this.справочникиToolStripMenuItem.Text = "Справочники";
+ //
+ // компонентыToolStripMenuItem
+ //
+ this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
+ this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
+ this.компонентыToolStripMenuItem.Text = "Компоненты";
+ this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
+ //
+ // изделияToolStripMenuItem
+ //
+ this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
+ this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
+ this.изделияToolStripMenuItem.Text = "Пиццы";
+ this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ПиццыToolStripMenuItem_Click);
+ //
+ // FormMain
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1233, 439);
+ this.Controls.Add(this.menuStrip1);
+ this.Controls.Add(this.button3);
+ this.Controls.Add(this.button5);
+ this.Controls.Add(this.button4);
+ this.Controls.Add(this.button2);
+ this.Controls.Add(this.button1);
+ this.Controls.Add(this.dataGridView);
+ this.MainMenuStrip = this.menuStrip1;
+ this.Name = "FormMain";
+ this.Text = "Абстрактный магазин";
+ this.Load += new System.EventHandler(this.FormMain_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.menuStrip1.ResumeLayout(false);
+ this.menuStrip1.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button button5;
+ private Button button4;
+ private Button button2;
+ private Button button1;
+ private Button button3;
+ private ContextMenuStrip contextMenuStrip;
+ private MenuStrip menuStrip1;
+ private ToolStripMenuItem справочникиToolStripMenuItem;
+ private ToolStripMenuItem компонентыToolStripMenuItem;
+ private ToolStripMenuItem изделияToolStripMenuItem;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormMain.cs b/Pizzeria/Pizzeria/FormMain.cs
new file mode 100644
index 0000000..1f13dba
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormMain.cs
@@ -0,0 +1,155 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaDataModels;
+using Microsoft.Extensions.Logging;
+
+namespace Pizzeria
+{
+ public partial class FormMain : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IOrderLogic _orderLogic;
+ public FormMain(ILogger logger, IOrderLogic orderLogic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _orderLogic = orderLogic;
+ }
+ private void FormMain_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ private void LoadData()
+ {
+ try
+ {
+ var list = _orderLogic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["PizzaId"].Visible = false;
+ dataGridView.Columns["PizzaName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ }
+ _logger.LogInformation(" ");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, " ");
+ MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
+ if (service is FormComponents form)
+ {
+ form.ShowDialog();
+ }
+ }
+ private void ToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormPizzas));
+ if (service is FormPizzas form)
+ {
+ form.ShowDialog();
+ }
+ }
+ private void ButtonCreateOrder_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
+ if (service is FormCreateOrder form)
+ {
+ form.ShowDialog();
+ LoadData();
+ }
+ }
+
+ private OrderBindingModel getBindingModel()
+ {
+ return new OrderBindingModel
+ {
+ Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value.ToString()),
+ Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value.ToString()),
+ Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
+ Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
+ PizzaId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["PizzaId"].Value.ToString()),
+ DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
+ };
+ }
+ private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation(" {id}. ' '", id);
+ try
+ {
+ var operationResult = _orderLogic.TakeOrderInWork(getBindingModel());
+ if (!operationResult)
+ {
+ throw new Exception(" . .");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, " ");
+ MessageBox.Show(ex.Message, "", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void ButtonOrderReady_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ int id =
+ Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation(" {id}. ''", id);
+ try
+ {
+ var operationResult = _orderLogic.FinishOrder(getBindingModel());
+ if (!operationResult)
+ {
+ throw new Exception(" . .");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, " ");
+ MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void ButtonIssuedOrder_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation(" {id}. ''", id);
+ try
+ {
+ var operationResult = _orderLogic.DeliveryOrder(getBindingModel());
+ if (!operationResult)
+ {
+ throw new Exception(" . .");
+ }
+ _logger.LogInformation(" {id} ", id);
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, " ");
+ MessageBox.Show(ex.Message, "", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormMain.resx b/Pizzeria/Pizzeria/FormMain.resx
new file mode 100644
index 0000000..c8fd0f0
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormMain.resx
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
+ 17, 17
+
+
+ 195, 17
+
+
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormPizza.Designer.cs b/Pizzeria/Pizzeria/FormPizza.Designer.cs
new file mode 100644
index 0000000..37d7958
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizza.Designer.cs
@@ -0,0 +1,254 @@
+namespace Pizzeria
+{
+ partial class FormPizza
+ {
+ ///
+ /// 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()
+ {
+ System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
+ this.label1 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.textBoxPrice = new System.Windows.Forms.TextBox();
+ this.groupBox = new System.Windows.Forms.GroupBox();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.button5 = new System.Windows.Forms.Button();
+ this.button1 = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
+ this.button4 = new System.Windows.Forms.Button();
+ this.button3 = new System.Windows.Forms.Button();
+ this.button6 = new System.Windows.Forms.Button();
+ this.groupBox.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(20, 19);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(80, 20);
+ this.label1.TabIndex = 0;
+ this.label1.Text = "Название:";
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(20, 56);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(86, 20);
+ this.label2.TabIndex = 1;
+ this.label2.Text = "Стоимость:";
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(106, 12);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(272, 27);
+ this.textBoxName.TabIndex = 2;
+ //
+ // textBoxPrice
+ //
+ this.textBoxPrice.Location = new System.Drawing.Point(106, 49);
+ this.textBoxPrice.Name = "textBoxPrice";
+ this.textBoxPrice.ReadOnly = true;
+ this.textBoxPrice.Size = new System.Drawing.Size(192, 27);
+ this.textBoxPrice.TabIndex = 3;
+ //
+ // groupBox
+ //
+ this.groupBox.Controls.Add(this.dataGridView);
+ this.groupBox.Controls.Add(this.button5);
+ this.groupBox.Controls.Add(this.button1);
+ this.groupBox.Controls.Add(this.button2);
+ this.groupBox.Controls.Add(this.button4);
+ this.groupBox.Location = new System.Drawing.Point(20, 92);
+ this.groupBox.Name = "groupBox";
+ this.groupBox.Size = new System.Drawing.Size(698, 369);
+ this.groupBox.TabIndex = 4;
+ this.groupBox.TabStop = false;
+ this.groupBox.Text = "Компоненты";
+ //
+ // dataGridView
+ //
+ this.dataGridView.AllowUserToAddRows = false;
+ this.dataGridView.AllowUserToDeleteRows = false;
+ this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
+ dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
+ dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
+ dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+ dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
+ dataGridViewCellStyle1.NullValue = "Test";
+ dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
+ dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
+ dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+ this.dataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.ID,
+ this.Component,
+ this.Count});
+ this.dataGridView.Location = new System.Drawing.Point(6, 37);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.ReadOnly = true;
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(473, 298);
+ this.dataGridView.TabIndex = 11;
+ //
+ // ID
+ //
+ this.ID.HeaderText = "Ид";
+ this.ID.MinimumWidth = 6;
+ this.ID.Name = "ID";
+ this.ID.ReadOnly = true;
+ this.ID.Visible = false;
+ this.ID.Width = 125;
+ //
+ // Component
+ //
+ this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.Component.HeaderText = "Компонент";
+ this.Component.MinimumWidth = 6;
+ this.Component.Name = "Component";
+ this.Component.ReadOnly = true;
+ //
+ // Count
+ //
+ this.Count.HeaderText = "Количество";
+ this.Count.MinimumWidth = 6;
+ this.Count.Name = "Count";
+ this.Count.ReadOnly = true;
+ this.Count.Width = 125;
+ //
+ // button5
+ //
+ this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button5.Location = new System.Drawing.Point(569, 146);
+ this.button5.Name = "button5";
+ this.button5.Size = new System.Drawing.Size(94, 29);
+ this.button5.TabIndex = 10;
+ this.button5.Text = "Удалить";
+ this.button5.UseVisualStyleBackColor = true;
+ this.button5.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // button1
+ //
+ this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button1.Location = new System.Drawing.Point(569, 52);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(94, 29);
+ this.button1.TabIndex = 7;
+ this.button1.Text = "Добавить";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // button2
+ //
+ this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button2.Location = new System.Drawing.Point(569, 99);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(94, 29);
+ this.button2.TabIndex = 8;
+ this.button2.Text = "Изменить";
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // button4
+ //
+ this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button4.Location = new System.Drawing.Point(569, 193);
+ this.button4.Name = "button4";
+ this.button4.Size = new System.Drawing.Size(94, 29);
+ this.button4.TabIndex = 9;
+ this.button4.Text = "Обновить";
+ this.button4.UseVisualStyleBackColor = true;
+ this.button4.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // button3
+ //
+ this.button3.Location = new System.Drawing.Point(466, 490);
+ this.button3.Name = "button3";
+ this.button3.Size = new System.Drawing.Size(94, 29);
+ this.button3.TabIndex = 5;
+ this.button3.Text = "Сохранить";
+ this.button3.UseVisualStyleBackColor = true;
+ this.button3.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // button6
+ //
+ this.button6.Location = new System.Drawing.Point(589, 490);
+ this.button6.Name = "button6";
+ this.button6.Size = new System.Drawing.Size(94, 29);
+ this.button6.TabIndex = 6;
+ this.button6.Text = "Отмена";
+ this.button6.UseVisualStyleBackColor = true;
+ this.button6.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FormPizza
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(743, 536);
+ this.Controls.Add(this.button6);
+ this.Controls.Add(this.button3);
+ this.Controls.Add(this.groupBox);
+ this.Controls.Add(this.textBoxPrice);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.label1);
+ this.Name = "FormPizza";
+ this.Text = "Пицца";
+ this.Load += new System.EventHandler(this.FormPizza_Load);
+ this.groupBox.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label label1;
+ private Label label2;
+ private TextBox textBoxName;
+ private TextBox textBoxPrice;
+ private GroupBox groupBox;
+ private DataGridView dataGridView;
+ private Button button5;
+ private Button button1;
+ private Button button2;
+ private Button button4;
+ private Button button3;
+ private Button button6;
+ private DataGridViewTextBoxColumn ID;
+ private DataGridViewTextBoxColumn Component;
+ private DataGridViewTextBoxColumn Count;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormPizza.cs b/Pizzeria/Pizzeria/FormPizza.cs
new file mode 100644
index 0000000..f21b7ca
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizza.cs
@@ -0,0 +1,205 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.SearchModels;
+using PizzeriaDataModels;
+using Microsoft.Extensions.Logging;
+
+
+namespace Pizzeria
+{
+ public partial class FormPizza : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IPizzaLogic _logic;
+ private int? _id;
+ private Dictionary _pizzaComponents;
+ public int Id { set { _id = value; } }
+ public FormPizza(ILogger logger, IPizzaLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ _pizzaComponents = new Dictionary();
+ }
+ private void FormPizza_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ _logger.LogInformation("Загрузка пиццы");
+ try
+ {
+ var view = _logic.ReadElement(new PizzaSearchModel
+ {
+ Id = _id.Value
+ });
+ if (view != null)
+ {
+ textBoxName.Text = view.PizzaName;
+ textBoxPrice.Text = view.Price.ToString();
+ _pizzaComponents = view.PizzaComponents ?? new Dictionary();
+ LoadData();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки пиццы");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка компонент пиццы");
+ try
+ {
+ if (_pizzaComponents != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var pc in _pizzaComponents)
+ {
+ dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
+ }
+ textBoxPrice.Text = CalcPrice().ToString();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки компонент пиццы");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormPizzaComponent));
+ if (service is FormPizzaComponent form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ComponentModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
+ if (_pizzaComponents.ContainsKey(form.Id))
+ {
+ _pizzaComponents[form.Id] = (form.ComponentModel, form.Count);
+ }
+ else
+ {
+ _pizzaComponents.Add(form.Id, (form.ComponentModel, form.Count));
+ }
+ LoadData();
+ }
+ }
+ }
+ private void ButtonUpd_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormPizzaComponent));
+ if (service is FormPizzaComponent form)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
+ form.Id = id;
+ form.Count = _pizzaComponents[id].Item2;
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ComponentModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
+ _pizzaComponents[form.Id] = (form.ComponentModel, form.Count);
+ LoadData();
+ }
+ }
+ }
+ }
+ private void ButtonDel_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ try
+ {
+ var name = dataGridView.SelectedRows[0].Cells[1].Value;
+ var count = dataGridView.SelectedRows[0].Cells[2].Value;
+ _logger.LogInformation("Удаление компонента: {ComponentName} - {Count}", name, count);
+
+ _pizzaComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ LoadData();
+ }
+ }
+ }
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxName.Text))
+ {
+ MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (string.IsNullOrEmpty(textBoxPrice.Text))
+ {
+ MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (_pizzaComponents == null || _pizzaComponents.Count == 0)
+ {
+ MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение пиццы");
+ try
+ {
+ var model = new PizzaBindingModel
+ {
+ Id = _id ?? 0,
+ PizzaName = textBoxName.Text,
+ Price = Convert.ToDouble(textBoxPrice.Text),
+ PizzaComponents = _pizzaComponents
+ };
+ 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 double CalcPrice()
+ {
+ double price = 0;
+ foreach (var elem in _pizzaComponents)
+ {
+ price += (elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2;
+ }
+ return Math.Round(price * 1.1, 2);
+ }
+
+ }
+}
diff --git a/Pizzeria/Pizzeria/FormPizza.resx b/Pizzeria/Pizzeria/FormPizza.resx
new file mode 100644
index 0000000..58a78b5
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizza.resx
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
+ True
+
+
+ True
+
+
+ True
+
+
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs b/Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs
new file mode 100644
index 0000000..9d5ab54
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs
@@ -0,0 +1,120 @@
+namespace Pizzeria
+{
+ partial class FormPizzaComponent
+ {
+ ///
+ /// 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.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label1 = new System.Windows.Forms.Label();
+ this.comboBoxComponent = new System.Windows.Forms.ComboBox();
+ this.SuspendLayout();
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(249, 101);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(94, 29);
+ this.buttonCancel.TabIndex = 11;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(135, 101);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(94, 29);
+ this.buttonSave.TabIndex = 10;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(118, 59);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(225, 27);
+ this.textBoxCount.TabIndex = 9;
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(23, 66);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(93, 20);
+ this.label2.TabIndex = 7;
+ this.label2.Text = "Количество:";
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(23, 33);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(91, 20);
+ this.label1.TabIndex = 6;
+ this.label1.Text = "Компонент:";
+ //
+ // comboBoxComponent
+ //
+ this.comboBoxComponent.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxComponent.FormattingEnabled = true;
+ this.comboBoxComponent.Location = new System.Drawing.Point(120, 25);
+ this.comboBoxComponent.Name = "comboBoxComponent";
+ this.comboBoxComponent.Size = new System.Drawing.Size(224, 28);
+ this.comboBoxComponent.TabIndex = 12;
+ //
+ // FormPizzaComponent
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(370, 153);
+ this.Controls.Add(this.comboBoxComponent);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.label1);
+ this.Name = "FormPizzaComponent";
+ this.Text = "Компонент пиццы";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Button buttonCancel;
+ private Button buttonSave;
+ private TextBox textBoxCount;
+ private Label label2;
+ private Label label1;
+ private ComboBox comboBoxComponent;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormPizzaComponent.cs b/Pizzeria/Pizzeria/FormPizzaComponent.cs
new file mode 100644
index 0000000..2ac2bb7
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizzaComponent.cs
@@ -0,0 +1,78 @@
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.ViewModels;
+using PizzeriaDataModels;
+
+namespace Pizzeria
+{
+ public partial class FormPizzaComponent : Form
+ {
+ private readonly List? _list;
+ public int Id
+ {
+ get
+ {
+ return Convert.ToInt32(comboBoxComponent.SelectedValue);
+ }
+ set
+ {
+ comboBoxComponent.SelectedValue = value;
+ }
+ }
+ public IComponentModel? ComponentModel
+ {
+ get
+ {
+ if (_list == null)
+ {
+ return null;
+ }
+ foreach (var elem in _list)
+ {
+ if (elem.Id == Id)
+ {
+ return elem;
+ }
+ }
+ return null;
+ }
+ }
+ public int Count
+ {
+ get { return Convert.ToInt32(textBoxCount.Text); }
+ set { textBoxCount.Text = value.ToString(); }
+ }
+
+ public FormPizzaComponent(IComponentLogic logic)
+ {
+ InitializeComponent();
+ _list = logic.ReadList(null);
+ if (_list != null)
+ {
+ comboBoxComponent.DisplayMember = "ComponentName";
+ comboBoxComponent.ValueMember = "Id";
+ comboBoxComponent.DataSource = _list;
+ comboBoxComponent.SelectedItem = null;
+ }
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxComponent.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/Pizzeria/Pizzeria/FormPizzaComponent.resx b/Pizzeria/Pizzeria/FormPizzaComponent.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizzaComponent.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/Pizzeria/Pizzeria/FormPizzas.Designer.cs b/Pizzeria/Pizzeria/FormPizzas.Designer.cs
new file mode 100644
index 0000000..e54d9e5
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizzas.Designer.cs
@@ -0,0 +1,123 @@
+namespace Pizzeria
+{
+ partial class FormPizzas
+ {
+ ///
+ /// 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.button5 = new System.Windows.Forms.Button();
+ this.button4 = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
+ this.button1 = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // button5
+ //
+ this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button5.Location = new System.Drawing.Point(614, 139);
+ this.button5.Name = "button5";
+ this.button5.Size = new System.Drawing.Size(94, 29);
+ this.button5.TabIndex = 10;
+ this.button5.Text = "Удалить";
+ this.button5.UseVisualStyleBackColor = true;
+ this.button5.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // button4
+ //
+ this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button4.Location = new System.Drawing.Point(614, 186);
+ this.button4.Name = "button4";
+ this.button4.Size = new System.Drawing.Size(94, 29);
+ this.button4.TabIndex = 9;
+ this.button4.Text = "Обновить";
+ this.button4.UseVisualStyleBackColor = true;
+ this.button4.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // button2
+ //
+ this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button2.Location = new System.Drawing.Point(614, 92);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(94, 29);
+ this.button2.TabIndex = 8;
+ this.button2.Text = "Изменить";
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // button1
+ //
+ this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button1.Location = new System.Drawing.Point(614, 45);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(94, 29);
+ this.button1.TabIndex = 7;
+ this.button1.Text = "Добавить";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(-4, 0);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(586, 447);
+ this.dataGridView.TabIndex = 6;
+ //
+ // FormPizzas
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(720, 447);
+ this.Controls.Add(this.button5);
+ this.Controls.Add(this.button4);
+ this.Controls.Add(this.button2);
+ this.Controls.Add(this.button1);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormPizzas";
+ this.Text = "FormPizzas";
+ this.Load += new System.EventHandler(this.FormPizzas_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private Button button5;
+ private Button button4;
+ private Button button2;
+ private Button button1;
+ private DataGridView dataGridView;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormPizzas.cs b/Pizzeria/Pizzeria/FormPizzas.cs
new file mode 100644
index 0000000..fb84a32
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizzas.cs
@@ -0,0 +1,104 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+
+namespace Pizzeria
+{
+ public partial class FormPizzas : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IPizzaLogic _logic;
+ public FormPizzas(ILogger logger, IPizzaLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void FormPizzas_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["PizzaName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["PizzaComponents"].Visible = false;
+ }
+ _logger.LogInformation("Загрузка компонентов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки компонентов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormPizza));
+ if (service is FormPizza form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ private void ButtonUpd_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormPizza));
+ if (service is FormPizza form)
+ {
+ form.Id =
+ Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+ private void ButtonDel_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id =
+ Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Удаление компонента");
+ try
+ {
+ if (!_logic.Delete(new PizzaBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления компонента");
+ MessageBox.Show(ex.Message, "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/Pizzeria/Pizzeria/FormPizzas.resx b/Pizzeria/Pizzeria/FormPizzas.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizzas.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/Pizzeria/Pizzeria/Pizzeria.csproj b/Pizzeria/Pizzeria/Pizzeria.csproj
index b57c89e..43e30b3 100644
--- a/Pizzeria/Pizzeria/Pizzeria.csproj
+++ b/Pizzeria/Pizzeria/Pizzeria.csproj
@@ -8,4 +8,23 @@
enable
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Always
+
+
+
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/Program.cs b/Pizzeria/Pizzeria/Program.cs
index 25f4942..6905fbb 100644
--- a/Pizzeria/Pizzeria/Program.cs
+++ b/Pizzeria/Pizzeria/Program.cs
@@ -1,17 +1,53 @@
+using PizzeriaBusinessLogic;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.StoragesContracts;
+using PizzeriaListImplement.Implements;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
+
namespace Pizzeria
{
internal static class Program
{
+ private static ServiceProvider? _serviceProvider;
+ public static ServiceProvider? ServiceProvider => _serviceProvider;
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
- // To customize application configuration such as set high DPI settings or default font,
- // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new Form1());
+ IServiceCollection services = new ServiceCollection();
+ ConfigureServices(services);
+
+ _serviceProvider = services.BuildServiceProvider();
+ Application.Run(_serviceProvider.GetService());
+ }
+
+ private static void ConfigureServices(IServiceCollection services)
+ {
+ services.AddLogging(option =>
+ {
+ option.SetMinimumLevel(LogLevel.Information);
+ option.AddNLog("nlog.config");
+ });
+
+ 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();
}
}
}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/Properties/DataSources/PizzeriaContracts.ViewModels.PizzaViewModel.datasource b/Pizzeria/Pizzeria/Properties/DataSources/PizzeriaContracts.ViewModels.PizzaViewModel.datasource
new file mode 100644
index 0000000..f4df9d1
--- /dev/null
+++ b/Pizzeria/Pizzeria/Properties/DataSources/PizzeriaContracts.ViewModels.PizzaViewModel.datasource
@@ -0,0 +1,10 @@
+
+
+
+ PizzeriaContracts.ViewModels.PizzaViewModel, PizzeriaContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
+
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/nlog.config b/Pizzeria/Pizzeria/nlog.config
new file mode 100644
index 0000000..809a1e0
--- /dev/null
+++ b/Pizzeria/Pizzeria/nlog.config
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Pizzeria/PizzeriaBusinessLogic/ComponentLogic.cs b/Pizzeria/PizzeriaBusinessLogic/ComponentLogic.cs
new file mode 100644
index 0000000..c945142
--- /dev/null
+++ b/Pizzeria/PizzeriaBusinessLogic/ComponentLogic.cs
@@ -0,0 +1,109 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.StoragesContracts;
+using PizzeriaContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+
+
+namespace PizzeriaBusinessLogic
+{
+ public class ComponentLogic : IComponentLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IComponentStorage _componentStorage;
+ public ComponentLogic(ILogger logger, IComponentStorage componentStorage)
+ {
+ _logger = logger;
+ _componentStorage = componentStorage;
+ }
+ public List? ReadList(ComponentSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id}", model?.ComponentName, model?.Id);
+ var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+ public ComponentViewModel? ReadElement(ComponentSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id}", model.ComponentName, model.Id);
+ var element = _componentStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+ public bool Create(ComponentBindingModel model)
+ {
+ CheckModel(model);
+ if (_componentStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Update(ComponentBindingModel model)
+ {
+ CheckModel(model);
+ if (_componentStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Delete(ComponentBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_componentStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+ private void CheckModel(ComponentBindingModel model, bool withParams =
+ true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.ComponentName))
+ {
+ throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName));
+ }
+ if (model.Cost <= 0)
+ {
+ throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
+ }
+ _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id);
+ var element = _componentStorage.GetElement(new ComponentSearchModel{
+ ComponentName = model.ComponentName
+ });
+
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Компонент с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/Pizzeria/PizzeriaBusinessLogic/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/OrderLogic.cs
new file mode 100644
index 0000000..f071a3f
--- /dev/null
+++ b/Pizzeria/PizzeriaBusinessLogic/OrderLogic.cs
@@ -0,0 +1,113 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.StoragesContracts;
+using PizzeriaContracts.ViewModels;
+using PizzeriaDataModels;
+using Microsoft.Extensions.Logging;
+
+namespace PizzeriaBusinessLogic
+{
+ public class OrderLogic : IOrderLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IOrderStorage _orderStorage;
+ public OrderLogic(ILogger logger, IOrderStorage orderStorage)
+ {
+ _logger = logger;
+ _orderStorage = orderStorage;
+ }
+ public List? ReadList(OrderSearchModel? model)
+ {
+ _logger.LogInformation("Id:{ Id}", model?.Id);
+ var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ public bool CreateOrder(OrderBindingModel model)
+ {
+ CheckModel(model);
+
+ if (model.Status != OrderStatus.Неизвестен)
+ {
+ _logger.LogWarning("Insert operation failed. Incorrect Order status");
+ return false;
+ }
+
+ model.Status = OrderStatus.Принят;
+
+ if (_orderStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool UpdateStatus(OrderBindingModel model, OrderStatus newStatus)
+ {
+ CheckModel(model);
+
+ if(model.Status + 1 != newStatus)
+ {
+ _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Incorrect Order status.");
+ return false;
+ }
+
+ model.Status = newStatus;
+
+ if(newStatus == OrderStatus.Выдан)
+ {
+ model.DateImplement = DateTime.Now;
+ }
+
+ if (_orderStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool TakeOrderInWork(OrderBindingModel model)
+ {
+ return UpdateStatus(model, OrderStatus.Выполняется);
+ }
+
+ public bool FinishOrder(OrderBindingModel model)
+ {
+ return UpdateStatus(model, OrderStatus.Готов);
+ }
+
+ public bool DeliveryOrder(OrderBindingModel model)
+ {
+ return UpdateStatus(model, OrderStatus.Выдан);
+ }
+
+ private void CheckModel(OrderBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (model.Count <= 0)
+ {
+ throw new ArgumentNullException("Количество пицц должно быть больше 0", nameof(model.Count));
+ }
+ if (model.Sum <= 0)
+ {
+ throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
+ }
+ _logger.LogInformation("Sum:{ Sum}. Id: { Id}", model.Sum, model.Id);
+ }
+
+ }
+}
diff --git a/Pizzeria/PizzeriaBusinessLogic/PizzaLogic.cs b/Pizzeria/PizzeriaBusinessLogic/PizzaLogic.cs
new file mode 100644
index 0000000..728e3b2
--- /dev/null
+++ b/Pizzeria/PizzeriaBusinessLogic/PizzaLogic.cs
@@ -0,0 +1,108 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.StoragesContracts;
+using PizzeriaContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+
+namespace PizzeriaBusinessLogic
+{
+ public class PizzaLogic : IPizzaLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IPizzaStorage _pizzaStorage;
+ public PizzaLogic(ILogger logger, IPizzaStorage pizzaStorage)
+ {
+ _logger = logger;
+ _pizzaStorage = pizzaStorage;
+ }
+ public List? ReadList(PizzaSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. PizzaName:{PizzaName}. Id:{ Id}", model?.PizzaName, model?.Id);
+ var list = model == null ? _pizzaStorage.GetFullList() : _pizzaStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+ public PizzaViewModel? ReadElement(PizzaSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. PizzaName:{PizzaName}. Id:{ Id}", model.PizzaName, model.Id);
+ var element = _pizzaStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+ public bool Create(PizzaBindingModel model)
+ {
+ CheckModel(model);
+ if (_pizzaStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Update(PizzaBindingModel model)
+ {
+ CheckModel(model);
+ if (_pizzaStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Delete(PizzaBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_pizzaStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+ private void CheckModel(PizzaBindingModel model, bool withParams =
+ true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.PizzaName))
+ {
+ throw new ArgumentNullException("Нет названия компонента", nameof(model.PizzaName));
+ }
+ if (model.Price <= 0)
+ {
+ throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Price));
+ }
+ _logger.LogInformation("Component. PizzaName:{PizzaName}. Price:{ Price}. Id: { Id}", model.PizzaName, model.Price, model.Id);
+ var element = _pizzaStorage.GetElement(new PizzaSearchModel{
+ PizzaName = model.PizzaName
+ });
+
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Компонент с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj b/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj
new file mode 100644
index 0000000..9ba5e7e
--- /dev/null
+++ b/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj
@@ -0,0 +1,17 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Pizzeria/PizzeriaContracts/BindingModels/ComponentBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/ComponentBindingModel.cs
new file mode 100644
index 0000000..fec10c0
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/BindingModels/ComponentBindingModel.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using PizzeriaDataModels;
+
+namespace PizzeriaContracts.BindingModels
+{
+ public class ComponentBindingModel : IComponentModel
+ {
+ public int Id { get; set; }
+ public string ComponentName { get; set; } = string.Empty;
+ public double Cost { get; set; }
+ }
+
+}
diff --git a/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs
new file mode 100644
index 0000000..a90b43a
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using PizzeriaDataModels;
+
+namespace PizzeriaContracts.BindingModels
+{
+ public class OrderBindingModel : IOrderModel
+ {
+ public int Id { get; set; }
+ public int PizzaId { get; set; }
+ public int Count { get; set; }
+ public double Sum { get; set; }
+ public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
+ public DateTime DateCreate { get; set; } = DateTime.Now;
+ public DateTime? DateImplement { get; set; }
+ }
+
+}
diff --git a/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs
new file mode 100644
index 0000000..bcf6cf1
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using PizzeriaDataModels;
+
+namespace PizzeriaContracts.BindingModels
+{
+ public class PizzaBindingModel : IPizzaModel
+ {
+ public int Id { get; set; }
+ public string PizzaName { get; set; } = string.Empty;
+ public double Price { get; set; }
+ public Dictionary PizzaComponents
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IComponentLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IComponentLogic.cs
new file mode 100644
index 0000000..f114a89
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IComponentLogic.cs
@@ -0,0 +1,16 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.ViewModels;
+
+namespace PizzeriaContracts.BusinessLogicsContracts
+{
+ public interface IComponentLogic
+ {
+ List? ReadList(ComponentSearchModel? model);
+ ComponentViewModel? ReadElement(ComponentSearchModel model);
+ bool Create(ComponentBindingModel model);
+ bool Update(ComponentBindingModel model);
+ bool Delete(ComponentBindingModel model);
+ }
+
+}
diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs
new file mode 100644
index 0000000..fda864a
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs
@@ -0,0 +1,15 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.ViewModels;
+
+namespace PizzeriaContracts.BusinessLogicsContracts
+{
+ public interface IOrderLogic
+ {
+ List? ReadList(OrderSearchModel? model);
+ bool CreateOrder(OrderBindingModel model);
+ bool TakeOrderInWork(OrderBindingModel model);
+ bool FinishOrder(OrderBindingModel model);
+ bool DeliveryOrder(OrderBindingModel model);
+ }
+}
diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IPizzaLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IPizzaLogic.cs
new file mode 100644
index 0000000..dcf0eb7
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IPizzaLogic.cs
@@ -0,0 +1,16 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.ViewModels;
+
+namespace PizzeriaContracts.BusinessLogicsContracts
+{
+ public interface IPizzaLogic
+ {
+ List? ReadList(PizzaSearchModel? model);
+ PizzaViewModel? ReadElement(PizzaSearchModel model);
+ bool Create(PizzaBindingModel model);
+ bool Update(PizzaBindingModel model);
+ bool Delete(PizzaBindingModel model);
+ }
+
+}
diff --git a/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj b/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj
new file mode 100644
index 0000000..f8743a9
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/Pizzeria/PizzeriaContracts/SearchModels/ComponentSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/ComponentSearchModel.cs
new file mode 100644
index 0000000..f0d07ff
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/SearchModels/ComponentSearchModel.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PizzeriaContracts.SearchModels
+{
+ public class ComponentSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ComponentName { get; set; }
+ }
+
+}
diff --git a/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs
new file mode 100644
index 0000000..3695879
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PizzeriaContracts.SearchModels
+{
+ public class OrderSearchModel
+ {
+ public int? Id { get; set; }
+ }
+}
diff --git a/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs
new file mode 100644
index 0000000..d4719e9
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PizzeriaContracts.SearchModels
+{
+ public class PizzaSearchModel
+ {
+ public int? Id { get; set; }
+ public string? PizzaName { get; set; }
+ }
+}
diff --git a/Pizzeria/PizzeriaContracts/StoragesContracts/IComponentStorage.cs b/Pizzeria/PizzeriaContracts/StoragesContracts/IComponentStorage.cs
new file mode 100644
index 0000000..fd79a39
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/StoragesContracts/IComponentStorage.cs
@@ -0,0 +1,17 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.ViewModels;
+
+namespace PizzeriaContracts.StoragesContracts
+{
+ public interface IComponentStorage
+ {
+ List GetFullList();
+ List GetFilteredList(ComponentSearchModel model);
+ ComponentViewModel? GetElement(ComponentSearchModel model);
+ ComponentViewModel? Insert(ComponentBindingModel model);
+ ComponentViewModel? Update(ComponentBindingModel model);
+ ComponentViewModel? Delete(ComponentBindingModel model);
+ }
+
+}
diff --git a/Pizzeria/PizzeriaContracts/StoragesContracts/IOrderStorage.cs b/Pizzeria/PizzeriaContracts/StoragesContracts/IOrderStorage.cs
new file mode 100644
index 0000000..93b2b2a
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/StoragesContracts/IOrderStorage.cs
@@ -0,0 +1,16 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.ViewModels;
+
+namespace PizzeriaContracts.StoragesContracts
+{
+ public interface IOrderStorage
+ {
+ List GetFullList();
+ List GetFilteredList(OrderSearchModel model);
+ OrderViewModel? GetElement(OrderSearchModel model);
+ OrderViewModel? Insert(OrderBindingModel model);
+ OrderViewModel? Update(OrderBindingModel model);
+ OrderViewModel? Delete(OrderBindingModel model);
+ }
+}
diff --git a/Pizzeria/PizzeriaContracts/StoragesContracts/IPizzaStorage.cs b/Pizzeria/PizzeriaContracts/StoragesContracts/IPizzaStorage.cs
new file mode 100644
index 0000000..b17907c
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/StoragesContracts/IPizzaStorage.cs
@@ -0,0 +1,16 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.ViewModels;
+
+namespace PizzeriaContracts.StoragesContracts
+{
+ public interface IPizzaStorage
+ {
+ List GetFullList();
+ List GetFilteredList(PizzaSearchModel model);
+ PizzaViewModel? GetElement(PizzaSearchModel model);
+ PizzaViewModel? Insert(PizzaBindingModel model);
+ PizzaViewModel? Update(PizzaBindingModel model);
+ PizzaViewModel? Delete(PizzaBindingModel model);
+ }
+}
diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs
new file mode 100644
index 0000000..f371a3b
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel;
+using PizzeriaDataModels;
+
+namespace PizzeriaContracts.ViewModels
+{
+ public class ComponentViewModel : IComponentModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название компонента")]
+ public string ComponentName { get; set; } = string.Empty;
+ [DisplayName("Цена")]
+ public double Cost { get; set; }
+ }
+
+}
diff --git a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs
new file mode 100644
index 0000000..02a6c07
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel;
+using PizzeriaDataModels;
+
+namespace PizzeriaContracts.ViewModels
+{
+ public class OrderViewModel : IOrderModel
+ {
+ [DisplayName("Номер")]
+ public int Id { get; set; }
+ public int PizzaId { get; set; }
+ [DisplayName("Изделие")]
+ public string PizzaName { get; set; } = string.Empty;
+ [DisplayName("Количество")]
+ public int Count { get; set; }
+ [DisplayName("Сумма")]
+ public double Sum { get; set; }
+ [DisplayName("Статус")]
+ public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
+ [DisplayName("Дата создания")]
+ public DateTime DateCreate { get; set; } = DateTime.Now;
+ [DisplayName("Дата выполнения")]
+ public DateTime? DateImplement { get; set; }
+ }
+}
diff --git a/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs
new file mode 100644
index 0000000..c4bc220
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel;
+using PizzeriaDataModels;
+
+
+namespace PizzeriaContracts.ViewModels
+{
+ public class PizzaViewModel : IPizzaModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название изделия")]
+ public string PizzaName { get; set; } = string.Empty;
+ [DisplayName("Цена")]
+ public double Price { get; set; }
+ public Dictionary PizzaComponents
+ {
+ get;
+ set;
+ } = new();
+ }
+
+}
diff --git a/Pizzeria/PizzeriaDataModels/Enums/OrderStatus.cs b/Pizzeria/PizzeriaDataModels/Enums/OrderStatus.cs
new file mode 100644
index 0000000..99b3e51
--- /dev/null
+++ b/Pizzeria/PizzeriaDataModels/Enums/OrderStatus.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PizzeriaDataModels
+{
+ public enum OrderStatus
+ {
+ Неизвестен = -1,
+ Принят = 0,
+ Выполняется = 1,
+ Готов = 2,
+ Выдан = 3
+ }
+}
diff --git a/Pizzeria/PizzeriaDataModels/IId.cs b/Pizzeria/PizzeriaDataModels/IId.cs
new file mode 100644
index 0000000..f7e3b49
--- /dev/null
+++ b/Pizzeria/PizzeriaDataModels/IId.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PizzeriaDataModels
+{
+ public interface IId
+ {
+ int Id { get; }
+ }
+}
diff --git a/Pizzeria/PizzeriaDataModels/Models/IComponentModel.cs b/Pizzeria/PizzeriaDataModels/Models/IComponentModel.cs
new file mode 100644
index 0000000..f228150
--- /dev/null
+++ b/Pizzeria/PizzeriaDataModels/Models/IComponentModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PizzeriaDataModels
+{
+ public interface IComponentModel : IId
+ {
+ string ComponentName { get; }
+ double Cost { get; }
+ }
+}
diff --git a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs
new file mode 100644
index 0000000..56e0e90
--- /dev/null
+++ b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using PizzeriaDataModels;
+
+namespace PizzeriaDataModels
+{
+ public interface IOrderModel : IId
+ {
+ int PizzaId { get; }
+ int Count { get; }
+ double Sum { get; }
+ OrderStatus Status { get; }
+ DateTime DateCreate { get; }
+ DateTime? DateImplement { get; }
+ }
+}
diff --git a/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs b/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs
new file mode 100644
index 0000000..ae8354c
--- /dev/null
+++ b/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PizzeriaDataModels
+{
+ public interface IPizzaModel : IId
+ {
+ string PizzaName { get; }
+ double Price { get; }
+ Dictionary PizzaComponents { get; }
+
+ }
+}
diff --git a/Pizzeria/PizzeriaDataModels/PizzeriaDataModels.csproj b/Pizzeria/PizzeriaDataModels/PizzeriaDataModels.csproj
new file mode 100644
index 0000000..132c02c
--- /dev/null
+++ b/Pizzeria/PizzeriaDataModels/PizzeriaDataModels.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
diff --git a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs
new file mode 100644
index 0000000..24824be
--- /dev/null
+++ b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs
@@ -0,0 +1,27 @@
+using PizzeriaListImplement.Models;
+
+
+namespace PizzeriaListImplement
+{
+ public class DataListSingleton
+ {
+ private static DataListSingleton? _instance;
+ public List Components { get; set; }
+ public List Orders { get; set; }
+ public List Pizzas { get; set; }
+ private DataListSingleton()
+ {
+ Components = new List();
+ Orders = new List();
+ Pizzas = new List();
+ }
+ public static DataListSingleton GetInstance()
+ {
+ if (_instance == null)
+ {
+ _instance = new DataListSingleton();
+ }
+ return _instance;
+ }
+ }
+}
diff --git a/Pizzeria/PizzeriaListImplement/Implements/ComponentStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/ComponentStorage.cs
new file mode 100644
index 0000000..c33e693
--- /dev/null
+++ b/Pizzeria/PizzeriaListImplement/Implements/ComponentStorage.cs
@@ -0,0 +1,103 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.StoragesContracts;
+using PizzeriaContracts.ViewModels;
+using PizzeriaListImplement.Models;
+
+namespace PizzeriaListImplement.Implements
+{
+ public class ComponentStorage : IComponentStorage
+ {
+ private readonly DataListSingleton _source;
+ public ComponentStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var component in _source.Components)
+ {
+ result.Add(component.GetViewModel);
+ }
+ return result;
+ }
+ public List GetFilteredList(ComponentSearchModel
+ model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.ComponentName))
+ {
+ return result;
+ }
+ foreach (var component in _source.Components)
+ {
+ if (component.ComponentName.Contains(model.ComponentName))
+ {
+ result.Add(component.GetViewModel);
+ }
+ }
+ return result;
+ }
+ public ComponentViewModel? GetElement(ComponentSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var component in _source.Components)
+ {
+ if ((!string.IsNullOrEmpty(model.ComponentName) &&
+ component.ComponentName == model.ComponentName) ||
+ (model.Id.HasValue && component.Id == model.Id))
+ {
+ return component.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ComponentViewModel? Insert(ComponentBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var component in _source.Components)
+ {
+ if (model.Id <= component.Id)
+ {
+ model.Id = component.Id + 1;
+ }
+ }
+ var newComponent = Component.Create(model);
+ if (newComponent == null)
+ {
+ return null;
+ }
+ _source.Components.Add(newComponent);
+ return newComponent.GetViewModel;
+ }
+ public ComponentViewModel? Update(ComponentBindingModel model)
+ {
+ foreach (var component in _source.Components)
+ {
+ if (component.Id == model.Id)
+ {
+ component.Update(model);
+ return component.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ComponentViewModel? Delete(ComponentBindingModel model)
+ {
+ for (int i = 0; i < _source.Components.Count; ++i)
+ {
+ if (_source.Components[i].Id == model.Id)
+ {
+ var element = _source.Components[i];
+ _source.Components.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs
new file mode 100644
index 0000000..2e033c4
--- /dev/null
+++ b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs
@@ -0,0 +1,126 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.StoragesContracts;
+using PizzeriaContracts.ViewModels;
+using PizzeriaListImplement.Models;
+
+namespace PizzeriaListImplement.Implements
+{
+ public class OrderStorage : IOrderStorage
+ {
+ private readonly DataListSingleton _source;
+ private IPizzaStorage _pizzaStorage;
+ public OrderStorage(IPizzaStorage pizzaStorage)
+ {
+ _pizzaStorage = pizzaStorage;
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ var result = new List();
+
+ foreach (var order in _source.Orders)
+ {
+ OrderViewModel viewModel = order.GetViewModel;
+ viewModel.PizzaName = _pizzaStorage.GetElement(new PizzaSearchModel { Id = order.PizzaId }).PizzaName;
+ result.Add(viewModel);
+ }
+
+ return result;
+ }
+ 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)
+ {
+ OrderViewModel viewModel = order.GetViewModel;
+ viewModel.PizzaName = _pizzaStorage.GetElement(new PizzaSearchModel { Id = order.PizzaId }).PizzaName;
+ result.Add(viewModel);
+ }
+ }
+
+ return result;
+ }
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+
+ foreach (var order in _source.Orders)
+ {
+ if (model.Id.HasValue && order.Id == model.Id)
+ {
+ OrderViewModel viewModel = order.GetViewModel;
+ viewModel.PizzaName = _pizzaStorage.GetElement(new PizzaSearchModel { Id = order.PizzaId }).PizzaName;
+ return viewModel;
+ }
+ }
+
+ return null;
+ }
+ public OrderViewModel? Insert(OrderBindingModel model)
+ {
+ model.Id = 1;
+
+ foreach (var order in _source.Orders)
+ {
+ if (model.Id <= order.Id)
+ {
+ model.Id = order.Id + 1;
+ }
+ }
+
+ var newOrder = Order.Create(model);
+
+ if (newOrder == null)
+ {
+ return null;
+ }
+
+ _source.Orders.Add(newOrder);
+
+ return newOrder.GetViewModel;
+ }
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ foreach (var order in _source.Orders)
+ {
+ if (order.Id == model.Id)
+ {
+ order.Update(model);
+ OrderViewModel viewModel = order.GetViewModel;
+ viewModel.PizzaName = _pizzaStorage.GetElement(new PizzaSearchModel { Id = order.PizzaId }).PizzaName;
+ return viewModel;
+ }
+ }
+
+ return null;
+ }
+ public OrderViewModel? Delete(OrderBindingModel model)
+ {
+ for (int i = 0; i < _source.Orders.Count; ++i)
+ {
+ if (_source.Orders[i].Id == model.Id)
+ {
+ var element = _source.Orders[i];
+ _source.Orders.RemoveAt(i);
+ OrderViewModel viewModel = element.GetViewModel;
+ viewModel.PizzaName = _pizzaStorage.GetElement(new PizzaSearchModel { Id = element.PizzaId }).PizzaName;
+ return viewModel;
+ }
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs
new file mode 100644
index 0000000..140af23
--- /dev/null
+++ b/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs
@@ -0,0 +1,117 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.StoragesContracts;
+using PizzeriaContracts.ViewModels;
+using PizzeriaListImplement.Models;
+
+namespace PizzeriaListImplement.Implements
+{
+ public class PizzaStorage : IPizzaStorage
+ {
+ private readonly DataListSingleton _source;
+
+ public PizzaStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+
+ foreach (var pizza in _source.Pizzas)
+ {
+ result.Add(pizza.GetViewModel);
+ }
+
+ return result;
+ }
+ public List GetFilteredList(PizzaSearchModel model)
+ {
+ var result = new List();
+
+ if (string.IsNullOrEmpty(model.PizzaName))
+ {
+ return result;
+ }
+
+ foreach (var pizza in _source.Pizzas)
+ {
+ if (pizza.PizzaName.Contains(model.PizzaName))
+ {
+ result.Add(pizza.GetViewModel);
+ }
+ }
+
+ return result;
+ }
+ public PizzaViewModel? GetElement(PizzaSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.PizzaName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+
+ foreach (var pizza in _source.Pizzas)
+ {
+ if ((!string.IsNullOrEmpty(model.PizzaName) && pizza.PizzaName == model.PizzaName) || (model.Id.HasValue && pizza.Id == model.Id))
+ {
+ return pizza.GetViewModel;
+ }
+ }
+
+ return null;
+ }
+ public PizzaViewModel? Insert(PizzaBindingModel model)
+ {
+ model.Id = 1;
+
+ foreach (var pizza in _source.Pizzas)
+ {
+ if (model.Id <= pizza.Id)
+ {
+ model.Id = pizza.Id + 1;
+ }
+ }
+
+ var newPizza = Pizza.Create(model);
+
+ if (newPizza == null)
+ {
+ return null;
+ }
+
+ _source.Pizzas.Add(newPizza);
+
+ return newPizza.GetViewModel;
+ }
+ public PizzaViewModel? Update(PizzaBindingModel model)
+ {
+ foreach (var pizza in _source.Pizzas)
+ {
+ if (pizza.Id == model.Id)
+ {
+ pizza.Update(model);
+ return pizza.GetViewModel;
+ }
+ }
+
+ return null;
+ }
+ public PizzaViewModel? Delete(PizzaBindingModel model)
+ {
+ for (int i = 0; i < _source.Pizzas.Count; ++i)
+ {
+ if (_source.Pizzas[i].Id == model.Id)
+ {
+ var element = _source.Pizzas[i];
+ _source.Pizzas.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+
+ return null;
+ }
+
+ }
+}
diff --git a/Pizzeria/PizzeriaListImplement/Models/Component.cs b/Pizzeria/PizzeriaListImplement/Models/Component.cs
new file mode 100644
index 0000000..346e337
--- /dev/null
+++ b/Pizzeria/PizzeriaListImplement/Models/Component.cs
@@ -0,0 +1,41 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.ViewModels;
+using PizzeriaDataModels;
+
+namespace PizzeriaListImplement.Models
+{
+ public class Component : IComponentModel
+ {
+ public int Id { get; private set; }
+ public string ComponentName { get; private set; } = string.Empty;
+ public double Cost { get; set; }
+ public static Component? Create(ComponentBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Component()
+ {
+ Id = model.Id,
+ ComponentName = model.ComponentName,
+ Cost = model.Cost
+ };
+ }
+ public void Update(ComponentBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ComponentName = model.ComponentName;
+ Cost = model.Cost;
+ }
+ public ComponentViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ComponentName = ComponentName,
+ Cost = Cost
+ };
+ }
+}
diff --git a/Pizzeria/PizzeriaListImplement/Models/Order.cs b/Pizzeria/PizzeriaListImplement/Models/Order.cs
new file mode 100644
index 0000000..595e119
--- /dev/null
+++ b/Pizzeria/PizzeriaListImplement/Models/Order.cs
@@ -0,0 +1,62 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.ViewModels;
+using PizzeriaDataModels;
+
+namespace PizzeriaListImplement.Models
+{
+ public class Order : IOrderModel
+ {
+ public int PizzaId { get; private set; }
+
+ public int Count { get; private set; }
+
+ public double Sum { get; private set; }
+
+ public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
+
+ public DateTime DateCreate { get; private set; } = DateTime.Now;
+
+ public DateTime? DateImplement { get; private set; }
+
+ public int Id { get; private set; }
+
+ public static Order? Create(OrderBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Order()
+ {
+ Id = model.Id,
+ PizzaId = model.PizzaId,
+ Count = model.Count,
+ Sum = model.Sum,
+ Status = model.Status,
+ DateCreate = model.DateCreate,
+ DateImplement = model.DateImplement
+ };
+ }
+
+ public void Update(OrderBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Status = model.Status;
+ DateImplement = model.DateImplement;
+ }
+
+ public OrderViewModel GetViewModel => new()
+ {
+ Id = Id,
+ PizzaId = PizzaId,
+ Count = Count,
+ Sum = Sum,
+ Status = Status,
+ DateCreate = DateCreate,
+ DateImplement = DateImplement
+ };
+ }
+}
diff --git a/Pizzeria/PizzeriaListImplement/Models/Pizza.cs b/Pizzeria/PizzeriaListImplement/Models/Pizza.cs
new file mode 100644
index 0000000..f48582b
--- /dev/null
+++ b/Pizzeria/PizzeriaListImplement/Models/Pizza.cs
@@ -0,0 +1,51 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.ViewModels;
+using PizzeriaDataModels;
+
+namespace PizzeriaListImplement.Models
+{
+ public class Pizza : IPizzaModel
+ {
+ public int Id { get; private set; }
+ public string PizzaName { get; private set; } = string.Empty;
+ public double Price { get; private set; }
+ public Dictionary PizzaComponents
+ {
+ get;
+ private set;
+ } = new Dictionary();
+ public static Pizza? Create(PizzaBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Pizza()
+ {
+
+ Id = model.Id,
+ PizzaName = model.PizzaName,
+ Price = model.Price,
+ PizzaComponents = model.PizzaComponents
+ };
+ }
+ public void Update(PizzaBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ PizzaName = model.PizzaName;
+ Price = model.Price;
+ PizzaComponents = model.PizzaComponents;
+ }
+ public PizzaViewModel GetViewModel => new()
+ {
+ Id = Id,
+ PizzaName = PizzaName,
+ Price = Price,
+ PizzaComponents = PizzaComponents
+ };
+ }
+}
+
diff --git a/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj b/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj
new file mode 100644
index 0000000..b612a23
--- /dev/null
+++ b/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj
@@ -0,0 +1,14 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+