diff --git a/SushiBar/SushiBar.sln b/SushiBar/SushiBar.sln
index 6d47062..f8e68e4 100644
--- a/SushiBar/SushiBar.sln
+++ b/SushiBar/SushiBar.sln
@@ -5,13 +5,15 @@ VisualStudioVersion = 17.3.32819.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBar", "SushiBar\SushiBar.csproj", "{DB81A759-B157-477C-9281-EE358968519D}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarDataModels", "SushiBarModels\SushiBarDataModels.csproj", "{CFB2D9F9-EA44-4E61-B6BE-5A2AA3C6AF07}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarDataModels", "SushiBarModels\SushiBarDataModels.csproj", "{CFB2D9F9-EA44-4E61-B6BE-5A2AA3C6AF07}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{1185D549-D227-4BE3-8EAD-D294029BCA5D}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{1185D549-D227-4BE3-8EAD-D294029BCA5D}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{A273021E-72E7-4C23-927C-A3E4851BD8D1}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{A273021E-72E7-4C23-927C-A3E4851BD8D1}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushibarListImplement", "SushibarListImplement\SushibarListImplement.csproj", "{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushibarListImplement", "SushibarListImplement\SushibarListImplement.csproj", "{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarFileImplement", "SushiBarFileImplement\SushiBarFileImplement.csproj", "{E55FF400-876B-4E35-8536-E099241195B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -39,6 +41,10 @@ Global
{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E55FF400-876B-4E35-8536-E099241195B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E55FF400-876B-4E35-8536-E099241195B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E55FF400-876B-4E35-8536-E099241195B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E55FF400-876B-4E35-8536-E099241195B8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs
index 4a260c2..aa69afe 100644
--- a/SushiBar/SushiBar/FormMain.Designer.cs
+++ b/SushiBar/SushiBar/FormMain.Designer.cs
@@ -40,6 +40,7 @@
this.buttonIssue = new System.Windows.Forms.Button();
this.buttonReload = new System.Windows.Forms.Button();
this.buttonReplenishment = new System.Windows.Forms.Button();
+ this.ButtonSell = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@@ -76,21 +77,21 @@
// componentsToolStripMenuItem
//
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
- this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.componentsToolStripMenuItem.Size = new System.Drawing.Size(143, 22);
this.componentsToolStripMenuItem.Text = "Components";
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
// sushiToolStripMenuItem
//
this.sushiToolStripMenuItem.Name = "sushiToolStripMenuItem";
- this.sushiToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.sushiToolStripMenuItem.Size = new System.Drawing.Size(143, 22);
this.sushiToolStripMenuItem.Text = "Sushi";
this.sushiToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click);
//
// storeToolStripMenuItem
//
this.storeToolStripMenuItem.Name = "storeToolStripMenuItem";
- this.storeToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.storeToolStripMenuItem.Size = new System.Drawing.Size(143, 22);
this.storeToolStripMenuItem.Text = "Store";
this.storeToolStripMenuItem.Click += new System.EventHandler(this.StoreToolStripMenuItem_Click);
//
@@ -154,11 +155,22 @@
this.buttonReplenishment.UseVisualStyleBackColor = true;
this.buttonReplenishment.Click += new System.EventHandler(this.ButtonReplenishment_Click);
//
+ // ButtonSell
+ //
+ this.ButtonSell.Location = new System.Drawing.Point(674, 386);
+ this.ButtonSell.Name = "ButtonSell";
+ this.ButtonSell.Size = new System.Drawing.Size(114, 23);
+ this.ButtonSell.TabIndex = 8;
+ this.ButtonSell.Text = "Sell";
+ this.ButtonSell.UseVisualStyleBackColor = true;
+ this.ButtonSell.Click += new System.EventHandler(this.ButtonSell_Click);
+ //
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.ButtonSell);
this.Controls.Add(this.buttonReplenishment);
this.Controls.Add(this.buttonReload);
this.Controls.Add(this.buttonIssue);
@@ -193,5 +205,6 @@
private ToolStripMenuItem sushiToolStripMenuItem;
private ToolStripMenuItem storeToolStripMenuItem;
private Button buttonReplenishment;
+ private Button ButtonSell;
}
}
\ No newline at end of file
diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs
index 2ca647b..89dd0e9 100644
--- a/SushiBar/SushiBar/FormMain.cs
+++ b/SushiBar/SushiBar/FormMain.cs
@@ -190,5 +190,15 @@ namespace SushiBar
form.ShowDialog();
}
}
+
+ private void ButtonSell_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormStoreSell));
+
+ if (service is FormStoreSell form)
+ {
+ form.ShowDialog();
+ }
+ }
}
}
diff --git a/SushiBar/SushiBar/FormStore.Designer.cs b/SushiBar/SushiBar/FormStore.Designer.cs
index 9d9db1d..1817a92 100644
--- a/SushiBar/SushiBar/FormStore.Designer.cs
+++ b/SushiBar/SushiBar/FormStore.Designer.cs
@@ -29,6 +29,9 @@
private void InitializeComponent()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.SushiName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Cost = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.comboBoxName = new System.Windows.Forms.ComboBox();
this.textBoxAddress = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
@@ -36,10 +39,10 @@
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
- this.SushiName = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Cost = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.labelMaxSushi = new System.Windows.Forms.Label();
+ this.maxSushi = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.maxSushi)).BeginInit();
this.SuspendLayout();
//
// dataGridView
@@ -55,6 +58,22 @@
this.dataGridView.Size = new System.Drawing.Size(598, 426);
this.dataGridView.TabIndex = 0;
//
+ // SushiName
+ //
+ this.SushiName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.SushiName.HeaderText = "Sushi";
+ this.SushiName.Name = "SushiName";
+ //
+ // Cost
+ //
+ this.Cost.HeaderText = "Cost";
+ this.Cost.Name = "Cost";
+ //
+ // Count
+ //
+ this.Count.HeaderText = "Count";
+ this.Count.Name = "Count";
+ //
// comboBoxName
//
this.comboBoxName.FormattingEnabled = true;
@@ -116,27 +135,29 @@
this.dateTimePicker.Size = new System.Drawing.Size(172, 23);
this.dateTimePicker.TabIndex = 8;
//
- // SushiName
+ // labelMaxSushi
//
- this.SushiName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
- this.SushiName.HeaderText = "Sushi";
- this.SushiName.Name = "SushiName";
+ this.labelMaxSushi.AutoSize = true;
+ this.labelMaxSushi.Location = new System.Drawing.Point(616, 126);
+ this.labelMaxSushi.Name = "labelMaxSushi";
+ this.labelMaxSushi.Size = new System.Drawing.Size(61, 15);
+ this.labelMaxSushi.TabIndex = 9;
+ this.labelMaxSushi.Text = "Max Suhsi";
//
- // Cost
+ // maxSushi
//
- this.Cost.HeaderText = "Cost";
- this.Cost.Name = "Cost";
- //
- // Count
- //
- this.Count.HeaderText = "Count";
- this.Count.Name = "Count";
+ this.maxSushi.Location = new System.Drawing.Point(616, 144);
+ this.maxSushi.Name = "maxSushi";
+ this.maxSushi.Size = new System.Drawing.Size(172, 23);
+ this.maxSushi.TabIndex = 10;
//
// FormStore
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.maxSushi);
+ this.Controls.Add(this.labelMaxSushi);
this.Controls.Add(this.dateTimePicker);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
@@ -149,6 +170,7 @@
this.Text = "FormStore";
this.Load += new System.EventHandler(this.FormStore_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.maxSushi)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@@ -167,5 +189,7 @@
private DataGridViewTextBoxColumn SushiName;
private DataGridViewTextBoxColumn Cost;
private DataGridViewTextBoxColumn Count;
+ private Label labelMaxSushi;
+ private NumericUpDown maxSushi;
}
}
\ No newline at end of file
diff --git a/SushiBar/SushiBar/FormStore.cs b/SushiBar/SushiBar/FormStore.cs
index 035995c..4aae052 100644
--- a/SushiBar/SushiBar/FormStore.cs
+++ b/SushiBar/SushiBar/FormStore.cs
@@ -35,12 +35,13 @@ namespace SushiBar
if (model != null)
{
comboBoxName.Text = model.StoreName;
- textBoxAddress.Text = model.StoreAdress;
+ textBoxAddress.Text = model.StoreAddress;
dateTimePicker.Text = Convert.ToString(model.OpeningDate);
+ maxSushi.Value = model.maxSushi;
dataGridView.Rows.Clear();
foreach (var el in model.Sushis.Values)
{
- dataGridView.Rows.Add(new object[] { el.Item1.SushiName, el.Item1.Price, el.Item2 });
+ dataGridView.Rows.Add(el.Item1.SushiName, el.Item1.Price, el.Item2);
}
}
_logger.LogInformation("Load stores");
@@ -52,7 +53,7 @@ namespace SushiBar
}
}
- private IStoreModel? GetStore(int id)
+ private IStoreModel? GetStore(int Id)
{
if (_listStores == null)
{
@@ -60,7 +61,7 @@ namespace SushiBar
}
foreach (var elem in _listStores)
{
- if (elem.Id == id)
+ if (elem.Id == Id)
{
return elem;
}
@@ -90,15 +91,16 @@ namespace SushiBar
StoreBindingModel model = new()
{
StoreName = comboBoxName.Text,
- StoreAdress = textBoxAddress.Text,
- OpeningDate = dateTime
+ StoreAddress = textBoxAddress.Text,
+ OpeningDate = dateTime,
+ maxSushi = (int)maxSushi.Value
};
- var search_model = GetStore(id);
- bool operationResult = false;
+ var searchModel = GetStore(id);
+ bool operationResult;
- if (search_model != null)
+ if (searchModel != null)
{
- model.Id = search_model.Id;
+ model.Id = searchModel.Id;
operationResult = _logic.Update(model);
}
else
diff --git a/SushiBar/SushiBar/FormStore.resx b/SushiBar/SushiBar/FormStore.resx
index 769b272..538d7b3 100644
--- a/SushiBar/SushiBar/FormStore.resx
+++ b/SushiBar/SushiBar/FormStore.resx
@@ -66,4 +66,13 @@
True
+
+ True
+
+
+ True
+
+
+ True
+
\ No newline at end of file
diff --git a/SushiBar/SushiBar/FormStoreReplenishment.cs b/SushiBar/SushiBar/FormStoreReplenishment.cs
index 36c2b40..0200c4b 100644
--- a/SushiBar/SushiBar/FormStoreReplenishment.cs
+++ b/SushiBar/SushiBar/FormStoreReplenishment.cs
@@ -64,7 +64,7 @@ namespace SushiBar
throw new Exception("Sushi is not found. Additional info below.");
}
- var resultOperation = _storeLogic.AddPackage(
+ var resultOperation = _storeLogic.SupplySushi(
model: new() { Id = (int)comboBoxStore.SelectedValue },
sushi: sushi,
quantity: Convert.ToInt32(textBoxCount.Text)
diff --git a/SushiBar/SushiBar/FormStoreSell.Designer.cs b/SushiBar/SushiBar/FormStoreSell.Designer.cs
new file mode 100644
index 0000000..5230d39
--- /dev/null
+++ b/SushiBar/SushiBar/FormStoreSell.Designer.cs
@@ -0,0 +1,110 @@
+namespace SushiBar
+{
+ partial class FormStoreSell
+ {
+ ///
+ /// 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.SushiNames = new System.Windows.Forms.ComboBox();
+ this.labelSushi = new System.Windows.Forms.Label();
+ this.Count = new System.Windows.Forms.NumericUpDown();
+ this.buttonSell = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.Count)).BeginInit();
+ this.SuspendLayout();
+ //
+ // SushiNames
+ //
+ this.SushiNames.FormattingEnabled = true;
+ this.SushiNames.Location = new System.Drawing.Point(12, 27);
+ this.SushiNames.Name = "SushiNames";
+ this.SushiNames.Size = new System.Drawing.Size(172, 23);
+ this.SushiNames.TabIndex = 0;
+ //
+ // labelSushi
+ //
+ this.labelSushi.AutoSize = true;
+ this.labelSushi.Location = new System.Drawing.Point(12, 9);
+ this.labelSushi.Name = "labelSushi";
+ this.labelSushi.Size = new System.Drawing.Size(35, 15);
+ this.labelSushi.TabIndex = 1;
+ this.labelSushi.Text = "Sushi";
+ //
+ // Count
+ //
+ this.Count.Location = new System.Drawing.Point(12, 56);
+ this.Count.Name = "Count";
+ this.Count.Size = new System.Drawing.Size(172, 23);
+ this.Count.TabIndex = 2;
+ //
+ // buttonSell
+ //
+ this.buttonSell.Location = new System.Drawing.Point(12, 85);
+ this.buttonSell.Name = "buttonSell";
+ this.buttonSell.Size = new System.Drawing.Size(82, 23);
+ this.buttonSell.TabIndex = 3;
+ this.buttonSell.Text = "Sell";
+ this.buttonSell.UseVisualStyleBackColor = true;
+ this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(100, 85);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(84, 23);
+ this.buttonCancel.TabIndex = 4;
+ this.buttonCancel.Text = "Cancel";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FormStoreSell
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(198, 118);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSell);
+ this.Controls.Add(this.Count);
+ this.Controls.Add(this.labelSushi);
+ this.Controls.Add(this.SushiNames);
+ this.Name = "FormStoreSell";
+ this.Text = "FormStoreSell";
+ this.Load += new System.EventHandler(this.FormStoreSell_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.Count)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private ComboBox SushiNames;
+ private Label labelSushi;
+ private NumericUpDown Count;
+ private Button buttonSell;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/SushiBar/SushiBar/FormStoreSell.cs b/SushiBar/SushiBar/FormStoreSell.cs
new file mode 100644
index 0000000..ae367f8
--- /dev/null
+++ b/SushiBar/SushiBar/FormStoreSell.cs
@@ -0,0 +1,84 @@
+using Microsoft.Extensions.Logging;
+using SushiBarContracts.BindingModels;
+using SushiBarContracts.BusinessLogicsContracts;
+
+namespace SushiBar
+{
+ public partial class FormStoreSell : Form
+ {
+ private readonly ILogger _logger;
+ private readonly ISushiLogic _logicSushi;
+ private readonly IStoreLogic _logicStore;
+
+ public FormStoreSell(ILogger logger, ISushiLogic sushiLogic, IStoreLogic storeLogic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicSushi = sushiLogic;
+ _logicStore = storeLogic;
+ }
+
+ private void ButtonSell_Click(object sender, EventArgs e)
+ {
+ if (Count.Value == 0)
+ {
+ MessageBox.Show("Count must be more then zero!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (SushiNames.SelectedValue == null)
+ {
+ MessageBox.Show("Select sushi", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Create sell");
+ try
+ {
+ var operationResult = _logicStore.SellSushi(
+ new SushiBindingModel()
+ {
+ Id = Convert.ToInt32(SushiNames.SelectedValue)
+ },
+ (int)Count.Value
+ );
+ if (!operationResult)
+ {
+ throw new Exception("Error on create sell. Additional info below");
+ }
+ MessageBox.Show("Complete create", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error on create");
+ MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+
+ private void FormStoreSell_Load(object sender, EventArgs e)
+ {
+ _logger.LogInformation("Load sushi to sell");
+ try
+ {
+ var list = _logicSushi.ReadList(null);
+ if (list == null) return;
+ SushiNames.DisplayMember = "SushiName";
+ SushiNames.ValueMember = "Id";
+ SushiNames.DataSource = list;
+ SushiNames.SelectedItem = null;
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error on loading");
+ MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+}
diff --git a/SushiBar/SushiBar/FormStoreSell.resx b/SushiBar/SushiBar/FormStoreSell.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/SushiBar/SushiBar/FormStoreSell.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/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs
index 845eae3..b89e7d7 100644
--- a/SushiBar/SushiBar/Program.cs
+++ b/SushiBar/SushiBar/Program.cs
@@ -4,7 +4,7 @@ using NLog.Extensions.Logging;
using SushiBarBusinessLogic.BusinessLogics;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.StoragesContracts;
-using SushibarListImplement.Implements;
+using SushiBarFileImplement.Implements;
namespace SushiBar
{
@@ -47,6 +47,7 @@ namespace SushiBar
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/SushiBar/SushiBar/SushiBar.csproj b/SushiBar/SushiBar/SushiBar.csproj
index 52a0900..97cb249 100644
--- a/SushiBar/SushiBar/SushiBar.csproj
+++ b/SushiBar/SushiBar/SushiBar.csproj
@@ -15,6 +15,7 @@
+
diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs
index 3f1ba18..57a3e43 100644
--- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs
+++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -12,11 +12,15 @@ namespace SushiBarBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
+ private readonly IStoreLogic _storeLogic;
+ private readonly ISushiStorage _sushiStorage;
- public OrderLogic(ILogger logger, IOrderStorage orderStorage)
+ public OrderLogic(ILogger logger, IOrderStorage orderStorage, IStoreLogic storeLogic, ISushiStorage sushiStorage)
{
_logger = logger;
_orderStorage = orderStorage;
+ _storeLogic = storeLogic;
+ _sushiStorage = sushiStorage;
}
public bool CreateOrder(OrderBindingModel model)
@@ -78,12 +82,29 @@ namespace SushiBarBusinessLogic.BusinessLogics
_logger.LogWarning("Status update operation failed");
return false;
}
+
+ if (status == OrderStatus.Ready)
+ {
+ var sushi = _sushiStorage.GetElement(new() { Id = model.SushiId });
+ if (sushi == null)
+ {
+ _logger.LogWarning("Status update to " + status + " operation failed. Document not found.");
+ return false;
+ }
+ if (!_storeLogic.CheckToSupply(sushi, model.Count))
+ {
+ _logger.LogWarning("Status update to " + status + " operation failed. Shop supply error.");
+ return false;
+ }
+ }
+
model.Status = status;
model.DateImplement = order?.DateImplement;
- if (model.Status == OrderStatus.Ready)
+ if (model.Status == OrderStatus.Issued)
{
model.DateImplement = DateTime.Now;
}
+
if (_orderStorage.Update(model) == null)
{
model.Status--;
diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/StoreLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/StoreLogic.cs
index 9bcc52c..75113b6 100644
--- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/StoreLogic.cs
+++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/StoreLogic.cs
@@ -57,10 +57,11 @@ namespace SushiBarBusinessLogic.BusinessLogics
_storeStorage.Update(new()
{
Id = element.Id,
- StoreAdress = element.StoreAdress,
+ StoreAddress = element.StoreAddress,
StoreName = element.StoreName,
OpeningDate = element.OpeningDate,
- Sushis = element.Sushis
+ Sushis = element.Sushis,
+ maxSushi = element.maxSushi
});
return true;
}
@@ -93,6 +94,116 @@ namespace SushiBarBusinessLogic.BusinessLogics
return true;
}
+ public bool SupplySushi(StoreSearchModel model, ISushiModel sushi, int quantity)
+ {
+ if (model == null || sushi == null || quantity <= 0)
+ {
+ throw new ArgumentNullException();
+ }
+
+ var store = _storeStorage.GetElement(model);
+ if (store == null)
+ {
+ _logger.LogWarning("Required store element not found in storage");
+ return false;
+ }
+
+ _logger.LogInformation("Shop element found. ID: {0}, Name: {1}", store.Id, store.StoreName);
+ int countSushi = store.Sushis.Sum(s => s.Value.Item2);
+ if (store.maxSushi - countSushi >= quantity)
+ {
+ if (store.Sushis.TryGetValue(sushi.Id, out var pair))
+ {
+ store.Sushis[sushi.Id] = (sushi, quantity + pair.Item2);
+ _logger.LogInformation("AddPackageInStore. Has been added {quantity} {package} in {StoreName}", quantity, sushi.SushiName, store.StoreName);
+ }
+ else
+ {
+ store.Sushis[sushi.Id] = (sushi, quantity);
+ _logger.LogInformation("AddPastryInShop. Has been added {quantity} new Package {package} in {StoreName}", quantity, sushi.SushiName, store.StoreName);
+ }
+
+ _storeStorage.Update(new()
+ {
+ Id = store.Id,
+ StoreAddress = store.StoreAddress,
+ StoreName = store.StoreName,
+ OpeningDate = store.OpeningDate,
+ Sushis = store.Sushis,
+ maxSushi = store.maxSushi
+ });
+ }
+ else
+ {
+ _logger.LogWarning("Required shop is overflowed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool CheckToSupply(ISushiModel sushi, int quantity)
+ {
+ if (quantity <= 0)
+ {
+ _logger.LogWarning("Check then supply operation error. Document count < 0.");
+ return false;
+ }
+
+ int countSushi = 0;
+ foreach (var store in _storeStorage.GetFullList())
+ {
+ countSushi += store.maxSushi;
+ countSushi = store.Sushis.Values.Aggregate(countSushi, (current, valueTuple) => current - valueTuple.Item2);
+ }
+
+ if (countSushi - quantity < 0)
+ {
+ _logger.LogWarning("Check then supply operation error. There's no place for new docs in stores.");
+ return false;
+ }
+
+ foreach (var store in _storeStorage.GetFullList())
+ {
+ countSushi = store.Sushis.Values.Aggregate(store.maxSushi, (current, valueTuple) => current - valueTuple.Item2);
+ if (countSushi == 0)
+ {
+ continue;
+ }
+
+ if (countSushi - quantity >= 0)
+ {
+ if (SupplySushi(new() { Id = store.Id }, sushi, countSushi))
+ countSushi = 0;
+ else
+ {
+ _logger.LogWarning("Supply error");
+ return false;
+ }
+ }
+ if (countSushi - quantity < 0)
+ {
+ if (SupplySushi(new StoreSearchModel { Id = store.Id }, sushi, countSushi))
+ quantity -= countSushi;
+ else
+ {
+ _logger.LogWarning("Supply error");
+ return false;
+ }
+ }
+ if (countSushi <= 0)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public bool SellSushi(ISushiModel model, int quantity)
+ {
+ return _storeStorage.SellSushi(model, quantity);
+ }
+
public StoreViewModel? ReadElement(StoreSearchModel model)
{
if (model == null)
@@ -117,7 +228,7 @@ namespace SushiBarBusinessLogic.BusinessLogics
{
_logger.LogInformation("ReadList. StoreName:{StoreName}.Id:{ Id} ", model?.StoreName, model?.Id);
- var list = (model == null) ? _storeStorage.GetFullList() : _storeStorage.GetFilteredList(model);
+ var list = model == null ? _storeStorage.GetFullList() : _storeStorage.GetFilteredList(model);
if (list == null)
{
@@ -163,7 +274,7 @@ namespace SushiBarBusinessLogic.BusinessLogics
throw new ArgumentNullException("Store name is empty!", nameof(model.StoreName));
}
- _logger.LogInformation("Store. StoreName:{0}.StoreAdress:{1}. Id: {2}", model.StoreName, model.StoreAdress, model.Id);
+ _logger.LogInformation("Store. StoreName:{0}.StoreAdress:{1}. Id: {2}", model.StoreName, model.StoreAddress, model.Id);
var element = _storeStorage.GetElement(new StoreSearchModel
{
StoreName = model.StoreName
diff --git a/SushiBar/SushiBarContracts/BindingModels/StoreBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/StoreBindingModel.cs
index 90814f6..5ad457e 100644
--- a/SushiBar/SushiBarContracts/BindingModels/StoreBindingModel.cs
+++ b/SushiBar/SushiBarContracts/BindingModels/StoreBindingModel.cs
@@ -2,12 +2,13 @@
namespace SushiBarContracts.BindingModels
{
- public class StoreBindingModel
+ public class StoreBindingModel : IStoreModel
{
public string StoreName { get; set; } = string.Empty;
- public string StoreAdress { get; set; } = string.Empty;
+ public string StoreAddress { get; set; } = string.Empty;
public DateTime OpeningDate { get; set; } = DateTime.Now;
public Dictionary Sushis { get; set; } = new();
+ public int maxSushi { get; set; }
public int Id { get; set; }
}
}
diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IStoreLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IStoreLogic.cs
index 9592818..ee423a2 100644
--- a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IStoreLogic.cs
+++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IStoreLogic.cs
@@ -12,6 +12,8 @@ namespace SushiBarContracts.BusinessLogicsContracts
bool Create(StoreBindingModel model);
bool Update(StoreBindingModel model);
bool Delete(StoreBindingModel model);
- bool AddPackage(StoreSearchModel model, ISushiModel sushi, int quantity);
+ bool SupplySushi(StoreSearchModel model, ISushiModel sushi, int quantity);
+ bool CheckToSupply(ISushiModel sushi, int quantity);
+ bool SellSushi(ISushiModel model, int quantity);
}
}
diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IStoreStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IStoreStorage.cs
index 1985f97..33b3c1c 100644
--- a/SushiBar/SushiBarContracts/StoragesContracts/IStoreStorage.cs
+++ b/SushiBar/SushiBarContracts/StoragesContracts/IStoreStorage.cs
@@ -1,6 +1,7 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
+using SushiBarDataModels.Models;
namespace SushiBarContracts.StoragesContracts
{
@@ -12,5 +13,6 @@ namespace SushiBarContracts.StoragesContracts
StoreViewModel? Insert(StoreBindingModel model);
StoreViewModel? Update(StoreBindingModel model);
StoreViewModel? Delete(StoreBindingModel model);
+ bool SellSushi(ISushiModel model, int quantity);
}
}
diff --git a/SushiBar/SushiBarContracts/ViewModels/StoreViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/StoreViewModel.cs
index f4e7543..96f0705 100644
--- a/SushiBar/SushiBarContracts/ViewModels/StoreViewModel.cs
+++ b/SushiBar/SushiBarContracts/ViewModels/StoreViewModel.cs
@@ -5,14 +5,15 @@ namespace SushiBarContracts.ViewModels
{
public class StoreViewModel : IStoreModel
{
- public Dictionary Sushis { get; set; } = new();
- public int Id { get; set; }
+ public Dictionary Sushis { get; init; } = new();
+ public int maxSushi { get; set; }
+ public int Id { get; init; }
[DisplayName("Name store")]
- public string StoreName { get; set; } = string.Empty;
- [DisplayName("Adress store")]
- public string StoreAdress { get; set; } = string.Empty;
+ public string StoreName { get; init; } = string.Empty;
+ [DisplayName("Address store")]
+ public string StoreAddress { get; init; } = string.Empty;
[DisplayName("Date opening")]
- public DateTime OpeningDate { get; set; } = DateTime.Now;
+ public DateTime OpeningDate { get; init; } = DateTime.Now;
}
}
diff --git a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs
new file mode 100644
index 0000000..7870eff
--- /dev/null
+++ b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs
@@ -0,0 +1,46 @@
+using SushiBarFileImplement.Models;
+using System.Xml.Linq;
+
+namespace SushiBarFileImplement
+{
+ public class DataFileSingleton
+ {
+ private static DataFileSingleton? instance;
+ private readonly string ComponentFileName = "Component.xml";
+ private readonly string OrderFileName = "Order.xml";
+ private readonly string SushiFileName = "Sushi.xml";
+ private readonly string StoreFileName = "Store.xml";
+ public List Components { get; }
+ public List Orders { get; }
+ public List Sushis { get; }
+ public List Stores { get; }
+ public static DataFileSingleton GetInstance()
+ {
+ instance ??= new DataFileSingleton();
+ return instance;
+ }
+ public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
+ public void SaveSushis() => SaveData(Sushis, SushiFileName, "Sushis", x => x.GetXElement);
+ public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
+ public void SaveStores() => SaveData(Stores, StoreFileName, "Store", x => x.GetXElement);
+
+ private DataFileSingleton()
+ {
+ Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
+ Sushis = LoadData(SushiFileName, "Sushi", x => Sushi.Create(x)!)!;
+ Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
+ Stores = LoadData(StoreFileName, "Store", x => Store.Create(x)!)!;
+ }
+ private static List? LoadData(string filename, string xmlNodeName, Func selectFunction)
+ {
+ return File.Exists(filename) ? XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList() : new List();
+ }
+ private static void SaveData(IReadOnlyCollection data, string filename, string xmlNodeName, Func selectFunction)
+ {
+ if (data != null)
+ {
+ new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
+ }
+ }
+ }
+}
diff --git a/SushiBar/SushiBarFileImplement/Implements/ComponentStorage.cs b/SushiBar/SushiBarFileImplement/Implements/ComponentStorage.cs
new file mode 100644
index 0000000..77f5e41
--- /dev/null
+++ b/SushiBar/SushiBarFileImplement/Implements/ComponentStorage.cs
@@ -0,0 +1,89 @@
+using SushiBarContracts.BindingModels;
+using SushiBarContracts.SearchModels;
+using SushiBarContracts.StoragesContracts;
+using SushiBarContracts.ViewModels;
+using SushiBarFileImplement.Models;
+
+namespace SushiBarFileImplement.Implements
+{
+ public class ComponentStorage : IComponentStorage
+ {
+ private readonly DataFileSingleton source;
+
+ public ComponentStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+ public ComponentViewModel? Delete(ComponentBindingModel model)
+ {
+ var element = source.Components.FirstOrDefault(x => x.Id == model.Id);
+ if (element != null)
+ {
+ source.Components.Remove(element);
+ source.SaveComponents();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+
+ public ComponentViewModel? GetElement(ComponentSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ return source
+ .Components
+ .FirstOrDefault(x =>
+ (!string.IsNullOrEmpty(model.ComponentName)
+ && x.ComponentName == model.ComponentName)
+ || (model.Id.HasValue && x.Id == model.Id))
+ ?.GetViewModel;
+ }
+
+ public List GetFilteredList(ComponentSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ComponentName))
+ {
+ return new();
+ }
+ return source.Components
+ .Where(x => x.ComponentName.Contains(model.ComponentName))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public List GetFullList()
+ {
+ return source
+ .Components
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public ComponentViewModel? Insert(ComponentBindingModel model)
+ {
+ model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
+ var newComponent = Component.Create(model);
+ if (newComponent == null)
+ {
+ return null;
+ }
+ source.Components.Add(newComponent);
+ source.SaveComponents();
+ return newComponent.GetViewModel;
+ }
+
+ public ComponentViewModel? Update(ComponentBindingModel model)
+ {
+ var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
+ if (component == null)
+ {
+ return null;
+ }
+ component.Update(model);
+ source.SaveComponents();
+ return component.GetViewModel;
+ }
+ }
+}
diff --git a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs
new file mode 100644
index 0000000..d2b2bbd
--- /dev/null
+++ b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs
@@ -0,0 +1,86 @@
+using SushiBarContracts.BindingModels;
+using SushiBarContracts.SearchModels;
+using SushiBarContracts.StoragesContracts;
+using SushiBarContracts.ViewModels;
+using SushiBarFileImplement.Models;
+
+namespace SushiBarFileImplement.Implements
+{
+ public class OrderStorage : IOrderStorage
+ {
+ private readonly DataFileSingleton source;
+
+ public OrderStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+ public OrderViewModel? Delete(OrderBindingModel model)
+ {
+ var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
+ if (element != null)
+ {
+ source.Orders.Remove(element);
+ source.SaveOrders();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+ return source
+ .Orders
+ .FirstOrDefault(x => x.Id == model.Id)
+ ?.GetViewModel;
+ }
+
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return new();
+ }
+ return source.Orders
+ .Where(x => x.Id == model.Id)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public List GetFullList()
+ {
+ return source
+ .Orders
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public OrderViewModel? Insert(OrderBindingModel model)
+ {
+ model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
+ var newOrder = Order.Create(model);
+ if (newOrder == null)
+ {
+ return null;
+ }
+ source.Orders.Add(newOrder);
+ source.SaveOrders();
+ return newOrder.GetViewModel;
+ }
+
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
+ if (order == null)
+ {
+ return null;
+ }
+ order.Update(model);
+ source.SaveOrders();
+ return order.GetViewModel;
+ }
+ }
+}
diff --git a/SushiBar/SushiBarFileImplement/Implements/StoreStorage.cs b/SushiBar/SushiBarFileImplement/Implements/StoreStorage.cs
new file mode 100644
index 0000000..86f7046
--- /dev/null
+++ b/SushiBar/SushiBarFileImplement/Implements/StoreStorage.cs
@@ -0,0 +1,161 @@
+using SushiBarContracts.BindingModels;
+using SushiBarContracts.SearchModels;
+using SushiBarContracts.StoragesContracts;
+using SushiBarContracts.ViewModels;
+using SushiBarDataModels.Models;
+using SushiBarFileImplement.Models;
+
+namespace SushiBarFileImplement.Implements;
+
+public class StoreStorage : IStoreStorage
+{
+ private readonly DataFileSingleton _singleton;
+
+ public StoreStorage()
+ {
+ _singleton = DataFileSingleton.GetInstance();
+ }
+
+ public List GetFullList()
+ {
+ return _singleton.Stores
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public List GetFilteredList(StoreSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return new List();
+ }
+ return _singleton.Stores
+ .Where(x => x.Id == model.Id)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public StoreViewModel? GetElement(StoreSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+ return _singleton.Stores
+ .FirstOrDefault(x => x.Id == model.Id)
+ ?.GetViewModel;
+ }
+
+ public StoreViewModel? Insert(StoreBindingModel model)
+ {
+ model.Id = _singleton.Stores.Count > 0 ? _singleton.Stores.Max(x => x.Id) + 1 : 1;
+ var store = Store.Create(model);
+ if (store == null)
+ {
+ return null;
+ }
+ _singleton.Stores.Add(store);
+ _singleton.SaveStores();
+ return store.GetViewModel;
+ }
+
+ public StoreViewModel? Update(StoreBindingModel model)
+ {
+ var store = _singleton.Stores.FirstOrDefault(x => x.Id == model.Id);
+ if (store == null)
+ {
+ return null;
+ }
+ store.Update(model);
+ _singleton.SaveStores();
+ return store.GetViewModel;
+ }
+
+ public StoreViewModel? Delete(StoreBindingModel model)
+ {
+ var element = _singleton.Stores.FirstOrDefault(x => x.Id == model.Id);
+ if (element == null) return null;
+
+ _singleton.Stores.Remove(element);
+ _singleton.SaveStores();
+ return element.GetViewModel;
+ }
+
+ public bool SellSushi(ISushiModel model, int quantity)
+ {
+ var sushi = _singleton.Sushis.FirstOrDefault(x => x.Id == model.Id);
+ int countStore = quantity;
+
+ if (sushi is null)
+ {
+ return false;
+ }
+
+ foreach (var store in _singleton.Stores)
+ {
+ foreach (var valueTuple in store.Sushis.Values)
+ {
+ if (valueTuple.Item1.Id == sushi.Id)
+ {
+ quantity -= valueTuple.Item2;
+ }
+
+ if (quantity <= 0)
+ {
+ break;
+ }
+ }
+ }
+
+ if (quantity > 0)
+ {
+ return false;
+ }
+
+ quantity = countStore;
+ foreach (var shop in _singleton.Stores)
+ {
+ var sushis = shop.Sushis;
+
+ for (var j =1; j < sushis.Count + 1; j++)
+ {
+ if (sushis[j].Item1.Id == sushi.Id)
+ {
+ while (sushis[j].Item2 > 0 && quantity > 0)
+ {
+ var tempItem2 = sushis[j].Item2;
+ tempItem2--;
+ quantity--;
+ sushis[j] = (sushis[j].Item1, tempItem2);
+ }
+ }
+
+ if (quantity > 0) continue;
+ shop.Update(new StoreBindingModel()
+ {
+ Id = shop.Id,
+ StoreName = shop.StoreName,
+ StoreAddress = shop.StoreAddress,
+ OpeningDate = shop.OpeningDate,
+ maxSushi = shop.maxSushi,
+ Sushis = sushis
+ });
+ _singleton.SaveStores();
+ return true;
+ }
+
+ shop.Update(new StoreBindingModel()
+ {
+ Id = shop.Id,
+ StoreName = shop.StoreName,
+ StoreAddress = shop.StoreAddress,
+ OpeningDate = shop.OpeningDate,
+ maxSushi = shop.maxSushi,
+ Sushis = sushis
+ });
+ _singleton.SaveStores();
+ }
+
+ return quantity <= 0;
+ }
+}
\ No newline at end of file
diff --git a/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs
new file mode 100644
index 0000000..4258fe0
--- /dev/null
+++ b/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs
@@ -0,0 +1,89 @@
+using SushiBarContracts.BindingModels;
+using SushiBarContracts.SearchModels;
+using SushiBarContracts.StoragesContracts;
+using SushiBarContracts.ViewModels;
+using SushiBarFileImplement.Models;
+
+namespace SushiBarFileImplement.Implements
+{
+ public class SushiStorage : ISushiStorage
+ {
+ private readonly DataFileSingleton source;
+
+ public SushiStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+ public SushiViewModel? Delete(SushiBindingModel model)
+ {
+ var element = source.Sushis.FirstOrDefault(x => x.Id == model.Id);
+ if (element != null)
+ {
+ source.Sushis.Remove(element);
+ source.SaveSushis();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+
+ public SushiViewModel? GetElement(SushiSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.SushiName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ return source
+ .Sushis
+ .FirstOrDefault(x =>
+ (!string.IsNullOrEmpty(model.SushiName)
+ && x.SushiName == model.SushiName)
+ || (model.Id.HasValue && x.Id == model.Id))
+ ?.GetViewModel;
+ }
+
+ public List GetFilteredList(SushiSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.SushiName))
+ {
+ return new();
+ }
+ return source.Sushis
+ .Where(x => x.SushiName.Contains(model.SushiName))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public List GetFullList()
+ {
+ return source
+ .Sushis
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public SushiViewModel? Insert(SushiBindingModel model)
+ {
+ model.Id = source.Sushis.Count > 0 ? source.Sushis.Max(x => x.Id) + 1 : 1;
+ var newSushi = Sushi.Create(model);
+ if (newSushi == null)
+ {
+ return null;
+ }
+ source.Sushis.Add(newSushi);
+ source.SaveSushis();
+ return newSushi.GetViewModel;
+ }
+
+ public SushiViewModel? Update(SushiBindingModel model)
+ {
+ var sushi = source.Sushis.FirstOrDefault(x => x.Id == model.Id);
+ if (sushi == null)
+ {
+ return null;
+ }
+ sushi.Update(model);
+ source.SaveSushis();
+ return sushi.GetViewModel;
+ }
+ }
+}
diff --git a/SushiBar/SushiBarFileImplement/Models/Component.cs b/SushiBar/SushiBarFileImplement/Models/Component.cs
new file mode 100644
index 0000000..38fe39b
--- /dev/null
+++ b/SushiBar/SushiBarFileImplement/Models/Component.cs
@@ -0,0 +1,60 @@
+using SushiBarContracts.BindingModels;
+using SushiBarContracts.ViewModels;
+using SushiBarDataModels.Models;
+using System.Xml.Linq;
+
+namespace SushiBarFileImplement.Models
+{
+ public class Component : IComponentModel
+ {
+ public int Id { get; private set; }
+ public string ComponentName { get; private set; } = string.Empty;
+ public double Cost { get; set; }
+
+ public static Component? Create(ComponentBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Component()
+ {
+ Id = model.Id,
+ ComponentName = model.ComponentName,
+ Cost = model.Cost
+ };
+ }
+ public static Component? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new Component()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ ComponentName = element.Element("ComponentName")!.Value,
+ Cost = Convert.ToDouble(element.Element("Cost")!.Value)
+ };
+ }
+ public void Update(ComponentBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ComponentName = model.ComponentName;
+ Cost = model.Cost;
+ }
+ public ComponentViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ComponentName = ComponentName,
+ Cost = Cost
+ };
+ public XElement GetXElement => new("Component",
+ new XAttribute("Id", Id),
+ new XElement("ComponentName", ComponentName),
+ new XElement("Cost", Cost.ToString()));
+ }
+}
diff --git a/SushiBar/SushiBarFileImplement/Models/Order.cs b/SushiBar/SushiBarFileImplement/Models/Order.cs
new file mode 100644
index 0000000..35fa392
--- /dev/null
+++ b/SushiBar/SushiBarFileImplement/Models/Order.cs
@@ -0,0 +1,97 @@
+using SushiBarContracts.BindingModels;
+using SushiBarContracts.ViewModels;
+using SushiBarDataModels.Enums;
+using SushiBarDataModels.Models;
+using System.Xml.Linq;
+
+namespace SushiBarFileImplement.Models
+{
+ public class Order : IOrderModel
+ {
+ public int Id { get; private set; }
+ public string SushiName { get; private set; } = string.Empty;
+ public int SushiId { get; private set; }
+ public int Count { get; private set; }
+ public double Sum { get; private set; }
+ public OrderStatus Status { get; private set; } = OrderStatus.Unknown;
+ public DateTime DateCreate { get; private set; } = DateTime.Now;
+ public DateTime? DateImplement { get; set; }
+
+ public static Order? Create(OrderBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Order()
+ {
+ Id = model.Id,
+ SushiId = model.SushiId,
+ SushiName = model.SushiName,
+ Count = model.Count,
+ Sum = model.Sum,
+ Status = model.Status,
+ DateCreate = model.DateCreate,
+ DateImplement = model.DateImplement
+ };
+ }
+ public static Order? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+
+ var order = new Order()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ SushiId = Convert.ToInt32(element.Element("SushiId")!.Value),
+ SushiName = element.Element("SushiName")!.Value,
+ Count = Convert.ToInt32(element.Element("Count")!.Value),
+ Sum = Convert.ToDouble(element.Element("Sum")!.Value),
+ Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
+ DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null)
+ };
+
+ DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl);
+ order.DateImplement = dateImpl;
+
+ return order;
+ }
+ public void Update(OrderBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ SushiId = model.SushiId;
+ SushiName = model.SushiName;
+ Count = model.Count;
+ Sum = model.Sum;
+ Status = model.Status;
+ DateCreate = model.DateCreate;
+ DateImplement = model.DateImplement;
+ }
+ public OrderViewModel GetViewModel => new()
+ {
+ Id = Id,
+ SushiId = SushiId,
+ SushiName = SushiName,
+ Count = Count,
+ Sum = Sum,
+ Status = Status,
+ DateCreate = DateCreate,
+ DateImplement = DateImplement
+ };
+
+ public XElement GetXElement => new("Order",
+ new XAttribute("Id", Id),
+ new XElement("SushiName", SushiName),
+ new XElement("SushiId", SushiId.ToString()),
+ new XElement("Count", Count.ToString()),
+ new XElement("Sum", Sum.ToString()),
+ new XElement("Status", Status.ToString()),
+ new XElement("DateCreate", DateCreate.ToString()),
+ new XElement("DateImplement", DateImplement.ToString()));
+ }
+}
diff --git a/SushiBar/SushiBarFileImplement/Models/Store.cs b/SushiBar/SushiBarFileImplement/Models/Store.cs
new file mode 100644
index 0000000..c41b18f
--- /dev/null
+++ b/SushiBar/SushiBarFileImplement/Models/Store.cs
@@ -0,0 +1,104 @@
+using System.Xml.Linq;
+using SushiBarContracts.BindingModels;
+using SushiBarContracts.ViewModels;
+using SushiBarDataModels.Models;
+
+namespace SushiBarFileImplement.Models
+{
+ public class Store : IStoreModel
+ {
+ public int Id { get; private init; }
+ public string StoreName { get; private set; } = string.Empty;
+ public string StoreAddress { get; private set; } = string.Empty;
+ public DateTime OpeningDate { get; private set; }
+ public int maxSushi { get; private set; }
+
+ private Dictionary _sushi = new();
+
+ public Dictionary Sushis
+ {
+ get
+ {
+ var source = DataFileSingleton.GetInstance();
+ return _sushi.ToDictionary(i => i.Key,
+ i => (source.Sushis.FirstOrDefault(z => z.Id == i.Key)! as ISushiModel, i.Value));
+ }
+ private init => Sushis = value;
+ }
+
+ public static Store? Create(StoreBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+
+ return new Store()
+ {
+ Id = model.Id,
+ StoreName = model.StoreName,
+ OpeningDate = model.OpeningDate,
+ StoreAddress = model.StoreAddress,
+ _sushi = model.Sushis
+ .ToDictionary(x => x.Key, x => x.Value.Item2),
+ maxSushi = model.maxSushi
+ };
+ }
+
+ public static Store? Create(XElement? element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+
+ return new Store()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ StoreName = element.Element("StoreName")!.Value,
+ StoreAddress = element.Element("StoreAddress")!.Value,
+ maxSushi = Convert.ToInt32(element.Element("MaxSushi")!.Value),
+ _sushi = element.Element("Sushis")
+ !.Elements("Sushi")
+ .ToDictionary(
+ x => Convert.ToInt32(x.Element("Key")?.Value),
+ x => Convert.ToInt32(x.Element("Value")?.Value)
+ )
+ };
+ }
+
+ public void Update(StoreBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+
+ StoreName = model.StoreName;
+ StoreAddress = model.StoreAddress;
+ _sushi = model.Sushis
+ .ToDictionary(x => x.Key, x => x.Value.Item2);
+ maxSushi = model.maxSushi;
+ }
+
+ public StoreViewModel GetViewModel => new()
+ {
+ Id = Id,
+ StoreName = StoreName,
+ Sushis = Sushis,
+ StoreAddress = StoreAddress,
+ maxSushi = maxSushi
+ };
+
+ public XElement GetXElement => new("Store",
+ new XAttribute("Id", Id),
+ new XElement("StoreName", StoreName),
+ new XElement("StoreAddress", StoreAddress),
+ new XElement("MaxSushi", maxSushi),
+ new XElement("Sushis", _sushi.Select(x => new XElement("Sushi",
+ new XElement("Key", x.Key),
+ new XElement("Value", x.Value))
+ ).ToArray())
+ );
+ }
+}
diff --git a/SushiBar/SushiBarFileImplement/Models/Suhsi.cs b/SushiBar/SushiBarFileImplement/Models/Suhsi.cs
new file mode 100644
index 0000000..c603262
--- /dev/null
+++ b/SushiBar/SushiBarFileImplement/Models/Suhsi.cs
@@ -0,0 +1,87 @@
+using SushiBarContracts.BindingModels;
+using SushiBarContracts.ViewModels;
+using SushiBarDataModels.Models;
+using System.Xml.Linq;
+
+namespace SushiBarFileImplement.Models
+{
+ public class Sushi : ISushiModel
+ {
+ public int Id { get; private set; }
+ public string SushiName { get; private set; } = string.Empty;
+ public double Price { get; private set; }
+ public Dictionary Components { get; private set; } = new();
+
+ private Dictionary? _sushiComponents = null;
+ public Dictionary SushiComponents
+ {
+ get
+ {
+ if (_sushiComponents == null)
+ {
+ var source = DataFileSingleton.GetInstance();
+ _sushiComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,y.Value));
+ }
+ return _sushiComponents;
+ }
+ }
+ public static Sushi? Create(SushiBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Sushi()
+ {
+ Id = model.Id,
+ SushiName = model.SushiName,
+ Price = model.Price,
+ Components = model.SushiComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
+ };
+ }
+ public static Sushi? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new Sushi()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ SushiName = element.Element("SushiName")!.Value,
+ Price = Convert.ToDouble(element.Element("Price")!.Value),
+ Components = element.Element("SushiComponents")!
+ .Elements("ProductComponent")
+ .ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value),
+ x => Convert.ToInt32(x.Element("Value")?.Value))
+ };
+ }
+ public void Update(SushiBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ SushiName = model.SushiName;
+ Price = model.Price;
+ Components = model.SushiComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
+ _sushiComponents = null;
+ }
+ public SushiViewModel GetViewModel => new()
+ {
+ Id = Id,
+ SushiName = SushiName,
+ Price = Price,
+ SushiComponents = SushiComponents
+ };
+ public XElement GetXElement => new("Sushi",
+ new XAttribute("Id", Id),
+ new XElement("SushiName", SushiName),
+ new XElement("Price", Price.ToString()),
+ new XElement("SushiComponents", Components.Select(x => new XElement("ProductComponent",
+ new XElement("Key", x.Key),
+ new XElement("Value", x.Value))
+ ).ToArray())
+ );
+ }
+}
diff --git a/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj b/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj
new file mode 100644
index 0000000..277f68e
--- /dev/null
+++ b/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/SushiBar/SushiBarModels/Models/IStoreModel.cs b/SushiBar/SushiBarModels/Models/IStoreModel.cs
index 2d31eda..5b3c8b9 100644
--- a/SushiBar/SushiBarModels/Models/IStoreModel.cs
+++ b/SushiBar/SushiBarModels/Models/IStoreModel.cs
@@ -3,8 +3,9 @@
public interface IStoreModel : IId
{
public string StoreName { get; }
- public string StoreAdress { get; }
+ public string StoreAddress { get; }
DateTime OpeningDate { get; }
Dictionary Sushis { get; }
+ public int maxSushi { get; }
}
}
diff --git a/SushiBar/SushibarListImplement/Implements/StoreStorage.cs b/SushiBar/SushibarListImplement/Implements/StoreStorage.cs
index 1adbb11..45c4534 100644
--- a/SushiBar/SushibarListImplement/Implements/StoreStorage.cs
+++ b/SushiBar/SushibarListImplement/Implements/StoreStorage.cs
@@ -2,6 +2,7 @@
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
+using SushiBarDataModels.Models;
using SushibarListImplement.Models;
namespace SushibarListImplement.Implements
@@ -27,6 +28,11 @@ namespace SushibarListImplement.Implements
return null;
}
+ public bool SellSushi(ISushiModel model, int quantity)
+ {
+ throw new NotImplementedException();
+ }
+
public StoreViewModel? GetElement(StoreSearchModel model)
{
if (string.IsNullOrEmpty(model.StoreName) && !model.Id.HasValue)
diff --git a/SushiBar/SushibarListImplement/Models/Store.cs b/SushiBar/SushibarListImplement/Models/Store.cs
index 5d7300d..b0ad75f 100644
--- a/SushiBar/SushibarListImplement/Models/Store.cs
+++ b/SushiBar/SushibarListImplement/Models/Store.cs
@@ -7,9 +7,10 @@ namespace SushibarListImplement.Models
public class Store : IStoreModel
{
public string StoreName { get; private set; } = string.Empty;
- public string StoreAdress { get; private set; } = string.Empty;
+ public string StoreAddress { get; private set; } = string.Empty;
public DateTime OpeningDate { get; private set; }
public Dictionary Sushis { get; private set; } = new();
+ public int maxSushi { get; }
public int Id { get; private set; }
public static Store? Create(StoreBindingModel? model)
@@ -22,9 +23,9 @@ namespace SushibarListImplement.Models
{
Id = model.Id,
StoreName = model.StoreName,
- StoreAdress = model.StoreAdress,
+ StoreAddress = model.StoreAddress,
OpeningDate = model.OpeningDate,
- Sushis = new()
+ Sushis = new Dictionary()
};
}
@@ -35,7 +36,7 @@ namespace SushibarListImplement.Models
return;
}
StoreName = model.StoreName;
- StoreAdress = model.StoreAdress;
+ StoreAddress = model.StoreAddress;
OpeningDate = model.OpeningDate;
Sushis = model.Sushis;
}
@@ -44,7 +45,7 @@ namespace SushibarListImplement.Models
{
Id = Id,
StoreName = StoreName,
- StoreAdress = StoreAdress,
+ StoreAddress = StoreAddress,
OpeningDate = OpeningDate,
Sushis = Sushis
};