From c78f16557f51ba4fa6f3a7366ce3df89a9e30e9a Mon Sep 17 00:00:00 2001
From: MaxKarme <91691525+MaxKarme@users.noreply.github.com>
Date: Mon, 27 Mar 2023 22:50:07 +0400
Subject: [PATCH] lab1_hard
---
Pizzeria/Pizzeria/FormMain.Designer.cs | 30 ++-
Pizzeria/Pizzeria/FormMain.cs | 16 ++
Pizzeria/Pizzeria/FormPizza.cs | 2 +-
Pizzeria/Pizzeria/FormShop.Designer.cs | 210 ++++++++++++++++++
Pizzeria/Pizzeria/FormShop.cs | 117 ++++++++++
Pizzeria/Pizzeria/FormShop.resx | 63 ++++++
Pizzeria/Pizzeria/FormShopPizza.Designer.cs | 144 ++++++++++++
Pizzeria/Pizzeria/FormShopPizza.cs | 109 +++++++++
Pizzeria/Pizzeria/FormShopPizza.resx | 60 +++++
Pizzeria/Pizzeria/FormShops.Designer.cs | 123 ++++++++++
Pizzeria/Pizzeria/FormShops.cs | 101 +++++++++
Pizzeria/Pizzeria/FormShops.resx | 60 +++++
Pizzeria/Pizzeria/Program.cs | 5 +
Pizzeria/PizzeriaBusinessLogic/ShopLogic.cs | 141 ++++++++++++
.../BindingModels/ShopBindingModel.cs | 20 ++
.../BusinessLogicsContracts/IShopLogic.cs | 17 ++
.../SearchModels/ShopSearchModel.cs | 14 ++
.../StoragesContracts/IShopStorage.cs | 16 ++
.../ViewModels/ShopViewModel.cs | 23 ++
.../PizzeriaDataModels/Models/IShopModel.cs | 17 ++
.../DataListSingleton.cs | 2 +
.../Implements/ShopStorage.cs | 116 ++++++++++
Pizzeria/PizzeriaListImplement/Models/Shop.cs | 56 +++++
23 files changed, 1458 insertions(+), 4 deletions(-)
create mode 100644 Pizzeria/Pizzeria/FormShop.Designer.cs
create mode 100644 Pizzeria/Pizzeria/FormShop.cs
create mode 100644 Pizzeria/Pizzeria/FormShop.resx
create mode 100644 Pizzeria/Pizzeria/FormShopPizza.Designer.cs
create mode 100644 Pizzeria/Pizzeria/FormShopPizza.cs
create mode 100644 Pizzeria/Pizzeria/FormShopPizza.resx
create mode 100644 Pizzeria/Pizzeria/FormShops.Designer.cs
create mode 100644 Pizzeria/Pizzeria/FormShops.cs
create mode 100644 Pizzeria/Pizzeria/FormShops.resx
create mode 100644 Pizzeria/PizzeriaBusinessLogic/ShopLogic.cs
create mode 100644 Pizzeria/PizzeriaContracts/BindingModels/ShopBindingModel.cs
create mode 100644 Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IShopLogic.cs
create mode 100644 Pizzeria/PizzeriaContracts/SearchModels/ShopSearchModel.cs
create mode 100644 Pizzeria/PizzeriaContracts/StoragesContracts/IShopStorage.cs
create mode 100644 Pizzeria/PizzeriaContracts/ViewModels/ShopViewModel.cs
create mode 100644 Pizzeria/PizzeriaDataModels/Models/IShopModel.cs
create mode 100644 Pizzeria/PizzeriaListImplement/Implements/ShopStorage.cs
create mode 100644 Pizzeria/PizzeriaListImplement/Models/Shop.cs
diff --git a/Pizzeria/Pizzeria/FormMain.Designer.cs b/Pizzeria/Pizzeria/FormMain.Designer.cs
index 1a753ee..f00039f 100644
--- a/Pizzeria/Pizzeria/FormMain.Designer.cs
+++ b/Pizzeria/Pizzeria/FormMain.Designer.cs
@@ -40,6 +40,8 @@
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.button6 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@@ -134,7 +136,8 @@
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.компонентыToolStripMenuItem,
- this.изделияToolStripMenuItem});
+ this.изделияToolStripMenuItem,
+ this.магазиныToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24);
this.справочникиToolStripMenuItem.Text = "Справочники";
@@ -142,22 +145,41 @@
// компонентыToolStripMenuItem
//
this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
- this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
+ this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 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.Size = new System.Drawing.Size(182, 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(182, 26);
+ this.магазиныToolStripMenuItem.Text = "Магазины";
+ this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
+ //
+ // button6
+ //
+ this.button6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button6.Location = new System.Drawing.Point(987, 284);
+ this.button6.Name = "button6";
+ this.button6.Size = new System.Drawing.Size(209, 29);
+ this.button6.TabIndex = 12;
+ this.button6.Text = "Пополнить магазин";
+ this.button6.UseVisualStyleBackColor = true;
+ this.button6.Click += new System.EventHandler(this.ButtonRestore_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.button6);
this.Controls.Add(this.menuStrip1);
this.Controls.Add(this.button3);
this.Controls.Add(this.button5);
@@ -190,5 +212,7 @@
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem изделияToolStripMenuItem;
+ private ToolStripMenuItem магазиныToolStripMenuItem;
+ private Button button6;
}
}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormMain.cs b/Pizzeria/Pizzeria/FormMain.cs
index 1f13dba..4f2c854 100644
--- a/Pizzeria/Pizzeria/FormMain.cs
+++ b/Pizzeria/Pizzeria/FormMain.cs
@@ -54,6 +54,14 @@ namespace Pizzeria
form.ShowDialog();
}
}
+ private void ToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShops));
+ if (service is FormShops form)
+ {
+ form.ShowDialog();
+ }
+ }
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
@@ -151,5 +159,13 @@ namespace Pizzeria
LoadData();
}
+ private void ButtonRestore_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShopPizza));
+ if (service is FormShopPizza form)
+ {
+ form.ShowDialog();
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormPizza.cs b/Pizzeria/Pizzeria/FormPizza.cs
index f21b7ca..a91ecd5 100644
--- a/Pizzeria/Pizzeria/FormPizza.cs
+++ b/Pizzeria/Pizzeria/FormPizza.cs
@@ -81,7 +81,7 @@ namespace Pizzeria
{
return;
}
- _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
+ _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
if (_pizzaComponents.ContainsKey(form.Id))
{
_pizzaComponents[form.Id] = (form.ComponentModel, form.Count);
diff --git a/Pizzeria/Pizzeria/FormShop.Designer.cs b/Pizzeria/Pizzeria/FormShop.Designer.cs
new file mode 100644
index 0000000..921424f
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormShop.Designer.cs
@@ -0,0 +1,210 @@
+namespace Pizzeria
+{
+ partial class FormShop
+ {
+ ///
+ /// 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.dateTimePicker = new System.Windows.Forms.DateTimePicker();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.textBoxAddres = new System.Windows.Forms.TextBox();
+ this.labelTime = new System.Windows.Forms.Label();
+ this.labelAddress = new System.Windows.Forms.Label();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ColumnID = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnManufactureName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Цена = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.labelShop = new System.Windows.Forms.Label();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // dateTimePicker
+ //
+ this.dateTimePicker.Location = new System.Drawing.Point(439, 36);
+ this.dateTimePicker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.dateTimePicker.Name = "dateTimePicker";
+ this.dateTimePicker.Size = new System.Drawing.Size(236, 27);
+ this.dateTimePicker.TabIndex = 26;
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(12, 36);
+ this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(161, 27);
+ this.textBoxName.TabIndex = 25;
+ //
+ // textBoxAddres
+ //
+ this.textBoxAddres.Location = new System.Drawing.Point(180, 36);
+ this.textBoxAddres.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.textBoxAddres.Name = "textBoxAddres";
+ this.textBoxAddres.Size = new System.Drawing.Size(252, 27);
+ this.textBoxAddres.TabIndex = 24;
+ //
+ // labelTime
+ //
+ this.labelTime.AutoSize = true;
+ this.labelTime.Location = new System.Drawing.Point(439, 12);
+ this.labelTime.Name = "labelTime";
+ this.labelTime.Size = new System.Drawing.Size(110, 20);
+ this.labelTime.TabIndex = 23;
+ this.labelTime.Text = "Дата открытия";
+ //
+ // labelAddress
+ //
+ this.labelAddress.AutoSize = true;
+ this.labelAddress.Location = new System.Drawing.Point(180, 12);
+ this.labelAddress.Name = "labelAddress";
+ this.labelAddress.Size = new System.Drawing.Size(51, 20);
+ this.labelAddress.TabIndex = 22;
+ this.labelAddress.Text = "Адрес";
+ //
+ // 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.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.ColumnID,
+ this.ColumnManufactureName,
+ this.Цена,
+ this.ColumnCount});
+ this.dataGridView.Location = new System.Drawing.Point(12, 74);
+ this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 62;
+ this.dataGridView.RowTemplate.Height = 25;
+ this.dataGridView.Size = new System.Drawing.Size(664, 296);
+ this.dataGridView.TabIndex = 21;
+ //
+ // ColumnID
+ //
+ this.ColumnID.HeaderText = "ID";
+ this.ColumnID.MinimumWidth = 8;
+ this.ColumnID.Name = "ColumnID";
+ this.ColumnID.Visible = false;
+ this.ColumnID.Width = 150;
+ //
+ // ColumnManufactureName
+ //
+ this.ColumnManufactureName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.ColumnManufactureName.HeaderText = "Название пиццы";
+ this.ColumnManufactureName.MinimumWidth = 8;
+ this.ColumnManufactureName.Name = "ColumnManufactureName";
+ //
+ // Цена
+ //
+ this.Цена.HeaderText = "Цена";
+ this.Цена.MinimumWidth = 6;
+ this.Цена.Name = "Цена";
+ this.Цена.Width = 125;
+ //
+ // ColumnCount
+ //
+ this.ColumnCount.HeaderText = "Количество";
+ this.ColumnCount.MinimumWidth = 8;
+ this.ColumnCount.Name = "ColumnCount";
+ this.ColumnCount.Width = 150;
+ //
+ // labelShop
+ //
+ this.labelShop.AutoSize = true;
+ this.labelShop.Location = new System.Drawing.Point(12, 12);
+ this.labelShop.Name = "labelShop";
+ this.labelShop.Size = new System.Drawing.Size(69, 20);
+ this.labelShop.TabIndex = 20;
+ this.labelShop.Text = "Магазин";
+ //
+ // buttonSave
+ //
+ this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonSave.Location = new System.Drawing.Point(415, 383);
+ this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(137, 30);
+ this.buttonSave.TabIndex = 28;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonCancel.Location = new System.Drawing.Point(558, 383);
+ this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(118, 30);
+ this.buttonCancel.TabIndex = 27;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FormShop
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(704, 426);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.dateTimePicker);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.textBoxAddres);
+ this.Controls.Add(this.labelTime);
+ this.Controls.Add(this.labelAddress);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.labelShop);
+ this.Name = "FormShop";
+ this.Text = "FormShop";
+ this.Load += new System.EventHandler(this.FormShop_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private DateTimePicker dateTimePicker;
+ private TextBox textBoxName;
+ private TextBox textBoxAddres;
+ private Label labelTime;
+ private Label labelAddress;
+ private DataGridView dataGridView;
+ private DataGridViewTextBoxColumn ColumnID;
+ private DataGridViewTextBoxColumn ColumnManufactureName;
+ private DataGridViewTextBoxColumn Цена;
+ private DataGridViewTextBoxColumn ColumnCount;
+ private Label labelShop;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormShop.cs b/Pizzeria/Pizzeria/FormShop.cs
new file mode 100644
index 0000000..f0298e4
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormShop.cs
@@ -0,0 +1,117 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.SearchModels;
+using PizzeriaDataModels;
+using Microsoft.Extensions.Logging;
+
+
+namespace Pizzeria
+{
+ public partial class FormShop : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IShopLogic _logic;
+ private int? _id;
+ private Dictionary _shopPizzas;
+ public int Id { set { _id = value; } }
+ public FormShop(ILogger logger, IShopLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ _shopPizzas = new Dictionary();
+ }
+ private void FormShop_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ _logger.LogInformation("Загрузка магазина");
+ try
+ {
+ var view = _logic.ReadElement(new ShopSearchModel
+ {
+ Id = _id.Value
+ });
+ if (view != null)
+ {
+ textBoxName.Text = view.ShopName;
+ textBoxAddres.Text = view.Addres.ToString();
+ dateTimePicker.Text = view.OpenTime.ToString();
+ _shopPizzas = view.ShopPizzas ?? new Dictionary();
+ LoadData();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки магазина");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка компонент магазина");
+ try
+ {
+ if (_shopPizzas != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var pc in _shopPizzas)
+ {
+ dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.PizzaName , pc.Value.Item1.Price, pc.Value.Item2 });
+ }
+ }
+ }
+ 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;
+ }
+ if (string.IsNullOrEmpty(textBoxAddres.Text))
+ {
+ MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение магазина");
+ try
+ {
+ var model = new ShopBindingModel
+ {
+ Id = _id ?? 0,
+ ShopName = textBoxName.Text,
+ Addres = textBoxAddres.Text,
+ OpenTime = dateTimePicker.Value.Date,
+ ShopPizzas = _shopPizzas
+ };
+ 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/FormShop.resx b/Pizzeria/Pizzeria/FormShop.resx
new file mode 100644
index 0000000..3f97278
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormShop.resx
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormShopPizza.Designer.cs b/Pizzeria/Pizzeria/FormShopPizza.Designer.cs
new file mode 100644
index 0000000..2a719f6
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormShopPizza.Designer.cs
@@ -0,0 +1,144 @@
+namespace Pizzeria
+{
+ partial class FormShopPizza
+ {
+ ///
+ /// 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.comboBoxShop = 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.comboBoxPizza = new System.Windows.Forms.ComboBox();
+ this.label1 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label3 = new System.Windows.Forms.Label();
+ this.SuspendLayout();
+ //
+ // comboBoxShop
+ //
+ this.comboBoxShop.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxShop.FormattingEnabled = true;
+ this.comboBoxShop.Location = new System.Drawing.Point(116, 24);
+ this.comboBoxShop.Name = "comboBoxShop";
+ this.comboBoxShop.Size = new System.Drawing.Size(224, 28);
+ this.comboBoxShop.TabIndex = 16;
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(246, 136);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(94, 29);
+ this.buttonCancel.TabIndex = 15;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(132, 136);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(94, 29);
+ this.buttonSave.TabIndex = 14;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(116, 92);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(225, 27);
+ this.textBoxCount.TabIndex = 13;
+ //
+ // comboBoxPizza
+ //
+ this.comboBoxPizza.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxPizza.FormattingEnabled = true;
+ this.comboBoxPizza.Location = new System.Drawing.Point(116, 58);
+ this.comboBoxPizza.Name = "comboBoxPizza";
+ this.comboBoxPizza.Size = new System.Drawing.Size(224, 28);
+ this.comboBoxPizza.TabIndex = 17;
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(23, 27);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(72, 20);
+ this.label1.TabIndex = 18;
+ this.label1.Text = "Магазин:";
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(23, 61);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(58, 20);
+ this.label2.TabIndex = 19;
+ this.label2.Text = "Пицца:";
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(23, 95);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(93, 20);
+ this.label3.TabIndex = 20;
+ this.label3.Text = "Количество:";
+ //
+ // FormShopPizza
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(371, 194);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.comboBoxPizza);
+ this.Controls.Add(this.comboBoxShop);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxCount);
+ this.Name = "FormShopPizza";
+ this.Text = "FormShopPizza";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private ComboBox comboBoxShop;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private TextBox textBoxCount;
+ private ComboBox comboBoxPizza;
+ private Label label1;
+ private Label label2;
+ private Label label3;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormShopPizza.cs b/Pizzeria/Pizzeria/FormShopPizza.cs
new file mode 100644
index 0000000..2bdab9a
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormShopPizza.cs
@@ -0,0 +1,109 @@
+using Microsoft.Extensions.Logging;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.ViewModels;
+using PizzeriaDataModels;
+
+
+namespace Pizzeria
+{
+ public partial class FormShopPizza : Form
+ {
+ ILogger _logger;
+ IShopLogic _shopLogic;
+ IPizzaLogic _pizzaLogic;
+ List _listPizza;
+
+ public int ShopId
+ {
+ get
+ {
+ return Convert.ToInt32(comboBoxShop.SelectedValue);
+ }
+ set
+ {
+ comboBoxShop.SelectedValue = value;
+ }
+ }
+
+ public FormShopPizza(ILogger logger, IShopLogic shopLigic, IPizzaLogic pizzaLigic)
+ {
+ InitializeComponent();
+
+ _logger = logger;
+ _shopLogic = shopLigic;
+ _pizzaLogic = pizzaLigic;
+
+ List _listShop = shopLigic.ReadList(null);
+ List _listPizza = pizzaLigic.ReadList(null);
+ if (_listShop != null)
+ {
+ comboBoxShop.DisplayMember = "ShopName";
+ comboBoxShop.ValueMember = "Id";
+ comboBoxShop.DataSource = _listShop;
+ comboBoxShop.SelectedItem = null;
+ }
+ if (_listPizza != null)
+ {
+ comboBoxPizza.DisplayMember = "PizzaName";
+ comboBoxPizza.ValueMember = "Id";
+ comboBoxPizza.DataSource = _listPizza;
+ comboBoxPizza.SelectedItem = null;
+ }
+ }
+
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxShop.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ if (comboBoxPizza.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+
+ try
+ {
+ int count = Convert.ToInt32(textBoxCount.Text);
+
+ bool res = _shopLogic.AddPizza(
+ new() { Id = Convert.ToInt32(comboBoxShop.SelectedValue) },
+ _pizzaLogic.ReadElement(new() { Id = Convert.ToInt32(comboBoxPizza.SelectedValue) }),
+ count
+ );
+
+ if (!res)
+ {
+ throw new Exception("Ошибка при пополнении. Дополнительная информация в логах");
+ }
+
+ MessageBox.Show("Пополнение прошло успешно");
+ DialogResult = DialogResult.OK;
+ Close();
+
+ }
+ catch (Exception err)
+ {
+ MessageBox.Show("Ошибка пополнения");
+ _logger.LogError(err, "Ошибка пополнения");
+ return;
+ }
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormShopPizza.resx b/Pizzeria/Pizzeria/FormShopPizza.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormShopPizza.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/FormShops.Designer.cs b/Pizzeria/Pizzeria/FormShops.Designer.cs
new file mode 100644
index 0000000..dea709f
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormShops.Designer.cs
@@ -0,0 +1,123 @@
+namespace Pizzeria
+{
+ partial class FormShops
+ {
+ ///
+ /// 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(603, 118);
+ this.button5.Name = "button5";
+ this.button5.Size = new System.Drawing.Size(94, 29);
+ this.button5.TabIndex = 15;
+ 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(603, 165);
+ this.button4.Name = "button4";
+ this.button4.Size = new System.Drawing.Size(94, 29);
+ this.button4.TabIndex = 14;
+ 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(603, 71);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(94, 29);
+ this.button2.TabIndex = 13;
+ 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(603, 24);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(94, 29);
+ this.button1.TabIndex = 12;
+ 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(-2, 1);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(579, 447);
+ this.dataGridView.TabIndex = 11;
+ //
+ // FormShops
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(709, 450);
+ 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 = "FormShops";
+ this.Text = "FormShops";
+ this.Load += new System.EventHandler(this.FormShops_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/FormShops.cs b/Pizzeria/Pizzeria/FormShops.cs
new file mode 100644
index 0000000..2c53019
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormShops.cs
@@ -0,0 +1,101 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+
+namespace Pizzeria
+{
+ public partial class FormShops : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IShopLogic _logic;
+ public FormShops(ILogger logger, IShopLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void FormShops_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["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["ShopPizzas"].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(FormShop));
+ if (service is FormShop 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(FormShop));
+ if (service is FormShop 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 ShopBindingModel
+ {
+ 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/FormShops.resx b/Pizzeria/Pizzeria/FormShops.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormShops.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/Program.cs b/Pizzeria/Pizzeria/Program.cs
index 6905fbb..9b368cb 100644
--- a/Pizzeria/Pizzeria/Program.cs
+++ b/Pizzeria/Pizzeria/Program.cs
@@ -37,9 +37,11 @@ namespace Pizzeria
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -47,6 +49,9 @@ namespace Pizzeria
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
services.AddTransient();
}
}
diff --git a/Pizzeria/PizzeriaBusinessLogic/ShopLogic.cs b/Pizzeria/PizzeriaBusinessLogic/ShopLogic.cs
new file mode 100644
index 0000000..33acfb6
--- /dev/null
+++ b/Pizzeria/PizzeriaBusinessLogic/ShopLogic.cs
@@ -0,0 +1,141 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.StoragesContracts;
+using PizzeriaContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+using PizzeriaDataModels;
+
+namespace PizzeriaBusinessLogic
+{
+ public class ShopLogic : IShopLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IShopStorage _shopStorage;
+ public ShopLogic(ILogger logger, IShopStorage shopStorage)
+ {
+ _logger = logger;
+ _shopStorage = shopStorage;
+ }
+ public List? ReadList(ShopSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. ShopName:{ShopName}. Id:{ Id}", model?.ShopName, model?.Id);
+ var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+ public ShopViewModel? ReadElement(ShopSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. ShopName:{ShopName}. Id:{ Id}", model.ShopName, model.Id);
+ var element = _shopStorage.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(ShopBindingModel model)
+ {
+ CheckModel(model);
+ if (_shopStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Update(ShopBindingModel model)
+ {
+ CheckModel(model);
+ if (_shopStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Delete(ShopBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_shopStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+ private void CheckModel(ShopBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.ShopName))
+ {
+ throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
+ }
+ if (string.IsNullOrEmpty(model.Addres))
+ {
+ throw new ArgumentNullException("Нет адреса магазина", nameof(model.ShopName));
+ }
+ _logger.LogInformation("Shop. ShopName:{ShopName}. Addres:{Addres}. Id: {Id}", model.ShopName, model.Addres, model.Id);
+ var element = _shopStorage.GetElement(new ShopSearchModel
+ {
+ ShopName = model.ShopName
+ });
+
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Магазин с таким названием уже есть");
+ }
+ }
+
+ public bool AddPizza(ShopSearchModel shop, IPizzaModel pizza, int count)
+ {
+ if (shop == null)
+ {
+ throw new ArgumentNullException(nameof(shop));
+ }
+ if (count <= 0)
+ {
+ throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count));
+ }
+
+ ShopViewModel model = _shopStorage.GetElement(shop);
+
+ if(model.ShopPizzas.TryGetValue(pizza.Id, out var pair))
+ {
+ model.ShopPizzas[pizza.Id] = (pair.Item1, pair.Item2 + count);
+ } else
+ {
+ model.ShopPizzas.Add(pizza.Id, (pizza, count));
+ }
+
+ _shopStorage.Update(new()
+ {
+ Id = model.Id,
+ ShopName = model.ShopName,
+ Addres = model.Addres,
+ ShopPizzas = model.ShopPizzas,
+ });
+
+ return true;
+ }
+ }
+}
diff --git a/Pizzeria/PizzeriaContracts/BindingModels/ShopBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/ShopBindingModel.cs
new file mode 100644
index 0000000..621cafe
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/BindingModels/ShopBindingModel.cs
@@ -0,0 +1,20 @@
+using PizzeriaDataModels;
+
+namespace PizzeriaContracts.BindingModels
+{
+ public class ShopBindingModel : IShopModel
+ {
+ public int Id { get; set; }
+ public string ShopName { get; set; } = String.Empty;
+
+ public string Addres { get; set; } = String.Empty;
+
+ public DateTime OpenTime { get; set; }
+
+ public Dictionary ShopPizzas
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IShopLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IShopLogic.cs
new file mode 100644
index 0000000..d26bdf8
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IShopLogic.cs
@@ -0,0 +1,17 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.ViewModels;
+using PizzeriaDataModels;
+
+namespace PizzeriaContracts.BusinessLogicsContracts
+{
+ public interface IShopLogic
+ {
+ List? ReadList(ShopSearchModel? model);
+ ShopViewModel? ReadElement(ShopSearchModel model);
+ bool AddPizza(ShopSearchModel shop, IPizzaModel pizza, int count);
+ bool Create(ShopBindingModel model);
+ bool Update(ShopBindingModel model);
+ bool Delete(ShopBindingModel model);
+ }
+}
diff --git a/Pizzeria/PizzeriaContracts/SearchModels/ShopSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/ShopSearchModel.cs
new file mode 100644
index 0000000..b8f9dea
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/SearchModels/ShopSearchModel.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 ShopSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ShopName { get; set; }
+ }
+}
diff --git a/Pizzeria/PizzeriaContracts/StoragesContracts/IShopStorage.cs b/Pizzeria/PizzeriaContracts/StoragesContracts/IShopStorage.cs
new file mode 100644
index 0000000..99cdc9c
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/StoragesContracts/IShopStorage.cs
@@ -0,0 +1,16 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.ViewModels;
+
+namespace PizzeriaContracts.StoragesContracts
+{
+ public interface IShopStorage
+ {
+ List GetFullList();
+ List GetFilteredList(ShopSearchModel model);
+ ShopViewModel? GetElement(ShopSearchModel model);
+ ShopViewModel? Insert(ShopBindingModel model);
+ ShopViewModel? Update(ShopBindingModel model);
+ ShopViewModel? Delete(ShopBindingModel model);
+ }
+}
diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ShopViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ShopViewModel.cs
new file mode 100644
index 0000000..ef7b3e1
--- /dev/null
+++ b/Pizzeria/PizzeriaContracts/ViewModels/ShopViewModel.cs
@@ -0,0 +1,23 @@
+using System.ComponentModel;
+using PizzeriaDataModels;
+
+namespace PizzeriaContracts.ViewModels
+{
+ public class ShopViewModel : IShopModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название магазина")]
+ public string ShopName { get; set; } = string.Empty;
+
+ [DisplayName("Адрес")]
+ public string Addres { get; set; } = string.Empty;
+ [DisplayName("Дата открытия")]
+ public DateTime OpenTime { get; set; }
+
+ public Dictionary ShopPizzas
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/Pizzeria/PizzeriaDataModels/Models/IShopModel.cs b/Pizzeria/PizzeriaDataModels/Models/IShopModel.cs
new file mode 100644
index 0000000..7760585
--- /dev/null
+++ b/Pizzeria/PizzeriaDataModels/Models/IShopModel.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PizzeriaDataModels
+{
+ public interface IShopModel : IId
+ {
+ string ShopName { get; }
+ string Addres { get; }
+ DateTime OpenTime { get; }
+
+ Dictionary ShopPizzas { get; }
+ }
+}
diff --git a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs
index 24824be..f6c9a38 100644
--- a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs
+++ b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs
@@ -9,11 +9,13 @@ namespace PizzeriaListImplement
public List Components { get; set; }
public List Orders { get; set; }
public List Pizzas { get; set; }
+ public List Shops { get; set; }
private DataListSingleton()
{
Components = new List();
Orders = new List();
Pizzas = new List();
+ Shops = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/Pizzeria/PizzeriaListImplement/Implements/ShopStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/ShopStorage.cs
new file mode 100644
index 0000000..137a7af
--- /dev/null
+++ b/Pizzeria/PizzeriaListImplement/Implements/ShopStorage.cs
@@ -0,0 +1,116 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.SearchModels;
+using PizzeriaContracts.StoragesContracts;
+using PizzeriaContracts.ViewModels;
+using PizzeriaListImplement.Models;
+
+namespace PizzeriaListImplement.Implements
+{
+ public class ShopStorage : IShopStorage
+ {
+ private readonly DataListSingleton _source;
+
+ public ShopStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+
+ foreach (var shop in _source.Shops)
+ {
+ result.Add(shop.GetViewModel);
+ }
+
+ return result;
+ }
+ public List GetFilteredList(ShopSearchModel model)
+ {
+ var result = new List();
+
+ if (string.IsNullOrEmpty(model.ShopName))
+ {
+ return result;
+ }
+
+ foreach (var shop in _source.Shops)
+ {
+ if (shop.ShopName.Contains(model.ShopName))
+ {
+ result.Add(shop.GetViewModel);
+ }
+ }
+
+ return result;
+ }
+ public ShopViewModel? GetElement(ShopSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+
+ foreach (var shop in _source.Shops)
+ {
+ if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (model.Id.HasValue && shop.Id == model.Id))
+ {
+ return shop.GetViewModel;
+ }
+ }
+
+ return null;
+ }
+ public ShopViewModel? Insert(ShopBindingModel model)
+ {
+ model.Id = 1;
+
+ foreach (var shop in _source.Shops)
+ {
+ if (model.Id <= shop.Id)
+ {
+ model.Id = shop.Id + 1;
+ }
+ }
+
+ var newShop = Shop.Create(model);
+
+ if (newShop == null)
+ {
+ return null;
+ }
+
+ _source.Shops.Add(newShop);
+
+ return newShop.GetViewModel;
+ }
+ public ShopViewModel? Update(ShopBindingModel model)
+ {
+ foreach (var shop in _source.Shops)
+ {
+ if (shop.Id == model.Id)
+ {
+ shop.Update(model);
+ return shop.GetViewModel;
+ }
+ }
+
+ return null;
+ }
+ public ShopViewModel? Delete(ShopBindingModel model)
+ {
+ for (int i = 0; i < _source.Shops.Count; ++i)
+ {
+ if (_source.Shops[i].Id == model.Id)
+ {
+ var element = _source.Shops[i];
+ _source.Shops.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/Pizzeria/PizzeriaListImplement/Models/Shop.cs b/Pizzeria/PizzeriaListImplement/Models/Shop.cs
new file mode 100644
index 0000000..1195166
--- /dev/null
+++ b/Pizzeria/PizzeriaListImplement/Models/Shop.cs
@@ -0,0 +1,56 @@
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.ViewModels;
+using PizzeriaDataModels;
+
+namespace PizzeriaListImplement.Models
+{
+ public class Shop : IShopModel
+ {
+ public int Id { get; private set; }
+ public string ShopName { get; private set; } = string.Empty;
+ public string Addres { get; private set; } = string.Empty;
+ public DateTime OpenTime { get; private set; } = DateTime.Now;
+
+ public Dictionary ShopPizzas
+ {
+ get;
+ private set;
+ } = new Dictionary();
+ public static Shop? Create(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Shop()
+ {
+
+ Id = model.Id,
+ ShopName = model.ShopName,
+ Addres = model.Addres,
+ OpenTime = model.OpenTime,
+ ShopPizzas = model.ShopPizzas
+ };
+ }
+ public void Update(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ShopName = model.ShopName;
+ Addres = model.Addres;
+ OpenTime = OpenTime;
+ ShopPizzas = model.ShopPizzas;
+ }
+ public ShopViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ShopName = ShopName,
+ Addres = Addres,
+ OpenTime = OpenTime,
+ ShopPizzas = ShopPizzas
+ };
+ }
+}
+