Compare commits

...

6 Commits

Author SHA1 Message Date
40a93a182a 2 hard lab 2023-03-11 21:23:26 +04:00
a46c723d58 Merge branch 'LabWork_2' into LabWork_2_hard 2023-02-28 08:58:17 +04:00
6c5c4607cf last fix 2023-02-14 22:44:19 +04:00
0851de65f5 fix 2023-02-14 10:05:38 +04:00
16d53bc9ec Complete 2023-02-13 19:08:26 +04:00
8edde4a4fc add project SushiBarFileImplements 2023-02-13 18:45:25 +04:00
33 changed files with 1268 additions and 55 deletions

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RiderProjectSettingsUpdater">
<option name="vcsConfiguration" value="2" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -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

View File

@ -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;
}
}

View File

@ -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();
}
}
}
}

View File

@ -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;
}
}

View File

@ -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

View File

@ -66,4 +66,13 @@
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="SushiName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Cost.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -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)

View File

@ -0,0 +1,110 @@
namespace SushiBar
{
partial class FormStoreSell
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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<FormStoreSell> 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 = "DocumentName";
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);
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -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
{

View File

@ -15,6 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\SushiBarBusinessLogic\SushiBarBusinessLogic.csproj" />
<ProjectReference Include="..\SushiBarFileImplement\SushiBarFileImplement.csproj" />
<ProjectReference Include="..\SushibarListImplement\SushibarListImplement.csproj" />
</ItemGroup>

View File

@ -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<OrderLogic> logger, IOrderStorage orderStorage)
public OrderLogic(ILogger<OrderLogic> 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) == false)
{
_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--;

View File

@ -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

View File

@ -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<int, (ISushiModel, int)> Sushis { get; set; } = new();
public int maxSushi { get; set; }
public int Id { get; set; }
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -5,14 +5,15 @@ namespace SushiBarContracts.ViewModels
{
public class StoreViewModel : IStoreModel
{
public Dictionary<int, (ISushiModel, int)> Sushis { get; set; } = new();
public int Id { get; set; }
public Dictionary<int, (ISushiModel, int)> 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;
}
}

View File

@ -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<Component> Components { get; }
public List<Order> Orders { get; }
public List<Sushi> Sushis { get; }
public List<Store> 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<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{
return File.Exists(filename) ? XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList() : new List<T>();
}
private static void SaveData<T>(IReadOnlyCollection<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
{
if (data != null)
{
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
}
}
}
}

View File

@ -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<ComponentViewModel> 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<ComponentViewModel> 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;
}
}
}

View File

@ -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<OrderViewModel> 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<OrderViewModel> 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;
}
}
}

View File

@ -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<StoreViewModel> GetFullList()
{
return _singleton.Stores
.Select(x => x.GetViewModel)
.ToList();
}
public List<StoreViewModel> GetFilteredList(StoreSearchModel model)
{
if (!model.Id.HasValue)
{
return new List<StoreViewModel>();
}
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;
}
}

View File

@ -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<SushiViewModel> 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<SushiViewModel> 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;
}
}
}

View File

@ -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()));
}
}

View File

@ -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()));
}
}

View File

@ -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<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _sushiComponents = null;
public Dictionary<int, (IComponentModel, int)> 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())
);
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -3,8 +3,9 @@
public interface IStoreModel : IId
{
public string StoreName { get; }
public string StoreAdress { get; }
public string StoreAddress { get; }
DateTime OpeningDate { get; }
Dictionary<int, (ISushiModel, int)> Sushis { get; }
public int maxSushi { get; }
}
}

View File

@ -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)

View File

@ -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<int, (ISushiModel, int)> 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<int, (ISushiModel, int)>()
};
}
@ -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
};