diff --git a/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs b/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs
new file mode 100644
index 0000000..aaf6db8
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs
@@ -0,0 +1,145 @@
+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()
+ {
+ textBoxCount = new TextBox();
+ labelCount = new Label();
+ labelPizza = new Label();
+ buttonCancel = new Button();
+ buttonSave = new Button();
+ labelSum = new Label();
+ textBoxSum = new TextBox();
+ comboBoxPizza = new ComboBox();
+ SuspendLayout();
+ //
+ // textBoxCount
+ //
+ textBoxCount.Location = new Point(99, 41);
+ textBoxCount.Name = "textBoxCount";
+ textBoxCount.Size = new Size(233, 23);
+ textBoxCount.TabIndex = 13;
+ textBoxCount.TextChanged += textBoxCount_TextChanged;
+ //
+ // labelCount
+ //
+ labelCount.AutoSize = true;
+ labelCount.Location = new Point(11, 44);
+ labelCount.Name = "labelCount";
+ labelCount.Size = new Size(75, 15);
+ labelCount.TabIndex = 12;
+ labelCount.Text = "Количество:";
+ //
+ // labelPizza
+ //
+ labelPizza.AutoSize = true;
+ labelPizza.Location = new Point(11, 15);
+ labelPizza.Name = "labelPizza";
+ labelPizza.Size = new Size(43, 15);
+ labelPizza.TabIndex = 11;
+ labelPizza.Text = "Пицца";
+ //
+ // buttonCancel
+ //
+ buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonCancel.Location = new Point(257, 109);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 15;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // buttonSave
+ //
+ buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonSave.Location = new Point(176, 109);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 16;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // labelSum
+ //
+ labelSum.AutoSize = true;
+ labelSum.Location = new Point(11, 73);
+ labelSum.Name = "labelSum";
+ labelSum.Size = new Size(48, 15);
+ labelSum.TabIndex = 12;
+ labelSum.Text = "Сумма:";
+ //
+ // textBoxSum
+ //
+ textBoxSum.Location = new Point(99, 70);
+ textBoxSum.Name = "textBoxSum";
+ textBoxSum.ReadOnly = true;
+ textBoxSum.Size = new Size(233, 23);
+ textBoxSum.TabIndex = 13;
+ //
+ // comboBoxPizza
+ //
+ comboBoxPizza.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxPizza.FormattingEnabled = true;
+ comboBoxPizza.Location = new Point(99, 12);
+ comboBoxPizza.Name = "comboBoxPizza";
+ comboBoxPizza.Size = new Size(233, 23);
+ comboBoxPizza.TabIndex = 17;
+ //
+ // FormCreateOrder
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(351, 150);
+ Controls.Add(comboBoxPizza);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(textBoxSum);
+ Controls.Add(labelSum);
+ Controls.Add(textBoxCount);
+ Controls.Add(labelCount);
+ Controls.Add(labelPizza);
+ Name = "FormCreateOrder";
+ Text = "Заказ";
+ Load += FormCreateOrder_Load;
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+ private TextBox textBoxCount;
+ private Label labelCount;
+ private Label labelPizza;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private Label labelSum;
+ private TextBox textBoxSum;
+ private ComboBox comboBoxPizza;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormCreateOrder.cs b/Pizzeria/Pizzeria/FormCreateOrder.cs
new file mode 100644
index 0000000..128684e
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormCreateOrder.cs
@@ -0,0 +1,124 @@
+
+using Microsoft.Extensions.Logging;
+using Microsoft.VisualBasic.Logging;
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.ViewModels;
+using PizzeriaDataModels.Models;
+using System.Windows.Forms;
+
+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("Загрузка пицц для заказа");
+ try
+ {
+ var _list = _logicP.ReadList(null);
+ if (_list != null)
+ {
+ comboBoxPizza.DisplayMember = "PizzaName";
+ comboBoxPizza.ValueMember = "Id";
+ comboBoxPizza.DataSource = _list;
+ comboBoxPizza.SelectedItem = null;
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при загрузке пиццы для заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ 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 buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+
+ 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);
+ }
+
+ }
+ }
+}
diff --git a/Pizzeria/Pizzeria/FormCreateOrder.resx b/Pizzeria/Pizzeria/FormCreateOrder.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormCreateOrder.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormMain.Designer.cs b/Pizzeria/Pizzeria/FormMain.Designer.cs
new file mode 100644
index 0000000..51ab41d
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormMain.Designer.cs
@@ -0,0 +1,188 @@
+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()
+ {
+ menuStrip = new MenuStrip();
+ справочкиниToolStripMenuItem = new ToolStripMenuItem();
+ компонентыToolStripMenuItem = new ToolStripMenuItem();
+ изделияToolStripMenuItem = new ToolStripMenuItem();
+ dataGridView = new DataGridView();
+ ButtonIssuedOrder = new Button();
+ ButtonOrderReady = new Button();
+ ButtonnTakeOrderInWork = new Button();
+ ButtonCreateOrder = new Button();
+ buttonRef_Click = new Button();
+ menuStrip.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // menuStrip
+ //
+ menuStrip.Items.AddRange(new ToolStripItem[] { справочкиниToolStripMenuItem });
+ menuStrip.Location = new Point(0, 0);
+ menuStrip.Name = "menuStrip";
+ menuStrip.Size = new Size(999, 24);
+ menuStrip.TabIndex = 0;
+ menuStrip.Text = "Справочники:";
+ //
+ // справочкиниToolStripMenuItem
+ //
+ справочкиниToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem });
+ справочкиниToolStripMenuItem.Name = "справочкиниToolStripMenuItem";
+ справочкиниToolStripMenuItem.Size = new Size(97, 20);
+ справочкиниToolStripMenuItem.Text = "Справочники:";
+ //
+ // компонентыToolStripMenuItem
+ //
+ компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
+ компонентыToolStripMenuItem.Size = new Size(148, 22);
+ компонентыToolStripMenuItem.Text = "Ингредиенты";
+ компонентыToolStripMenuItem.Click += ИнгредиентыToolStripMenuItem_Click;
+ //
+ // изделияToolStripMenuItem
+ //
+ изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
+ изделияToolStripMenuItem.Size = new Size(148, 22);
+ изделияToolStripMenuItem.Text = "Пиццы";
+ изделияToolStripMenuItem.Click += ПиццыToolStripMenuItem_Click;
+ //
+ // dataGridView
+ //
+ dataGridView.AllowUserToAddRows = false;
+ dataGridView.AllowUserToDeleteRows = false;
+ dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
+ dataGridView.BackgroundColor = SystemColors.ControlLightLight;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(0, 27);
+ dataGridView.MultiSelect = false;
+ dataGridView.Name = "dataGridView";
+ dataGridView.ReadOnly = true;
+ dataGridView.RowHeadersVisible = false;
+ dataGridView.RowTemplate.Height = 25;
+ dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridView.Size = new Size(773, 362);
+ dataGridView.TabIndex = 0;
+ //
+ // ButtonIssuedOrder
+ //
+ ButtonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ ButtonIssuedOrder.Location = new Point(799, 185);
+ ButtonIssuedOrder.Margin = new Padding(3, 2, 3, 2);
+ ButtonIssuedOrder.Name = "ButtonIssuedOrder";
+ ButtonIssuedOrder.Size = new Size(179, 32);
+ ButtonIssuedOrder.TabIndex = 8;
+ ButtonIssuedOrder.Text = "Заказ выдан";
+ ButtonIssuedOrder.UseVisualStyleBackColor = true;
+ ButtonIssuedOrder.Click += ButtonIssuedOrder_Click;
+ //
+ // ButtonOrderReady
+ //
+ ButtonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ ButtonOrderReady.Location = new Point(799, 139);
+ ButtonOrderReady.Margin = new Padding(3, 2, 3, 2);
+ ButtonOrderReady.Name = "ButtonOrderReady";
+ ButtonOrderReady.Size = new Size(179, 32);
+ ButtonOrderReady.TabIndex = 7;
+ ButtonOrderReady.Text = "Заказ готов";
+ ButtonOrderReady.UseVisualStyleBackColor = true;
+ ButtonOrderReady.Click += ButtonOrderReady_Click;
+ //
+ // ButtonnTakeOrderInWork
+ //
+ ButtonnTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ ButtonnTakeOrderInWork.Location = new Point(799, 93);
+ ButtonnTakeOrderInWork.Margin = new Padding(3, 2, 3, 2);
+ ButtonnTakeOrderInWork.Name = "ButtonnTakeOrderInWork";
+ ButtonnTakeOrderInWork.Size = new Size(179, 32);
+ ButtonnTakeOrderInWork.TabIndex = 6;
+ ButtonnTakeOrderInWork.Text = "Отдать на выполнение";
+ ButtonnTakeOrderInWork.UseVisualStyleBackColor = true;
+ ButtonnTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
+ //
+ // ButtonCreateOrder
+ //
+ ButtonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ ButtonCreateOrder.Location = new Point(799, 47);
+ ButtonCreateOrder.Margin = new Padding(3, 2, 3, 2);
+ ButtonCreateOrder.Name = "ButtonCreateOrder";
+ ButtonCreateOrder.Size = new Size(179, 32);
+ ButtonCreateOrder.TabIndex = 5;
+ ButtonCreateOrder.Text = "Создать заказ";
+ ButtonCreateOrder.UseVisualStyleBackColor = true;
+ ButtonCreateOrder.Click += ButtonCreateOrder_Click;
+ //
+ // buttonRef_Click
+ //
+ buttonRef_Click.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonRef_Click.Location = new Point(799, 231);
+ buttonRef_Click.Margin = new Padding(3, 2, 3, 2);
+ buttonRef_Click.Name = "buttonRef_Click";
+ buttonRef_Click.Size = new Size(179, 32);
+ buttonRef_Click.TabIndex = 8;
+ buttonRef_Click.Text = "Обновить список";
+ buttonRef_Click.UseVisualStyleBackColor = true;
+ buttonRef_Click.Click += ButtonRef_Click;
+ //
+ // FormMain
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(999, 390);
+ Controls.Add(buttonRef_Click);
+ Controls.Add(ButtonIssuedOrder);
+ Controls.Add(ButtonOrderReady);
+ Controls.Add(ButtonnTakeOrderInWork);
+ Controls.Add(ButtonCreateOrder);
+ Controls.Add(dataGridView);
+ Controls.Add(menuStrip);
+ MainMenuStrip = menuStrip;
+ Name = "FormMain";
+ Text = "Пиццерия";
+ Load += FormMain_Load;
+ menuStrip.ResumeLayout(false);
+ menuStrip.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private MenuStrip menuStrip;
+ private ToolStripMenuItem справочкиниToolStripMenuItem;
+ private ToolStripMenuItem компонентыToolStripMenuItem;
+ private ToolStripMenuItem изделияToolStripMenuItem;
+ private DataGridView dataGridView;
+ private Button ButtonIssuedOrder;
+ private Button ButtonOrderReady;
+ private Button ButtonnTakeOrderInWork;
+ private Button ButtonCreateOrder;
+ private Button buttonRef_Click;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormMain.cs b/Pizzeria/Pizzeria/FormMain.cs
new file mode 100644
index 0000000..fc01400
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormMain.cs
@@ -0,0 +1,138 @@
+using Microsoft.Extensions.Logging;
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+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 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(new OrderBindingModel{ Id = id });
+ 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(new OrderBindingModel { Id = id });
+ 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(new OrderBindingModel { Id = id });
+ 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();
+ }
+ }
+
+}
diff --git a/Pizzeria/Pizzeria/FormMain.resx b/Pizzeria/Pizzeria/FormMain.resx
new file mode 100644
index 0000000..6c82d08
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormMain.resx
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
\ 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..6453d21
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizza.Designer.cs
@@ -0,0 +1,240 @@
+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()
+ {
+ textBoxPrice = new TextBox();
+ textBoxName = new TextBox();
+ labelPrice = new Label();
+ labelName = new Label();
+ ButtonUpd = new Button();
+ ButtonDel = new Button();
+ ButtonRef = new Button();
+ ButtonAdd = new Button();
+ dataGridView = new DataGridView();
+ ColumnId = new DataGridViewTextBoxColumn();
+ ColumnComponent = new DataGridViewTextBoxColumn();
+ ColumnCount = new DataGridViewTextBoxColumn();
+ buttonCancel = new Button();
+ buttonSave = new Button();
+ groupBoxComponents = new GroupBox();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ groupBoxComponents.SuspendLayout();
+ SuspendLayout();
+ //
+ // textBoxPrice
+ //
+ textBoxPrice.Enabled = false;
+ textBoxPrice.Location = new Point(99, 41);
+ textBoxPrice.Name = "textBoxPrice";
+ textBoxPrice.Size = new Size(233, 23);
+ textBoxPrice.TabIndex = 5;
+ //
+ // textBoxName
+ //
+ textBoxName.Location = new Point(99, 12);
+ textBoxName.Name = "textBoxName";
+ textBoxName.Size = new Size(233, 23);
+ textBoxName.TabIndex = 6;
+ //
+ // labelPrice
+ //
+ labelPrice.AutoSize = true;
+ labelPrice.Location = new Point(11, 44);
+ labelPrice.Name = "labelPrice";
+ labelPrice.Size = new Size(70, 15);
+ labelPrice.TabIndex = 4;
+ labelPrice.Text = "Стоимость:";
+ //
+ // labelName
+ //
+ labelName.AutoSize = true;
+ labelName.Location = new Point(11, 15);
+ labelName.Name = "labelName";
+ labelName.Size = new Size(62, 15);
+ labelName.TabIndex = 3;
+ labelName.Text = "Название:";
+ //
+ // ButtonUpd
+ //
+ ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ ButtonUpd.Location = new Point(467, 135);
+ ButtonUpd.Margin = new Padding(3, 2, 3, 2);
+ ButtonUpd.Name = "ButtonUpd";
+ ButtonUpd.Size = new Size(82, 22);
+ ButtonUpd.TabIndex = 10;
+ ButtonUpd.Text = "Обновить";
+ ButtonUpd.UseVisualStyleBackColor = true;
+ ButtonUpd.Click += ButtonUpd_Click;
+ //
+ // ButtonDel
+ //
+ ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ ButtonDel.Location = new Point(467, 100);
+ ButtonDel.Margin = new Padding(3, 2, 3, 2);
+ ButtonDel.Name = "ButtonDel";
+ ButtonDel.Size = new Size(82, 22);
+ ButtonDel.TabIndex = 9;
+ ButtonDel.Text = "Удалить";
+ ButtonDel.UseVisualStyleBackColor = true;
+ ButtonDel.Click += ButtonDel_Click;
+ //
+ // ButtonRef
+ //
+ ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ ButtonRef.Location = new Point(467, 62);
+ ButtonRef.Margin = new Padding(3, 2, 3, 2);
+ ButtonRef.Name = "ButtonRef";
+ ButtonRef.Size = new Size(82, 22);
+ ButtonRef.TabIndex = 8;
+ ButtonRef.Text = "Изменить";
+ ButtonRef.UseVisualStyleBackColor = true;
+ ButtonRef.Click += ButtonRef_Click;
+ //
+ // ButtonAdd
+ //
+ ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ ButtonAdd.Location = new Point(467, 27);
+ ButtonAdd.Margin = new Padding(3, 2, 3, 2);
+ ButtonAdd.Name = "ButtonAdd";
+ ButtonAdd.Size = new Size(82, 22);
+ ButtonAdd.TabIndex = 7;
+ ButtonAdd.Text = "Добавить";
+ ButtonAdd.UseVisualStyleBackColor = true;
+ ButtonAdd.Click += ButtonAdd_Click;
+ //
+ // dataGridView
+ //
+ dataGridView.AllowUserToAddRows = false;
+ dataGridView.AllowUserToDeleteRows = false;
+ dataGridView.BackgroundColor = SystemColors.ControlLightLight;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnComponent, ColumnCount });
+ dataGridView.Location = new Point(6, 22);
+ dataGridView.Name = "dataGridView";
+ dataGridView.ReadOnly = true;
+ dataGridView.RowHeadersVisible = false;
+ dataGridView.RowTemplate.Height = 25;
+ dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridView.Size = new Size(429, 262);
+ dataGridView.TabIndex = 11;
+ //
+ // ColumnId
+ //
+ ColumnId.HeaderText = "Id";
+ ColumnId.Name = "ColumnId";
+ ColumnId.Visible = false;
+ //
+ // ColumnComponent
+ //
+ ColumnComponent.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ ColumnComponent.HeaderText = "Ингредиент";
+ ColumnComponent.Name = "ColumnComponent";
+ //
+ // ColumnCount
+ //
+ ColumnCount.HeaderText = "Количество";
+ ColumnCount.Name = "ColumnCount";
+ //
+ // buttonCancel
+ //
+ buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonCancel.Location = new Point(486, 386);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 12;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // buttonSave
+ //
+ buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonSave.Location = new Point(405, 386);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 13;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // groupBoxComponents
+ //
+ groupBoxComponents.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
+ groupBoxComponents.Controls.Add(ButtonUpd);
+ groupBoxComponents.Controls.Add(ButtonDel);
+ groupBoxComponents.Controls.Add(ButtonRef);
+ groupBoxComponents.Controls.Add(dataGridView);
+ groupBoxComponents.Controls.Add(ButtonAdd);
+ groupBoxComponents.Location = new Point(12, 81);
+ groupBoxComponents.Name = "groupBoxComponents";
+ groupBoxComponents.Size = new Size(579, 287);
+ groupBoxComponents.TabIndex = 14;
+ groupBoxComponents.TabStop = false;
+ groupBoxComponents.Text = "Ингредиенты";
+ //
+ // FormPizza
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(612, 430);
+ Controls.Add(groupBoxComponents);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(textBoxPrice);
+ Controls.Add(textBoxName);
+ Controls.Add(labelPrice);
+ Controls.Add(labelName);
+ Name = "FormPizza";
+ Text = "Пицца";
+ Load += FormPizza_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ groupBoxComponents.ResumeLayout(false);
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private TextBox textBoxPrice;
+ private TextBox textBoxName;
+ private Label labelPrice;
+ private Label labelName;
+ private Button ButtonUpd;
+ private Button ButtonDel;
+ private Button ButtonRef;
+ private Button ButtonAdd;
+ private DataGridView dataGridView;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private GroupBox groupBoxComponents;
+ private DataGridViewTextBoxColumn ColumnId;
+ private DataGridViewTextBoxColumn ColumnComponent;
+ private DataGridViewTextBoxColumn ColumnCount;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormPizza.cs b/Pizzeria/Pizzeria/FormPizza.cs
new file mode 100644
index 0000000..8ea52ab
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizza.cs
@@ -0,0 +1,204 @@
+using Microsoft.Extensions.Logging;
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.SearchModels;
+using PizzeriaDataModels.Models;
+
+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 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);
+ }
+
+ 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 ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ private void ButtonDel_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ try
+ {
+ _logger.LogInformation("Удаление ингредиента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); _PizzaComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ 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 buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+
+ 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);
+ }
+
+ }
+
+ }
+}
diff --git a/Pizzeria/Pizzeria/FormPizza.resx b/Pizzeria/Pizzeria/FormPizza.resx
new file mode 100644
index 0000000..524a4e1
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizza.resx
@@ -0,0 +1,129 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/FormPizzas.Designer.cs b/Pizzeria/Pizzeria/FormPizzas.Designer.cs
new file mode 100644
index 0000000..09e90e7
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizzas.Designer.cs
@@ -0,0 +1,128 @@
+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()
+ {
+ ButtonUpd = new Button();
+ ButtonDel = new Button();
+ ButtonRef = new Button();
+ ButtonAdd = new Button();
+ dataGridView = new DataGridView();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // ButtonUpd
+ //
+ ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ ButtonUpd.Location = new Point(584, 138);
+ ButtonUpd.Margin = new Padding(3, 2, 3, 2);
+ ButtonUpd.Name = "ButtonUpd";
+ ButtonUpd.Size = new Size(82, 22);
+ ButtonUpd.TabIndex = 9;
+ ButtonUpd.Text = "Обновить";
+ ButtonUpd.UseVisualStyleBackColor = true;
+ ButtonUpd.Click += ButtonRef_Click;
+ //
+ // ButtonDel
+ //
+ ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ ButtonDel.Location = new Point(584, 103);
+ ButtonDel.Margin = new Padding(3, 2, 3, 2);
+ ButtonDel.Name = "ButtonDel";
+ ButtonDel.Size = new Size(82, 22);
+ ButtonDel.TabIndex = 8;
+ ButtonDel.Text = "Удалить";
+ ButtonDel.UseVisualStyleBackColor = true;
+ ButtonDel.Click += ButtonDel_Click;
+ //
+ // ButtonRef
+ //
+ ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ ButtonRef.Location = new Point(584, 65);
+ ButtonRef.Margin = new Padding(3, 2, 3, 2);
+ ButtonRef.Name = "ButtonRef";
+ ButtonRef.Size = new Size(82, 22);
+ ButtonRef.TabIndex = 7;
+ ButtonRef.Text = "Изменить";
+ ButtonRef.UseVisualStyleBackColor = true;
+ ButtonRef.Click += ButtonUpd_Click;
+ //
+ // ButtonAdd
+ //
+ ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ ButtonAdd.Location = new Point(584, 30);
+ ButtonAdd.Margin = new Padding(3, 2, 3, 2);
+ ButtonAdd.Name = "ButtonAdd";
+ ButtonAdd.Size = new Size(82, 22);
+ ButtonAdd.TabIndex = 6;
+ ButtonAdd.Text = "Добавить";
+ ButtonAdd.UseVisualStyleBackColor = true;
+ ButtonAdd.Click += ButtonAdd_Click;
+ //
+ // dataGridView
+ //
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Dock = DockStyle.Left;
+ dataGridView.Location = new Point(0, 0);
+ dataGridView.Margin = new Padding(3, 2, 3, 2);
+ dataGridView.MultiSelect = false;
+ dataGridView.Name = "dataGridView";
+ dataGridView.ReadOnly = true;
+ dataGridView.RowHeadersVisible = false;
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridView.Size = new Size(550, 264);
+ dataGridView.TabIndex = 5;
+ //
+ // FormPizzas
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(702, 264);
+ Controls.Add(ButtonUpd);
+ Controls.Add(ButtonDel);
+ Controls.Add(ButtonRef);
+ Controls.Add(ButtonAdd);
+ Controls.Add(dataGridView);
+ Name = "FormPizzas";
+ Text = "Пиццы";
+ Load += FormPizzas_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private Button ButtonUpd;
+ private Button ButtonDel;
+ private Button ButtonRef;
+ private Button ButtonAdd;
+ 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..cd5580e
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizzas.cs
@@ -0,0 +1,107 @@
+using Microsoft.Extensions.Logging;
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+
+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 ButtonRef_Click(object sender, EventArgs e)
+ {
+ 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 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();
+ }
+ }
+ }
+ }
+
+
+ }
+}
diff --git a/Pizzeria/Pizzeria/FormPizzas.resx b/Pizzeria/Pizzeria/FormPizzas.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormPizzas.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormProductComponent.Designer.cs b/Pizzeria/Pizzeria/FormProductComponent.Designer.cs
new file mode 100644
index 0000000..ba3570d
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormProductComponent.Designer.cs
@@ -0,0 +1,121 @@
+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()
+ {
+ buttonCancel = new Button();
+ buttonSave = new Button();
+ textBoxCount = new TextBox();
+ labelCount = new Label();
+ labelComponent = new Label();
+ comboBoxComponent = new ComboBox();
+ SuspendLayout();
+ //
+ // buttonCancel
+ //
+ buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonCancel.Location = new Point(259, 87);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 8;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // buttonSave
+ //
+ buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonSave.Location = new Point(178, 87);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 9;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // textBoxCount
+ //
+ textBoxCount.Location = new Point(101, 41);
+ textBoxCount.Name = "textBoxCount";
+ textBoxCount.Size = new Size(233, 23);
+ textBoxCount.TabIndex = 6;
+ //
+ // labelCount
+ //
+ labelCount.AutoSize = true;
+ labelCount.Location = new Point(13, 44);
+ labelCount.Name = "labelCount";
+ labelCount.Size = new Size(75, 15);
+ labelCount.TabIndex = 5;
+ labelCount.Text = "Количество:";
+ //
+ // labelComponent
+ //
+ labelComponent.AutoSize = true;
+ labelComponent.Location = new Point(13, 15);
+ labelComponent.Name = "labelComponent";
+ labelComponent.Size = new Size(75, 15);
+ labelComponent.TabIndex = 4;
+ labelComponent.Text = "Ингредиент:";
+ //
+ // comboBoxComponent
+ //
+ comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxComponent.FormattingEnabled = true;
+ comboBoxComponent.Location = new Point(101, 12);
+ comboBoxComponent.Name = "comboBoxComponent";
+ comboBoxComponent.Size = new Size(233, 23);
+ comboBoxComponent.TabIndex = 10;
+ //
+ // FormPizzaComponent
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(355, 125);
+ Controls.Add(comboBoxComponent);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(textBoxCount);
+ Controls.Add(labelCount);
+ Controls.Add(labelComponent);
+ Name = "FormPizzaComponent";
+ Text = "Ингредиент пиццы";
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Button buttonCancel;
+ private Button buttonSave;
+ private TextBox textBoxCount;
+ private Label labelCount;
+ private Label labelComponent;
+ private ComboBox comboBoxComponent;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormProductComponent.cs b/Pizzeria/Pizzeria/FormProductComponent.cs
new file mode 100644
index 0000000..92565f4
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormProductComponent.cs
@@ -0,0 +1,83 @@
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.ViewModels;
+using PizzeriaDataModels.Models;
+
+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/FormProductComponent.resx b/Pizzeria/Pizzeria/FormProductComponent.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormProductComponent.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs
new file mode 100644
index 0000000..39cd57f
--- /dev/null
+++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs
@@ -0,0 +1,106 @@
+using Microsoft.Extensions.Logging;
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.StorageContracts;
+using PizzeriaContracts.ViewModels;
+
+
+namespace PizzeriaBusinessLogic.BusinessLogic
+{
+ 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("Pizza. 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/PizzeriaContracts/BindingModels/PizzaBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs
new file mode 100644
index 0000000..9905269
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs
@@ -0,0 +1,12 @@
+using PizzeriaDataModels.Models;
+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/IPizzaLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IPizzaLogic.cs
new file mode 100644
index 0000000..5ab632a
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IPizzaLogic.cs
@@ -0,0 +1,15 @@
+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/SearchModels/PizzaSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs
new file mode 100644
index 0000000..86ebea7
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs
@@ -0,0 +1,8 @@
+namespace PizzeriaContracts.SearchModels
+{
+ public class PizzaSearchModel
+ {
+ public int? Id { get; set; }
+ public string? PizzaName { get; set; }
+ }
+}
diff --git a/Pizzeria/PizzeriaContracts/StorageContracts/IPizzaStorage.cs b/Pizzeria/PizzeriaContracts/StorageContracts/IPizzaStorage.cs
new file mode 100644
index 0000000..4ec1629
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/StorageContracts/IPizzaStorage.cs
@@ -0,0 +1,17 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.ViewModels;
+
+namespace PizzeriaContracts.StorageContracts
+{
+ 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/PizzaViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs
new file mode 100644
index 0000000..4b85d07
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs
@@ -0,0 +1,18 @@
+using PizzeriaDataModels.Models;
+using System.ComponentModel;
+
+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/Models/IPizzaModel.cs b/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs
new file mode 100644
index 0000000..a490537
--- /dev/null
+++ b/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs
@@ -0,0 +1,9 @@
+namespace PizzeriaDataModels.Models
+{
+ public interface IPizzaModel : IId
+ {
+ string PizzaName { get; }
+ double Price { get; }
+ Dictionary PizzaComponents { get; }
+ }
+}
diff --git a/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs
new file mode 100644
index 0000000..271b0f7
--- /dev/null
+++ b/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs
@@ -0,0 +1,100 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.StorageContracts;
+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/Pizza.cs b/Pizzeria/PizzeriaListImplement/Models/Pizza.cs
new file mode 100644
index 0000000..fbc61ee
--- /dev/null
+++ b/Pizzeria/PizzeriaListImplement/Models/Pizza.cs
@@ -0,0 +1,49 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.ViewModels;
+using PizzeriaDataModels.Models;
+
+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
+ };
+ }
+}