Compare commits
19 Commits
main
...
LabWork_2_
Author | SHA1 | Date | |
---|---|---|---|
48e89f3b9f | |||
a44b0f052d | |||
40a93a182a | |||
a46c723d58 | |||
153d212184 | |||
6c5c4607cf | |||
4b9f66ba35 | |||
0851de65f5 | |||
16d53bc9ec | |||
8edde4a4fc | |||
b7ccba8acc | |||
665aaab1a6 | |||
ae4eef9254 | |||
9399daba9e | |||
d7f9f16b23 | |||
10a579904a | |||
a6bcc01785 | |||
3e25205bf6 | |||
a87d95c92b |
@ -3,7 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32819.101
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBar", "SushiBar\SushiBar.csproj", "{DB81A759-B157-477C-9281-EE358968519D}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBar", "SushiBar\SushiBar.csproj", "{DB81A759-B157-477C-9281-EE358968519D}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarDataModels", "SushiBarModels\SushiBarDataModels.csproj", "{CFB2D9F9-EA44-4E61-B6BE-5A2AA3C6AF07}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{1185D549-D227-4BE3-8EAD-D294029BCA5D}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{A273021E-72E7-4C23-927C-A3E4851BD8D1}"
|
||||
EndProject
|
||||
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
|
||||
@ -15,6 +25,26 @@ Global
|
||||
{DB81A759-B157-477C-9281-EE358968519D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DB81A759-B157-477C-9281-EE358968519D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DB81A759-B157-477C-9281-EE358968519D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CFB2D9F9-EA44-4E61-B6BE-5A2AA3C6AF07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CFB2D9F9-EA44-4E61-B6BE-5A2AA3C6AF07}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CFB2D9F9-EA44-4E61-B6BE-5A2AA3C6AF07}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CFB2D9F9-EA44-4E61-B6BE-5A2AA3C6AF07}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1185D549-D227-4BE3-8EAD-D294029BCA5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1185D549-D227-4BE3-8EAD-D294029BCA5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1185D549-D227-4BE3-8EAD-D294029BCA5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1185D549-D227-4BE3-8EAD-D294029BCA5D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A273021E-72E7-4C23-927C-A3E4851BD8D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A273021E-72E7-4C23-927C-A3E4851BD8D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A273021E-72E7-4C23-927C-A3E4851BD8D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A273021E-72E7-4C23-927C-A3E4851BD8D1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{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
|
||||
|
39
SushiBar/SushiBar/Form1.Designer.cs
generated
39
SushiBar/SushiBar/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <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.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
121
SushiBar/SushiBar/FormComponent.Designer.cs
generated
Normal file
121
SushiBar/SushiBar/FormComponent.Designer.cs
generated
Normal file
@ -0,0 +1,121 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class FormComponent
|
||||
{
|
||||
/// <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.textBoxName = new System.Windows.Forms.TextBox();
|
||||
this.labelName = new System.Windows.Forms.Label();
|
||||
this.labelCost = new System.Windows.Forms.Label();
|
||||
this.textBoxCost = new System.Windows.Forms.TextBox();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
this.textBoxName.Location = new System.Drawing.Point(57, 6);
|
||||
this.textBoxName.Name = "textBoxName";
|
||||
this.textBoxName.Size = new System.Drawing.Size(270, 23);
|
||||
this.textBoxName.TabIndex = 0;
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
this.labelName.AutoSize = true;
|
||||
this.labelName.Location = new System.Drawing.Point(12, 9);
|
||||
this.labelName.Name = "labelName";
|
||||
this.labelName.Size = new System.Drawing.Size(39, 15);
|
||||
this.labelName.TabIndex = 1;
|
||||
this.labelName.Text = "Name";
|
||||
//
|
||||
// labelCost
|
||||
//
|
||||
this.labelCost.AutoSize = true;
|
||||
this.labelCost.Location = new System.Drawing.Point(12, 36);
|
||||
this.labelCost.Name = "labelCost";
|
||||
this.labelCost.Size = new System.Drawing.Size(31, 15);
|
||||
this.labelCost.TabIndex = 2;
|
||||
this.labelCost.Text = "Cost";
|
||||
//
|
||||
// textBoxCost
|
||||
//
|
||||
this.textBoxCost.Location = new System.Drawing.Point(57, 33);
|
||||
this.textBoxCost.Name = "textBoxCost";
|
||||
this.textBoxCost.Size = new System.Drawing.Size(270, 23);
|
||||
this.textBoxCost.TabIndex = 3;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.BackColor = System.Drawing.SystemColors.Control;
|
||||
this.buttonSave.Location = new System.Drawing.Point(12, 62);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(153, 23);
|
||||
this.buttonSave.TabIndex = 4;
|
||||
this.buttonSave.Text = "Save";
|
||||
this.buttonSave.UseVisualStyleBackColor = false;
|
||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.BackColor = System.Drawing.SystemColors.Control;
|
||||
this.buttonCancel.Location = new System.Drawing.Point(171, 62);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(156, 23);
|
||||
this.buttonCancel.TabIndex = 5;
|
||||
this.buttonCancel.Text = "Cancel";
|
||||
this.buttonCancel.UseVisualStyleBackColor = false;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// FormComponent
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(339, 93);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.textBoxCost);
|
||||
this.Controls.Add(this.labelCost);
|
||||
this.Controls.Add(this.labelName);
|
||||
this.Controls.Add(this.textBoxName);
|
||||
this.Name = "FormComponent";
|
||||
this.Text = "FormComponent";
|
||||
this.Load += new System.EventHandler(this.FormComponent_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TextBox textBoxName;
|
||||
private Label labelName;
|
||||
private Label labelCost;
|
||||
private TextBox textBoxCost;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
84
SushiBar/SushiBar/FormComponent.cs
Normal file
84
SushiBar/SushiBar/FormComponent.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
public partial class FormComponent : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentLogic _logic;
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
public FormComponent(ILogger<FormComponent> logger, IComponentLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Fill name text box", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Saving Component");
|
||||
try
|
||||
{
|
||||
var model = new ComponentBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ComponentName = textBoxName.Text,
|
||||
Cost = Convert.ToDouble(textBoxCost.Text)
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||
_logic.Create(model);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Error on saving. Additional info below.");
|
||||
}
|
||||
MessageBox.Show("Saving is successful", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on saving");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void FormComponent_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Get component");
|
||||
var view = _logic.ReadElement(new ComponentSearchModel{ Id = _id.Value });
|
||||
if (view != null)
|
||||
{
|
||||
textBoxName.Text = view.ComponentName;
|
||||
textBoxCost.Text = view.Cost.ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error in getting cpmponent");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
SushiBar/SushiBar/FormComponent.resx
Normal file
60
SushiBar/SushiBar/FormComponent.resx
Normal 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>
|
114
SushiBar/SushiBar/FormComponents.Designer.cs
generated
Normal file
114
SushiBar/SushiBar/FormComponents.Designer.cs
generated
Normal file
@ -0,0 +1,114 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class FormComponents
|
||||
{
|
||||
/// <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.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonEdit = new System.Windows.Forms.Button();
|
||||
this.buttonRemove = new System.Windows.Forms.Button();
|
||||
this.buttonReload = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Location = new System.Drawing.Point(12, 12);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowTemplate.Height = 25;
|
||||
this.dataGridView.Size = new System.Drawing.Size(612, 426);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(630, 12);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(158, 23);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
this.buttonAdd.Text = "Add";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||
//
|
||||
// buttonEdit
|
||||
//
|
||||
this.buttonEdit.Location = new System.Drawing.Point(630, 41);
|
||||
this.buttonEdit.Name = "buttonEdit";
|
||||
this.buttonEdit.Size = new System.Drawing.Size(158, 23);
|
||||
this.buttonEdit.TabIndex = 2;
|
||||
this.buttonEdit.Text = "Edit";
|
||||
this.buttonEdit.UseVisualStyleBackColor = true;
|
||||
this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click);
|
||||
//
|
||||
// buttonRemove
|
||||
//
|
||||
this.buttonRemove.Location = new System.Drawing.Point(630, 70);
|
||||
this.buttonRemove.Name = "buttonRemove";
|
||||
this.buttonRemove.Size = new System.Drawing.Size(158, 23);
|
||||
this.buttonRemove.TabIndex = 3;
|
||||
this.buttonRemove.Text = "Remove";
|
||||
this.buttonRemove.UseVisualStyleBackColor = true;
|
||||
this.buttonRemove.Click += new System.EventHandler(this.ButtonRemove_Click);
|
||||
//
|
||||
// buttonReload
|
||||
//
|
||||
this.buttonReload.Location = new System.Drawing.Point(630, 99);
|
||||
this.buttonReload.Name = "buttonReload";
|
||||
this.buttonReload.Size = new System.Drawing.Size(158, 23);
|
||||
this.buttonReload.TabIndex = 4;
|
||||
this.buttonReload.Text = "Reload";
|
||||
this.buttonReload.UseVisualStyleBackColor = true;
|
||||
this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click);
|
||||
//
|
||||
// FormComponents
|
||||
//
|
||||
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.buttonReload);
|
||||
this.Controls.Add(this.buttonRemove);
|
||||
this.Controls.Add(this.buttonEdit);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Name = "FormComponents";
|
||||
this.Text = "Form1";
|
||||
this.Load += new System.EventHandler(this.FormComponents_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonAdd;
|
||||
private Button buttonEdit;
|
||||
private Button buttonRemove;
|
||||
private Button buttonReload;
|
||||
}
|
||||
}
|
105
SushiBar/SushiBar/FormComponents.cs
Normal file
105
SushiBar/SushiBar/FormComponents.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
public partial class FormComponents : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentLogic _logic;
|
||||
|
||||
public FormComponents(ILogger<FormComponents> logger, IComponentLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||
if (service is FormComponent form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonEdit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||
if (service is FormComponent form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Delete record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Delete component");
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new ComponentBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
{
|
||||
throw new Exception("Error on deleting. Additional info below.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error delete component");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonReload_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void FormComponents_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
_logger.LogInformation("Load components");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error load components");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
SushiBar/SushiBar/FormComponents.resx
Normal file
60
SushiBar/SushiBar/FormComponents.resx
Normal 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>
|
144
SushiBar/SushiBar/FormCreateOrder.Designer.cs
generated
Normal file
144
SushiBar/SushiBar/FormCreateOrder.Designer.cs
generated
Normal file
@ -0,0 +1,144 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class FormCreateOrder
|
||||
{
|
||||
/// <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.labelSushi = new System.Windows.Forms.Label();
|
||||
this.comboBoxSushi = new System.Windows.Forms.ComboBox();
|
||||
this.labelCount = new System.Windows.Forms.Label();
|
||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||
this.labelSum = new System.Windows.Forms.Label();
|
||||
this.textBoxSum = new System.Windows.Forms.TextBox();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// 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 = 0;
|
||||
this.labelSushi.Text = "Sushi";
|
||||
//
|
||||
// comboBoxSushi
|
||||
//
|
||||
this.comboBoxSushi.FormattingEnabled = true;
|
||||
this.comboBoxSushi.Location = new System.Drawing.Point(53, 6);
|
||||
this.comboBoxSushi.Name = "comboBoxSushi";
|
||||
this.comboBoxSushi.Size = new System.Drawing.Size(197, 23);
|
||||
this.comboBoxSushi.TabIndex = 1;
|
||||
this.comboBoxSushi.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSushi_SelectedIndexChanged);
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
this.labelCount.AutoSize = true;
|
||||
this.labelCount.Location = new System.Drawing.Point(12, 41);
|
||||
this.labelCount.Name = "labelCount";
|
||||
this.labelCount.Size = new System.Drawing.Size(40, 15);
|
||||
this.labelCount.TabIndex = 2;
|
||||
this.labelCount.Text = "Count";
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
this.textBoxCount.Location = new System.Drawing.Point(53, 38);
|
||||
this.textBoxCount.Name = "textBoxCount";
|
||||
this.textBoxCount.Size = new System.Drawing.Size(197, 23);
|
||||
this.textBoxCount.TabIndex = 3;
|
||||
this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged);
|
||||
//
|
||||
// labelSum
|
||||
//
|
||||
this.labelSum.AutoSize = true;
|
||||
this.labelSum.Location = new System.Drawing.Point(12, 74);
|
||||
this.labelSum.Name = "labelSum";
|
||||
this.labelSum.Size = new System.Drawing.Size(31, 15);
|
||||
this.labelSum.TabIndex = 4;
|
||||
this.labelSum.Text = "Sum";
|
||||
//
|
||||
// textBoxSum
|
||||
//
|
||||
this.textBoxSum.Location = new System.Drawing.Point(53, 71);
|
||||
this.textBoxSum.Name = "textBoxSum";
|
||||
this.textBoxSum.Size = new System.Drawing.Size(197, 23);
|
||||
this.textBoxSum.TabIndex = 5;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(12, 100);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(105, 23);
|
||||
this.buttonSave.TabIndex = 6;
|
||||
this.buttonSave.Text = "Save";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(123, 100);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(127, 23);
|
||||
this.buttonCancel.TabIndex = 7;
|
||||
this.buttonCancel.Text = "Cancel";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// FormCreateOrder
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(262, 130);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.textBoxSum);
|
||||
this.Controls.Add(this.labelSum);
|
||||
this.Controls.Add(this.textBoxCount);
|
||||
this.Controls.Add(this.labelCount);
|
||||
this.Controls.Add(this.comboBoxSushi);
|
||||
this.Controls.Add(this.labelSushi);
|
||||
this.Name = "FormCreateOrder";
|
||||
this.Text = "FormCreateOrder";
|
||||
this.Load += new System.EventHandler(this.FormCreateOrder_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelSushi;
|
||||
private ComboBox comboBoxSushi;
|
||||
private Label labelCount;
|
||||
private TextBox textBoxCount;
|
||||
private Label labelSum;
|
||||
private TextBox textBoxSum;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
122
SushiBar/SushiBar/FormCreateOrder.cs
Normal file
122
SushiBar/SushiBar/FormCreateOrder.cs
Normal file
@ -0,0 +1,122 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
public partial class FormCreateOrder : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISushiLogic _logicP;
|
||||
private readonly IOrderLogic _logicO;
|
||||
|
||||
public FormCreateOrder(ILogger<FormCreateOrder> logger, ISushiLogic logicP, IOrderLogic logicO)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicP = logicP;
|
||||
_logicO = logicO;
|
||||
}
|
||||
|
||||
private void CalcSum()
|
||||
{
|
||||
if (comboBoxSushi.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
try
|
||||
{
|
||||
int id = Convert.ToInt32(comboBoxSushi.SelectedValue);
|
||||
var sushi = _logicP.ReadElement(new SushiSearchModel { Id = id });
|
||||
int count = Convert.ToInt32(textBoxCount.Text);
|
||||
textBoxSum.Text = Math.Round(count * (sushi?.Price ?? 0), 2).ToString();
|
||||
_logger.LogInformation("Calculating sum of order");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on calculating sum of order");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logicP.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxSushi.DisplayMember = "SushiName";
|
||||
comboBoxSushi.ValueMember = "Id";
|
||||
comboBoxSushi.DataSource = list;
|
||||
comboBoxSushi.SelectedItem = null;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on loading sushi");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Fill in text box count", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxSushi.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Select sushi", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Create order");
|
||||
try
|
||||
{
|
||||
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
||||
{
|
||||
SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue),
|
||||
SushiName = comboBoxSushi.Text,
|
||||
Count = Convert.ToInt32(textBoxCount.Text),
|
||||
Sum = Convert.ToDouble(textBoxSum.Text)
|
||||
});
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Error on creating order. Additional info below.");
|
||||
}
|
||||
MessageBox.Show("Saving is successful", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on saving");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void FormCreateOrder_Load(object sender, EventArgs e)
|
||||
{
|
||||
_logger.LogInformation("Load sushi for order");
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void TextBoxCount_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
CalcSum();
|
||||
}
|
||||
|
||||
private void ComboBoxSushi_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
CalcSum();
|
||||
}
|
||||
}
|
||||
}
|
60
SushiBar/SushiBar/FormCreateOrder.resx
Normal file
60
SushiBar/SushiBar/FormCreateOrder.resx
Normal 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>
|
210
SushiBar/SushiBar/FormMain.Designer.cs
generated
Normal file
210
SushiBar/SushiBar/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,210 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class FormMain
|
||||
{
|
||||
/// <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.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||
this.directoryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.sushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.storeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.buttonCreateOrder = new System.Windows.Forms.Button();
|
||||
this.buttonSubmit = new System.Windows.Forms.Button();
|
||||
this.buttonReady = new System.Windows.Forms.Button();
|
||||
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();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Location = new System.Drawing.Point(12, 27);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowTemplate.Height = 25;
|
||||
this.dataGridView.Size = new System.Drawing.Size(656, 411);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.directoryToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(800, 24);
|
||||
this.menuStrip1.TabIndex = 1;
|
||||
this.menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// directoryToolStripMenuItem
|
||||
//
|
||||
this.directoryToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.componentsToolStripMenuItem,
|
||||
this.sushiToolStripMenuItem,
|
||||
this.storeToolStripMenuItem});
|
||||
this.directoryToolStripMenuItem.Name = "directoryToolStripMenuItem";
|
||||
this.directoryToolStripMenuItem.Size = new System.Drawing.Size(67, 20);
|
||||
this.directoryToolStripMenuItem.Text = "Directory";
|
||||
//
|
||||
// componentsToolStripMenuItem
|
||||
//
|
||||
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
|
||||
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(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(143, 22);
|
||||
this.storeToolStripMenuItem.Text = "Store";
|
||||
this.storeToolStripMenuItem.Click += new System.EventHandler(this.StoreToolStripMenuItem_Click);
|
||||
//
|
||||
// buttonCreateOrder
|
||||
//
|
||||
this.buttonCreateOrder.Location = new System.Drawing.Point(674, 27);
|
||||
this.buttonCreateOrder.Name = "buttonCreateOrder";
|
||||
this.buttonCreateOrder.Size = new System.Drawing.Size(114, 23);
|
||||
this.buttonCreateOrder.TabIndex = 2;
|
||||
this.buttonCreateOrder.Text = "Create Order";
|
||||
this.buttonCreateOrder.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
|
||||
//
|
||||
// buttonSubmit
|
||||
//
|
||||
this.buttonSubmit.Location = new System.Drawing.Point(674, 56);
|
||||
this.buttonSubmit.Name = "buttonSubmit";
|
||||
this.buttonSubmit.Size = new System.Drawing.Size(114, 23);
|
||||
this.buttonSubmit.TabIndex = 3;
|
||||
this.buttonSubmit.Text = "Submit";
|
||||
this.buttonSubmit.UseVisualStyleBackColor = true;
|
||||
this.buttonSubmit.Click += new System.EventHandler(this.ButtonSubmit_Click);
|
||||
//
|
||||
// buttonReady
|
||||
//
|
||||
this.buttonReady.Location = new System.Drawing.Point(674, 85);
|
||||
this.buttonReady.Name = "buttonReady";
|
||||
this.buttonReady.Size = new System.Drawing.Size(114, 23);
|
||||
this.buttonReady.TabIndex = 4;
|
||||
this.buttonReady.Text = "Order Ready";
|
||||
this.buttonReady.UseVisualStyleBackColor = true;
|
||||
this.buttonReady.Click += new System.EventHandler(this.ButtonReady_Click);
|
||||
//
|
||||
// buttonIssue
|
||||
//
|
||||
this.buttonIssue.Location = new System.Drawing.Point(674, 114);
|
||||
this.buttonIssue.Name = "buttonIssue";
|
||||
this.buttonIssue.Size = new System.Drawing.Size(114, 23);
|
||||
this.buttonIssue.TabIndex = 5;
|
||||
this.buttonIssue.Text = "Order Issue";
|
||||
this.buttonIssue.UseVisualStyleBackColor = true;
|
||||
this.buttonIssue.Click += new System.EventHandler(this.ButtonIssue_Click);
|
||||
//
|
||||
// buttonReload
|
||||
//
|
||||
this.buttonReload.Location = new System.Drawing.Point(674, 143);
|
||||
this.buttonReload.Name = "buttonReload";
|
||||
this.buttonReload.Size = new System.Drawing.Size(114, 23);
|
||||
this.buttonReload.TabIndex = 6;
|
||||
this.buttonReload.Text = "Reload";
|
||||
this.buttonReload.UseVisualStyleBackColor = true;
|
||||
this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click);
|
||||
//
|
||||
// buttonReplenishment
|
||||
//
|
||||
this.buttonReplenishment.Location = new System.Drawing.Point(674, 415);
|
||||
this.buttonReplenishment.Name = "buttonReplenishment";
|
||||
this.buttonReplenishment.Size = new System.Drawing.Size(114, 23);
|
||||
this.buttonReplenishment.TabIndex = 7;
|
||||
this.buttonReplenishment.Text = "Replenishment";
|
||||
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);
|
||||
this.Controls.Add(this.buttonReady);
|
||||
this.Controls.Add(this.buttonSubmit);
|
||||
this.Controls.Add(this.buttonCreateOrder);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Controls.Add(this.menuStrip1);
|
||||
this.MainMenuStrip = this.menuStrip1;
|
||||
this.Name = "FormMain";
|
||||
this.Text = "FormMain";
|
||||
this.Load += new System.EventHandler(this.FormMain_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.menuStrip1.ResumeLayout(false);
|
||||
this.menuStrip1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private MenuStrip menuStrip1;
|
||||
private ToolStripMenuItem directoryToolStripMenuItem;
|
||||
private Button buttonCreateOrder;
|
||||
private Button buttonSubmit;
|
||||
private Button buttonReady;
|
||||
private Button buttonIssue;
|
||||
private Button buttonReload;
|
||||
private ToolStripMenuItem componentsToolStripMenuItem;
|
||||
private ToolStripMenuItem sushiToolStripMenuItem;
|
||||
private ToolStripMenuItem storeToolStripMenuItem;
|
||||
private Button buttonReplenishment;
|
||||
private Button ButtonSell;
|
||||
}
|
||||
}
|
204
SushiBar/SushiBar/FormMain.cs
Normal file
204
SushiBar/SushiBar/FormMain.cs
Normal file
@ -0,0 +1,204 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarDataModels.Enums;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
public partial class FormMain : Form
|
||||
{
|
||||
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_orderLogic = orderLogic;
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Load components");
|
||||
try
|
||||
{
|
||||
var list = _orderLogic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["SushiId"].Visible = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on load orders");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||
if (service is FormCreateOrder form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSubmit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Order №{id}. Change statuc on -Submit", id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel {
|
||||
Id = id,
|
||||
SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value),
|
||||
SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(),
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
|
||||
});
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Error on saving. Additional info below.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error submit order");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonReady_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Order №{id}. Change status on -Ready",id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel {
|
||||
Id = id,
|
||||
SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value),
|
||||
SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString() ?? "",
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString() ?? "Unkown"),
|
||||
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString() ?? "0"),
|
||||
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString() ?? ""),
|
||||
});
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Error on saving. Additional info below.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on change status");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonIssue_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Order №{id}. Change status on -Issued", id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel {
|
||||
Id = id,
|
||||
SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value),
|
||||
SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(),
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
|
||||
});
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Error on saving. Additional info below.");
|
||||
}
|
||||
_logger.LogInformation("Order №{id} issued", id);
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on change status");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonReload_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||
if (service is FormComponents form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void SushiToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSushiMoreThenOne));
|
||||
|
||||
if (service is FormSushiMoreThenOne form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void StoreToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStores));
|
||||
|
||||
if (service is FormStores form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonReplenishment_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment));
|
||||
|
||||
if (service is FormStoreReplenishment form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSell_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStoreSell));
|
||||
|
||||
if (service is FormStoreSell form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
63
SushiBar/SushiBar/FormMain.resx
Normal file
63
SushiBar/SushiBar/FormMain.resx
Normal file
@ -0,0 +1,63 @@
|
||||
<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>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
195
SushiBar/SushiBar/FormStore.Designer.cs
generated
Normal file
195
SushiBar/SushiBar/FormStore.Designer.cs
generated
Normal file
@ -0,0 +1,195 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class FormStore
|
||||
{
|
||||
/// <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.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();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
|
||||
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
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.SushiName,
|
||||
this.Cost,
|
||||
this.Count});
|
||||
this.dataGridView.Location = new System.Drawing.Point(12, 12);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowTemplate.Height = 25;
|
||||
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;
|
||||
this.comboBoxName.Location = new System.Drawing.Point(616, 12);
|
||||
this.comboBoxName.Name = "comboBoxName";
|
||||
this.comboBoxName.Size = new System.Drawing.Size(172, 23);
|
||||
this.comboBoxName.TabIndex = 1;
|
||||
this.comboBoxName.SelectedIndexChanged += new System.EventHandler(this.ComboBoxName_SelectedIndexChanged);
|
||||
//
|
||||
// textBoxAddress
|
||||
//
|
||||
this.textBoxAddress.Location = new System.Drawing.Point(616, 56);
|
||||
this.textBoxAddress.Name = "textBoxAddress";
|
||||
this.textBoxAddress.Size = new System.Drawing.Size(172, 23);
|
||||
this.textBoxAddress.TabIndex = 2;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(616, 38);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(49, 15);
|
||||
this.label1.TabIndex = 3;
|
||||
this.label1.Text = "Address";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(616, 82);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(80, 15);
|
||||
this.label2.TabIndex = 5;
|
||||
this.label2.Text = "Date Opening";
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(621, 415);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonSave.TabIndex = 6;
|
||||
this.buttonSave.Text = "Save";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(702, 415);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(86, 23);
|
||||
this.buttonCancel.TabIndex = 7;
|
||||
this.buttonCancel.Text = "Cancel";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// dateTimePicker
|
||||
//
|
||||
this.dateTimePicker.Location = new System.Drawing.Point(616, 100);
|
||||
this.dateTimePicker.Name = "dateTimePicker";
|
||||
this.dateTimePicker.Size = new System.Drawing.Size(172, 23);
|
||||
this.dateTimePicker.TabIndex = 8;
|
||||
//
|
||||
// labelMaxSushi
|
||||
//
|
||||
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";
|
||||
//
|
||||
// maxSushi
|
||||
//
|
||||
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);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.textBoxAddress);
|
||||
this.Controls.Add(this.comboBoxName);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Name = "FormStore";
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private ComboBox comboBoxName;
|
||||
private TextBox textBoxAddress;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private DateTimePicker dateTimePicker;
|
||||
private DataGridViewTextBoxColumn SushiName;
|
||||
private DataGridViewTextBoxColumn Cost;
|
||||
private DataGridViewTextBoxColumn Count;
|
||||
private Label labelMaxSushi;
|
||||
private NumericUpDown maxSushi;
|
||||
}
|
||||
}
|
143
SushiBar/SushiBar/FormStore.cs
Normal file
143
SushiBar/SushiBar/FormStore.cs
Normal file
@ -0,0 +1,143 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
public partial class FormStore : Form
|
||||
{
|
||||
private readonly List<StoreViewModel>? _listStores;
|
||||
private readonly IStoreLogic _logic;
|
||||
private readonly ILogger _logger;
|
||||
public int id { get; set; }
|
||||
public FormStore(ILogger<FormStore> logger, IStoreLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_listStores = logic.ReadList(null);
|
||||
_logic = logic;
|
||||
if (_listStores != null)
|
||||
{
|
||||
comboBoxName.DisplayMember = "StoreName";
|
||||
comboBoxName.ValueMember = "Id";
|
||||
comboBoxName.DataSource = _listStores;
|
||||
comboBoxName.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData(bool extendDate = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
var model = GetStore(extendDate ? id : Convert.ToInt32(comboBoxName.SelectedValue));
|
||||
if (model != null)
|
||||
{
|
||||
comboBoxName.Text = model.StoreName;
|
||||
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(el.Item1.SushiName, el.Item1.Price, el.Item2);
|
||||
}
|
||||
}
|
||||
_logger.LogInformation("Load stores");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on load");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private IStoreModel? GetStore(int Id)
|
||||
{
|
||||
if (_listStores == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var elem in _listStores)
|
||||
{
|
||||
if (elem.Id == Id)
|
||||
{
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(comboBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Select store name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(textBoxAddress.Text))
|
||||
{
|
||||
MessageBox.Show("Fill in address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Saving store");
|
||||
|
||||
try
|
||||
{
|
||||
DateTime.TryParse(dateTimePicker.Text, out var dateTime);
|
||||
StoreBindingModel model = new()
|
||||
{
|
||||
StoreName = comboBoxName.Text,
|
||||
StoreAddress = textBoxAddress.Text,
|
||||
OpeningDate = dateTime,
|
||||
maxSushi = (int)maxSushi.Value
|
||||
};
|
||||
var searchModel = GetStore(id);
|
||||
bool operationResult;
|
||||
|
||||
if (searchModel != null)
|
||||
{
|
||||
model.Id = searchModel.Id;
|
||||
operationResult = _logic.Update(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
operationResult = _logic.Create(model);
|
||||
}
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Error on saving. Additional info below");
|
||||
}
|
||||
|
||||
MessageBox.Show("Save is successful", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on saving");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ComboBoxName_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
LoadData(false);
|
||||
}
|
||||
|
||||
private void FormStore_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
78
SushiBar/SushiBar/FormStore.resx
Normal file
78
SushiBar/SushiBar/FormStore.resx
Normal file
@ -0,0 +1,78 @@
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
142
SushiBar/SushiBar/FormStoreReplenishment.Designer.cs
generated
Normal file
142
SushiBar/SushiBar/FormStoreReplenishment.Designer.cs
generated
Normal file
@ -0,0 +1,142 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class FormStoreReplenishment
|
||||
{
|
||||
/// <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.comboBoxStore = new System.Windows.Forms.ComboBox();
|
||||
this.comboBoxSushi = new System.Windows.Forms.ComboBox();
|
||||
this.labelSushi = new System.Windows.Forms.Label();
|
||||
this.labelStore = new System.Windows.Forms.Label();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.labelCount = new System.Windows.Forms.Label();
|
||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// comboBoxStore
|
||||
//
|
||||
this.comboBoxStore.FormattingEnabled = true;
|
||||
this.comboBoxStore.Location = new System.Drawing.Point(73, 12);
|
||||
this.comboBoxStore.Name = "comboBoxStore";
|
||||
this.comboBoxStore.Size = new System.Drawing.Size(172, 23);
|
||||
this.comboBoxStore.TabIndex = 0;
|
||||
//
|
||||
// comboBoxSushi
|
||||
//
|
||||
this.comboBoxSushi.FormattingEnabled = true;
|
||||
this.comboBoxSushi.Location = new System.Drawing.Point(73, 41);
|
||||
this.comboBoxSushi.Name = "comboBoxSushi";
|
||||
this.comboBoxSushi.Size = new System.Drawing.Size(172, 23);
|
||||
this.comboBoxSushi.TabIndex = 1;
|
||||
//
|
||||
// labelSushi
|
||||
//
|
||||
this.labelSushi.AutoSize = true;
|
||||
this.labelSushi.Location = new System.Drawing.Point(12, 44);
|
||||
this.labelSushi.Name = "labelSushi";
|
||||
this.labelSushi.Size = new System.Drawing.Size(35, 15);
|
||||
this.labelSushi.TabIndex = 2;
|
||||
this.labelSushi.Text = "Sushi";
|
||||
//
|
||||
// labelStore
|
||||
//
|
||||
this.labelStore.AutoSize = true;
|
||||
this.labelStore.Location = new System.Drawing.Point(12, 15);
|
||||
this.labelStore.Name = "labelStore";
|
||||
this.labelStore.Size = new System.Drawing.Size(34, 15);
|
||||
this.labelStore.TabIndex = 3;
|
||||
this.labelStore.Text = "Store";
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(12, 101);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(113, 23);
|
||||
this.buttonSave.TabIndex = 4;
|
||||
this.buttonSave.Text = "Save";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(131, 101);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(114, 23);
|
||||
this.buttonCancel.TabIndex = 5;
|
||||
this.buttonCancel.Text = "Cancel";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
this.labelCount.AutoSize = true;
|
||||
this.labelCount.Location = new System.Drawing.Point(12, 75);
|
||||
this.labelCount.Name = "labelCount";
|
||||
this.labelCount.Size = new System.Drawing.Size(40, 15);
|
||||
this.labelCount.TabIndex = 6;
|
||||
this.labelCount.Text = "Count";
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
this.textBoxCount.Location = new System.Drawing.Point(73, 72);
|
||||
this.textBoxCount.Name = "textBoxCount";
|
||||
this.textBoxCount.Size = new System.Drawing.Size(172, 23);
|
||||
this.textBoxCount.TabIndex = 7;
|
||||
//
|
||||
// FormStoreReplenishment
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(257, 136);
|
||||
this.Controls.Add(this.textBoxCount);
|
||||
this.Controls.Add(this.labelCount);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.labelStore);
|
||||
this.Controls.Add(this.labelSushi);
|
||||
this.Controls.Add(this.comboBoxSushi);
|
||||
this.Controls.Add(this.comboBoxStore);
|
||||
this.Name = "FormStoreReplenishment";
|
||||
this.Text = "FormStoreReplenishment";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBoxStore;
|
||||
private ComboBox comboBoxSushi;
|
||||
private Label labelSushi;
|
||||
private Label labelStore;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private Label labelCount;
|
||||
private TextBox textBoxCount;
|
||||
}
|
||||
}
|
95
SushiBar/SushiBar/FormStoreReplenishment.cs
Normal file
95
SushiBar/SushiBar/FormStoreReplenishment.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
public partial class FormStoreReplenishment : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStoreLogic _storeLogic;
|
||||
private readonly ISushiLogic _sushiLogic;
|
||||
private readonly List<StoreViewModel>? _listStores;
|
||||
private readonly List<SushiViewModel>? _listSushi;
|
||||
public FormStoreReplenishment(ILogger<FormStoreReplenishment> logger, IStoreLogic storeLogic, ISushiLogic sushiLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_storeLogic = storeLogic;
|
||||
_sushiLogic = sushiLogic;
|
||||
_logger = logger;
|
||||
_listStores = storeLogic.ReadList(null);
|
||||
if (_listStores != null)
|
||||
{
|
||||
comboBoxStore.DisplayMember = "StoreName";
|
||||
comboBoxStore.ValueMember = "Id";
|
||||
comboBoxStore.DataSource = _listStores;
|
||||
comboBoxStore.SelectedItem = null;
|
||||
}
|
||||
|
||||
_listSushi = sushiLogic.ReadList(null);
|
||||
if (_listSushi != null)
|
||||
{
|
||||
comboBoxSushi.DisplayMember = "SushiName";
|
||||
comboBoxSushi.ValueMember = "Id";
|
||||
comboBoxSushi.DataSource = _listSushi;
|
||||
comboBoxSushi.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxStore.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Select store", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxSushi.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Select sushi", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Add sushi to store");
|
||||
|
||||
try
|
||||
{
|
||||
var sushi = _sushiLogic.ReadElement(new()
|
||||
{
|
||||
Id = (int)comboBoxSushi.SelectedValue
|
||||
});
|
||||
|
||||
if (sushi == null)
|
||||
{
|
||||
throw new Exception("Sushi is not found. Additional info below.");
|
||||
}
|
||||
|
||||
var resultOperation = _storeLogic.SupplySushi(
|
||||
model: new() { Id = (int)comboBoxStore.SelectedValue },
|
||||
sushi: sushi,
|
||||
quantity: Convert.ToInt32(textBoxCount.Text)
|
||||
);
|
||||
|
||||
if (!resultOperation)
|
||||
{
|
||||
throw new Exception("Error on saving. Additional info below.");
|
||||
}
|
||||
|
||||
MessageBox.Show("Save is successful", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on saving");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
SushiBar/SushiBar/FormStoreReplenishment.resx
Normal file
60
SushiBar/SushiBar/FormStoreReplenishment.resx
Normal 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>
|
110
SushiBar/SushiBar/FormStoreSell.Designer.cs
generated
Normal file
110
SushiBar/SushiBar/FormStoreSell.Designer.cs
generated
Normal 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;
|
||||
}
|
||||
}
|
84
SushiBar/SushiBar/FormStoreSell.cs
Normal file
84
SushiBar/SushiBar/FormStoreSell.cs
Normal 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 = "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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
SushiBar/SushiBar/FormStoreSell.resx
Normal file
60
SushiBar/SushiBar/FormStoreSell.resx
Normal 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>
|
114
SushiBar/SushiBar/FormStores.Designer.cs
generated
Normal file
114
SushiBar/SushiBar/FormStores.Designer.cs
generated
Normal file
@ -0,0 +1,114 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class FormStores
|
||||
{
|
||||
/// <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.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonRemove = new System.Windows.Forms.Button();
|
||||
this.buttonChange = new System.Windows.Forms.Button();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Location = new System.Drawing.Point(12, 12);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowTemplate.Height = 25;
|
||||
this.dataGridView.Size = new System.Drawing.Size(605, 426);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(623, 12);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(165, 23);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
this.buttonAdd.Text = "Add";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||
//
|
||||
// buttonRemove
|
||||
//
|
||||
this.buttonRemove.Location = new System.Drawing.Point(623, 41);
|
||||
this.buttonRemove.Name = "buttonRemove";
|
||||
this.buttonRemove.Size = new System.Drawing.Size(165, 23);
|
||||
this.buttonRemove.TabIndex = 2;
|
||||
this.buttonRemove.Text = "Remove";
|
||||
this.buttonRemove.UseVisualStyleBackColor = true;
|
||||
this.buttonRemove.Click += new System.EventHandler(this.ButtonRemove_Click);
|
||||
//
|
||||
// buttonChange
|
||||
//
|
||||
this.buttonChange.Location = new System.Drawing.Point(623, 70);
|
||||
this.buttonChange.Name = "buttonChange";
|
||||
this.buttonChange.Size = new System.Drawing.Size(165, 23);
|
||||
this.buttonChange.TabIndex = 3;
|
||||
this.buttonChange.Text = "Change";
|
||||
this.buttonChange.UseVisualStyleBackColor = true;
|
||||
this.buttonChange.Click += new System.EventHandler(this.ButtonChange_Click);
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
this.buttonUpdate.Location = new System.Drawing.Point(623, 99);
|
||||
this.buttonUpdate.Name = "buttonUpdate";
|
||||
this.buttonUpdate.Size = new System.Drawing.Size(165, 23);
|
||||
this.buttonUpdate.TabIndex = 4;
|
||||
this.buttonUpdate.Text = "Update";
|
||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||
this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click);
|
||||
//
|
||||
// FormStores
|
||||
//
|
||||
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.buttonUpdate);
|
||||
this.Controls.Add(this.buttonChange);
|
||||
this.Controls.Add(this.buttonRemove);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Name = "FormStores";
|
||||
this.Text = "FormStores";
|
||||
this.Load += new System.EventHandler(this.FormStores_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonAdd;
|
||||
private Button buttonRemove;
|
||||
private Button buttonChange;
|
||||
private Button buttonUpdate;
|
||||
}
|
||||
}
|
113
SushiBar/SushiBar/FormStores.cs
Normal file
113
SushiBar/SushiBar/FormStores.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
public partial class FormStores : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStoreLogic _logic;
|
||||
public FormStores(ILogger<FormStores> logger, IStoreLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["StoreName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["Sushis"].Visible = false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Load stores");
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on loading");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStore));
|
||||
|
||||
if (service is FormStore form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Delete record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Deleting store");
|
||||
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new StoreBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
{
|
||||
throw new Exception("Error on deleting. Additional info below.");
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error delete store");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonChange_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStore));
|
||||
|
||||
if (service is FormStore form)
|
||||
{
|
||||
form.id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void FormStores_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
60
SushiBar/SushiBar/FormStores.resx
Normal file
60
SushiBar/SushiBar/FormStores.resx
Normal 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>
|
226
SushiBar/SushiBar/FormSushi.Designer.cs
generated
Normal file
226
SushiBar/SushiBar/FormSushi.Designer.cs
generated
Normal file
@ -0,0 +1,226 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class FormSushi
|
||||
{
|
||||
/// <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.labelName = new System.Windows.Forms.Label();
|
||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||
this.labelCost = new System.Windows.Forms.Label();
|
||||
this.textBoxPrice = new System.Windows.Forms.TextBox();
|
||||
this.groupBox = new System.Windows.Forms.GroupBox();
|
||||
this.buttonReload = new System.Windows.Forms.Button();
|
||||
this.buttonRemove = new System.Windows.Forms.Button();
|
||||
this.buttonEdit = new System.Windows.Forms.Button();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.Value = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.groupBox.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
this.labelName.AutoSize = true;
|
||||
this.labelName.Location = new System.Drawing.Point(12, 9);
|
||||
this.labelName.Name = "labelName";
|
||||
this.labelName.Size = new System.Drawing.Size(39, 15);
|
||||
this.labelName.TabIndex = 0;
|
||||
this.labelName.Text = "Name";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
this.textBoxName.Location = new System.Drawing.Point(57, 6);
|
||||
this.textBoxName.Name = "textBoxName";
|
||||
this.textBoxName.Size = new System.Drawing.Size(589, 23);
|
||||
this.textBoxName.TabIndex = 1;
|
||||
//
|
||||
// labelCost
|
||||
//
|
||||
this.labelCost.AutoSize = true;
|
||||
this.labelCost.Location = new System.Drawing.Point(12, 41);
|
||||
this.labelCost.Name = "labelCost";
|
||||
this.labelCost.Size = new System.Drawing.Size(33, 15);
|
||||
this.labelCost.TabIndex = 2;
|
||||
this.labelCost.Text = "Price";
|
||||
//
|
||||
// textBoxPrice
|
||||
//
|
||||
this.textBoxPrice.Location = new System.Drawing.Point(57, 38);
|
||||
this.textBoxPrice.Name = "textBoxPrice";
|
||||
this.textBoxPrice.Size = new System.Drawing.Size(589, 23);
|
||||
this.textBoxPrice.TabIndex = 3;
|
||||
//
|
||||
// groupBox
|
||||
//
|
||||
this.groupBox.Controls.Add(this.buttonReload);
|
||||
this.groupBox.Controls.Add(this.buttonRemove);
|
||||
this.groupBox.Controls.Add(this.buttonEdit);
|
||||
this.groupBox.Controls.Add(this.buttonAdd);
|
||||
this.groupBox.Controls.Add(this.dataGridView);
|
||||
this.groupBox.Location = new System.Drawing.Point(15, 67);
|
||||
this.groupBox.Name = "groupBox";
|
||||
this.groupBox.Size = new System.Drawing.Size(773, 343);
|
||||
this.groupBox.TabIndex = 4;
|
||||
this.groupBox.TabStop = false;
|
||||
this.groupBox.Text = "Components";
|
||||
//
|
||||
// buttonReload
|
||||
//
|
||||
this.buttonReload.Location = new System.Drawing.Point(637, 109);
|
||||
this.buttonReload.Name = "buttonReload";
|
||||
this.buttonReload.Size = new System.Drawing.Size(130, 23);
|
||||
this.buttonReload.TabIndex = 4;
|
||||
this.buttonReload.Text = "Reload";
|
||||
this.buttonReload.UseVisualStyleBackColor = true;
|
||||
this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click);
|
||||
//
|
||||
// buttonRemove
|
||||
//
|
||||
this.buttonRemove.Location = new System.Drawing.Point(637, 80);
|
||||
this.buttonRemove.Name = "buttonRemove";
|
||||
this.buttonRemove.Size = new System.Drawing.Size(130, 23);
|
||||
this.buttonRemove.TabIndex = 3;
|
||||
this.buttonRemove.Text = "Remove";
|
||||
this.buttonRemove.UseVisualStyleBackColor = true;
|
||||
this.buttonRemove.Click += new System.EventHandler(this.ButtonRemove_Click);
|
||||
//
|
||||
// buttonEdit
|
||||
//
|
||||
this.buttonEdit.Location = new System.Drawing.Point(637, 51);
|
||||
this.buttonEdit.Name = "buttonEdit";
|
||||
this.buttonEdit.Size = new System.Drawing.Size(130, 23);
|
||||
this.buttonEdit.TabIndex = 2;
|
||||
this.buttonEdit.Text = "Edit";
|
||||
this.buttonEdit.UseVisualStyleBackColor = true;
|
||||
this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click);
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(637, 22);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(130, 23);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
this.buttonAdd.Text = "Add";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.ID,
|
||||
this.Component,
|
||||
this.Value});
|
||||
this.dataGridView.Location = new System.Drawing.Point(6, 22);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowTemplate.Height = 25;
|
||||
this.dataGridView.Size = new System.Drawing.Size(625, 315);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(658, 415);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(130, 23);
|
||||
this.buttonCancel.TabIndex = 5;
|
||||
this.buttonCancel.Text = "Cancel";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(522, 415);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(130, 23);
|
||||
this.buttonSave.TabIndex = 6;
|
||||
this.buttonSave.Text = "Save";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// ID
|
||||
//
|
||||
this.ID.HeaderText = "ID";
|
||||
this.ID.Name = "ID";
|
||||
this.ID.Visible = false;
|
||||
//
|
||||
// Component
|
||||
//
|
||||
this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
|
||||
this.Component.HeaderText = "ComponentName";
|
||||
this.Component.Name = "Component";
|
||||
//
|
||||
// Value
|
||||
//
|
||||
this.Value.HeaderText = "Count";
|
||||
this.Value.Name = "Value";
|
||||
//
|
||||
// FormSushi
|
||||
//
|
||||
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.buttonSave);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.groupBox);
|
||||
this.Controls.Add(this.textBoxPrice);
|
||||
this.Controls.Add(this.labelCost);
|
||||
this.Controls.Add(this.textBoxName);
|
||||
this.Controls.Add(this.labelName);
|
||||
this.Name = "FormSushi";
|
||||
this.Text = "FormSushi";
|
||||
this.Load += new System.EventHandler(this.FormSushi_Load);
|
||||
this.groupBox.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelName;
|
||||
private TextBox textBoxName;
|
||||
private Label labelCost;
|
||||
private TextBox textBoxPrice;
|
||||
private GroupBox groupBox;
|
||||
private Button buttonReload;
|
||||
private Button buttonRemove;
|
||||
private Button buttonEdit;
|
||||
private Button buttonAdd;
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonCancel;
|
||||
private Button buttonSave;
|
||||
private DataGridViewTextBoxColumn ID;
|
||||
private DataGridViewTextBoxColumn Component;
|
||||
private DataGridViewTextBoxColumn Value;
|
||||
}
|
||||
}
|
209
SushiBar/SushiBar/FormSushi.cs
Normal file
209
SushiBar/SushiBar/FormSushi.cs
Normal file
@ -0,0 +1,209 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
public partial class FormSushi : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISushiLogic _logic;
|
||||
private int? _id;
|
||||
private Dictionary<int, (IComponentModel, int)> _sushiComponents;
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormSushi(ILogger<FormSushi> logger, ISushiLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_sushiComponents = new Dictionary<int, (IComponentModel, int)>();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Load components");
|
||||
try
|
||||
{
|
||||
if (_sushiComponents != null)
|
||||
{
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var pc in _sushiComponents)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
|
||||
}
|
||||
textBoxPrice.Text = CalcPrice().ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error loading components for sushi");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private double CalcPrice()
|
||||
{
|
||||
double price = 0;
|
||||
foreach (var elem in _sushiComponents)
|
||||
{
|
||||
price += (elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2;
|
||||
}
|
||||
return Math.Round(price * 1.1, 2);
|
||||
|
||||
}
|
||||
|
||||
private void FormSushi_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
_logger.LogInformation("Load records");
|
||||
try
|
||||
{
|
||||
var view = _logic.ReadElement(new SushiSearchModel { Id = _id.Value });
|
||||
if (view != null)
|
||||
{
|
||||
textBoxName.Text = view.SushiName;
|
||||
textBoxPrice.Text = view.Price.ToString();
|
||||
_sushiComponents = view.SushiComponents ?? new Dictionary<int, (IComponentModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on loading");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent));
|
||||
if (service is FormSushiComponent form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.ComponentModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Add new component:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
|
||||
if (_sushiComponents.ContainsKey(form.Id))
|
||||
{
|
||||
_sushiComponents[form.Id] = (form.ComponentModel, form.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
_sushiComponents.Add(form.Id, (form.ComponentModel, form.Count));
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonEdit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent));
|
||||
if (service is FormSushiComponent form)
|
||||
{
|
||||
int id =
|
||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
||||
form.Id = id;
|
||||
form.Count = _sushiComponents[id].Item2;
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.ComponentModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Edit component:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
|
||||
_sushiComponents[form.Id] = (form.ComponentModel,form.Count);
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Delte record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Deleting component: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value);
|
||||
_sushiComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonReload_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Fill in name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxPrice.Text))
|
||||
{
|
||||
MessageBox.Show("Fill in cost", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (_sushiComponents == null || _sushiComponents.Count == 0)
|
||||
{
|
||||
MessageBox.Show("Fill in components", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Saving component");
|
||||
try
|
||||
{
|
||||
var model = new SushiBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
SushiName = textBoxName.Text,
|
||||
Price = Convert.ToDouble(textBoxPrice.Text),
|
||||
SushiComponents = _sushiComponents
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||
_logic.Create(model);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Error on saving. Additional info below.");
|
||||
}
|
||||
MessageBox.Show("Saving is successful", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on saving");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
69
SushiBar/SushiBar/FormSushi.resx
Normal file
69
SushiBar/SushiBar/FormSushi.resx
Normal file
@ -0,0 +1,69 @@
|
||||
<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>
|
||||
<metadata name="ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Component.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Value.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
119
SushiBar/SushiBar/FormSushiComponent.Designer.cs
generated
Normal file
119
SushiBar/SushiBar/FormSushiComponent.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class FormSushiComponent
|
||||
{
|
||||
/// <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.labelComp = new System.Windows.Forms.Label();
|
||||
this.comboBoxComponent = new System.Windows.Forms.ComboBox();
|
||||
this.labelCount = new System.Windows.Forms.Label();
|
||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// labelComp
|
||||
//
|
||||
this.labelComp.AutoSize = true;
|
||||
this.labelComp.Location = new System.Drawing.Point(12, 9);
|
||||
this.labelComp.Name = "labelComp";
|
||||
this.labelComp.Size = new System.Drawing.Size(71, 15);
|
||||
this.labelComp.TabIndex = 0;
|
||||
this.labelComp.Text = "Component";
|
||||
//
|
||||
// comboBoxComponent
|
||||
//
|
||||
this.comboBoxComponent.FormattingEnabled = true;
|
||||
this.comboBoxComponent.Location = new System.Drawing.Point(89, 6);
|
||||
this.comboBoxComponent.Name = "comboBoxComponent";
|
||||
this.comboBoxComponent.Size = new System.Drawing.Size(224, 23);
|
||||
this.comboBoxComponent.TabIndex = 1;
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
this.labelCount.AutoSize = true;
|
||||
this.labelCount.Location = new System.Drawing.Point(12, 41);
|
||||
this.labelCount.Name = "labelCount";
|
||||
this.labelCount.Size = new System.Drawing.Size(40, 15);
|
||||
this.labelCount.TabIndex = 2;
|
||||
this.labelCount.Text = "Count";
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
this.textBoxCount.Location = new System.Drawing.Point(89, 38);
|
||||
this.textBoxCount.Name = "textBoxCount";
|
||||
this.textBoxCount.Size = new System.Drawing.Size(224, 23);
|
||||
this.textBoxCount.TabIndex = 3;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(12, 67);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(143, 23);
|
||||
this.buttonSave.TabIndex = 4;
|
||||
this.buttonSave.Text = "Save";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(161, 67);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(152, 23);
|
||||
this.buttonCancel.TabIndex = 5;
|
||||
this.buttonCancel.Text = "Cancel";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// FormSushiComponent
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(325, 99);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.textBoxCount);
|
||||
this.Controls.Add(this.labelCount);
|
||||
this.Controls.Add(this.comboBoxComponent);
|
||||
this.Controls.Add(this.labelComp);
|
||||
this.Name = "FormSushiComponent";
|
||||
this.Text = "FormSushiComponent";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelComp;
|
||||
private ComboBox comboBoxComponent;
|
||||
private Label labelCount;
|
||||
private TextBox textBoxCount;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
81
SushiBar/SushiBar/FormSushiComponent.cs
Normal file
81
SushiBar/SushiBar/FormSushiComponent.cs
Normal file
@ -0,0 +1,81 @@
|
||||
using Microsoft.VisualBasic.Logging;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
public partial class FormSushiComponent: Form
|
||||
{
|
||||
private readonly List<ComponentViewModel>? _list;
|
||||
public int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(comboBoxComponent.SelectedValue);
|
||||
}
|
||||
set
|
||||
{
|
||||
comboBoxComponent.SelectedValue = value;
|
||||
}
|
||||
}
|
||||
public IComponentModel? ComponentModel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var elem in _list)
|
||||
{
|
||||
if (elem.Id == Id)
|
||||
{
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public int Count
|
||||
{
|
||||
get { return Convert.ToInt32(textBoxCount.Text); }
|
||||
set { textBoxCount.Text = value.ToString(); }
|
||||
}
|
||||
|
||||
public FormSushiComponent(IComponentLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_list = logic.ReadList(null);
|
||||
if (_list != null)
|
||||
{
|
||||
comboBoxComponent.DisplayMember = "ComponentName";
|
||||
comboBoxComponent.ValueMember = "Id";
|
||||
comboBoxComponent.DataSource = _list;
|
||||
comboBoxComponent.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Fill in text box count", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxComponent.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Select component", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
SushiBar/SushiBar/FormSushiComponent.resx
Normal file
60
SushiBar/SushiBar/FormSushiComponent.resx
Normal 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>
|
114
SushiBar/SushiBar/FormSushiMoreThenOne.Designer.cs
generated
Normal file
114
SushiBar/SushiBar/FormSushiMoreThenOne.Designer.cs
generated
Normal file
@ -0,0 +1,114 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class FormSushiMoreThenOne
|
||||
{
|
||||
/// <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.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonEdit = new System.Windows.Forms.Button();
|
||||
this.buttonRemove = new System.Windows.Forms.Button();
|
||||
this.buttonReload = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Location = new System.Drawing.Point(12, 12);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowTemplate.Height = 25;
|
||||
this.dataGridView.Size = new System.Drawing.Size(422, 426);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(440, 12);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(168, 23);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
this.buttonAdd.Text = "Add";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||
//
|
||||
// buttonEdit
|
||||
//
|
||||
this.buttonEdit.Location = new System.Drawing.Point(440, 41);
|
||||
this.buttonEdit.Name = "buttonEdit";
|
||||
this.buttonEdit.Size = new System.Drawing.Size(168, 23);
|
||||
this.buttonEdit.TabIndex = 2;
|
||||
this.buttonEdit.Text = "Edit";
|
||||
this.buttonEdit.UseVisualStyleBackColor = true;
|
||||
this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click);
|
||||
//
|
||||
// buttonRemove
|
||||
//
|
||||
this.buttonRemove.Location = new System.Drawing.Point(440, 70);
|
||||
this.buttonRemove.Name = "buttonRemove";
|
||||
this.buttonRemove.Size = new System.Drawing.Size(168, 23);
|
||||
this.buttonRemove.TabIndex = 3;
|
||||
this.buttonRemove.Text = "Remove";
|
||||
this.buttonRemove.UseVisualStyleBackColor = true;
|
||||
this.buttonRemove.Click += new System.EventHandler(this.ButtonRemove_Click);
|
||||
//
|
||||
// buttonReload
|
||||
//
|
||||
this.buttonReload.Location = new System.Drawing.Point(440, 99);
|
||||
this.buttonReload.Name = "buttonReload";
|
||||
this.buttonReload.Size = new System.Drawing.Size(168, 23);
|
||||
this.buttonReload.TabIndex = 4;
|
||||
this.buttonReload.Text = "Reload";
|
||||
this.buttonReload.UseVisualStyleBackColor = true;
|
||||
this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click);
|
||||
//
|
||||
// FormSushiMoreThenOne
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(620, 450);
|
||||
this.Controls.Add(this.buttonReload);
|
||||
this.Controls.Add(this.buttonRemove);
|
||||
this.Controls.Add(this.buttonEdit);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Name = "FormSushiMoreThenOne";
|
||||
this.Text = "FormSushiMoreThenOne";
|
||||
this.Load += new System.EventHandler(this.FormSushiMoreThenOne_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonAdd;
|
||||
private Button buttonEdit;
|
||||
private Button buttonRemove;
|
||||
private Button buttonReload;
|
||||
}
|
||||
}
|
102
SushiBar/SushiBar/FormSushiMoreThenOne.cs
Normal file
102
SushiBar/SushiBar/FormSushiMoreThenOne.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
public partial class FormSushiMoreThenOne : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISushiLogic _logic;
|
||||
public FormSushiMoreThenOne(ILogger<FormSushiMoreThenOne> logger, ISushiLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["SushiComponents"].Visible = false;
|
||||
}
|
||||
_logger.LogInformation("Load sushi");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on load sushi");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSushi));
|
||||
if (service is FormSushi form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonEdit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSushi));
|
||||
if (service is FormSushi form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Delete record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Delete sushi");
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new SushiBindingModel { Id = id }))
|
||||
{
|
||||
throw new Exception("Error on deleting. Additional info below.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error delete sushi");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonReload_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void FormSushiMoreThenOne_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
60
SushiBar/SushiBar/FormSushiMoreThenOne.resx
Normal file
60
SushiBar/SushiBar/FormSushiMoreThenOne.resx
Normal 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>
|
@ -1,17 +1,53 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
using SushiBarBusinessLogic.BusinessLogics;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarFileImplement.Implements;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<ISushiStorage, SushiStorage>();
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<ISushiLogic, SushiLogic>();
|
||||
services.AddTransient<IStoreStorage, StoreStorage>();
|
||||
services.AddTransient<IStoreLogic, StoreLogic>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormComponents>();
|
||||
services.AddTransient<FormCreateOrder>();
|
||||
services.AddTransient<FormSushi>();
|
||||
services.AddTransient<FormSushiComponent>();
|
||||
services.AddTransient<FormSushiMoreThenOne>();
|
||||
services.AddTransient<FormStores>();
|
||||
services.AddTransient<FormStore>();
|
||||
services.AddTransient<FormStoreReplenishment>();
|
||||
services.AddTransient<FormStoreSell>();
|
||||
}
|
||||
}
|
||||
}
|
@ -8,4 +8,15 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SushiBarBusinessLogic\SushiBarBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\SushiBarFileImplement\SushiBarFileImplement.csproj" />
|
||||
<ProjectReference Include="..\SushibarListImplement\SushibarListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
109
SushiBar/SushiBarBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
109
SushiBar/SushiBarBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
@ -0,0 +1,109 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ComponentLogic : IComponentLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_componentStorage = componentStorage;
|
||||
}
|
||||
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{Id}", model?.ComponentName, model?.Id);
|
||||
var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public ComponentViewModel? ReadElement(ComponentSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id);
|
||||
var element = _componentStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public bool Create(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_componentStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_componentStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_componentStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(ComponentBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
throw new ArgumentNullException("Name of component is empty", nameof(model.ComponentName));
|
||||
}
|
||||
if (model.Cost <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Cost must be more then zero", nameof(model.Cost));
|
||||
}
|
||||
_logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id);
|
||||
var element = _componentStorage.GetElement(new ComponentSearchModel
|
||||
{
|
||||
ComponentName = model.ComponentName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("This name is already exists");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
138
SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
138
SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
@ -0,0 +1,138 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Enums;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IStoreLogic _storeLogic;
|
||||
private readonly ISushiStorage _sushiStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IStoreLogic storeLogic, ISushiStorage sushiStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_storeLogic = storeLogic;
|
||||
_sushiStorage = sushiStorage;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (model.Status != OrderStatus.Unknown)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
|
||||
model.Status = OrderStatus.Accepted;
|
||||
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
return UpdateStatus(model, OrderStatus.Ready);
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return UpdateStatus(model, OrderStatus.Issued);
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList .Id:{Id}", model?.Id);
|
||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return UpdateStatus(model, OrderStatus.Performed);
|
||||
}
|
||||
|
||||
private bool UpdateStatus(OrderBindingModel model, OrderStatus status)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel() { Id = model.Id });
|
||||
|
||||
if (model.Status + 1 != status)
|
||||
{
|
||||
_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.Issued)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
}
|
||||
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
model.Status--;
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Order. OrderId:{Id} .Count:{Count} .Sum:{Sum} .Status{Status} .DateCreate{DateCreate}", model.Id, model.Count, model.Sum, model.Status.ToString(), model.DateCreate.ToString());
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel
|
||||
{
|
||||
Id = model.Id
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("This name is already exists");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
289
SushiBar/SushiBarBusinessLogic/BusinessLogics/StoreLogic.cs
Normal file
289
SushiBar/SushiBarBusinessLogic/BusinessLogics/StoreLogic.cs
Normal file
@ -0,0 +1,289 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class StoreLogic : IStoreLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStoreStorage _storeStorage;
|
||||
|
||||
public StoreLogic(ILogger<StoreLogic> logger, IStoreStorage storeStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_storeStorage = storeStorage;
|
||||
}
|
||||
|
||||
public bool AddPackage(StoreSearchModel model, ISushiModel sushi, int quantity)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (quantity <= 0)
|
||||
{
|
||||
throw new ArgumentException("Quantity must be more then zero", nameof(quantity));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddPackageInStore. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id);
|
||||
|
||||
var element = _storeStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("AddPackageInStore element not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddPackageInStore find. Id:{Id}", element.Id);
|
||||
|
||||
if (element.Sushis.TryGetValue(sushi.Id, out var pair))
|
||||
{
|
||||
element.Sushis[sushi.Id] = (sushi, quantity + pair.Item2);
|
||||
_logger.LogInformation("AddPackageInStore. Has been added {quantity} {package} in {StoreName}", quantity, sushi.SushiName, element.StoreName);
|
||||
}
|
||||
else
|
||||
{
|
||||
element.Sushis[sushi.Id] = (sushi, quantity);
|
||||
_logger.LogInformation("AddPastryInShop. Has been added {quantity} new Package {package} in {StoreName}", quantity, sushi.SushiName, element.StoreName);
|
||||
}
|
||||
|
||||
_storeStorage.Update(new()
|
||||
{
|
||||
Id = element.Id,
|
||||
StoreAddress = element.StoreAddress,
|
||||
StoreName = element.StoreName,
|
||||
OpeningDate = element.OpeningDate,
|
||||
Sushis = element.Sushis,
|
||||
maxSushi = element.maxSushi
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Create(StoreBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
model.Sushis = new();
|
||||
|
||||
if (_storeStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(StoreBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
|
||||
if (_storeStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id);
|
||||
var element = _storeStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<StoreViewModel>? ReadList(StoreSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. StoreName:{StoreName}.Id:{ Id} ", model?.StoreName, model?.Id);
|
||||
|
||||
var list = model == null ? _storeStorage.GetFullList() : _storeStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(StoreBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
if (string.IsNullOrEmpty(model.StoreName))
|
||||
{
|
||||
throw new ArgumentNullException("Store name is empty!", nameof(model.StoreName));
|
||||
}
|
||||
|
||||
if (_storeStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(StoreBindingModel model, bool withParams=true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.StoreName))
|
||||
{
|
||||
throw new ArgumentNullException("Store name is empty!", nameof(model.StoreName));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Store. StoreName:{0}.StoreAdress:{1}. Id: {2}", model.StoreName, model.StoreAddress, model.Id);
|
||||
var element = _storeStorage.GetElement(new StoreSearchModel
|
||||
{
|
||||
StoreName = model.StoreName
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id && element.StoreName == model.StoreName)
|
||||
{
|
||||
throw new InvalidOperationException("This name of store is already exists!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
113
SushiBar/SushiBarBusinessLogic/BusinessLogics/SushiLogic.cs
Normal file
113
SushiBar/SushiBarBusinessLogic/BusinessLogics/SushiLogic.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class SushiLogic : ISushiLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISushiStorage _sushiStorage;
|
||||
|
||||
public SushiLogic(ILogger<ComponentLogic> logger, ISushiStorage sushiStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_sushiStorage = sushiStorage;
|
||||
}
|
||||
|
||||
public bool Create(SushiBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_sushiStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(SushiBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_sushiStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public SushiViewModel? ReadElement(SushiSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. SushiName:{SushiName}.Id:{Id}", model.SushiName, model.Id);
|
||||
var element = _sushiStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<SushiViewModel>? ReadList(SushiSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. SushiName:{SushiName}.Id:{Id}", model?.SushiName, model?.Id);
|
||||
var list = model == null ? _sushiStorage.GetFullList() : _sushiStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(SushiBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_sushiStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(SushiBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.SushiName))
|
||||
{
|
||||
throw new ArgumentNullException("Name of sushi is empty", nameof(model.SushiName));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Price must be more then zero", nameof(model.Price));
|
||||
}
|
||||
_logger.LogInformation("Sushi. SushiName:{SushiName} .Price:{Price}. Id:{Id}", model.SushiName, model.Price, model.Id);
|
||||
var element = _sushiStorage.GetElement(new SushiSearchModel {
|
||||
SushiName = model.SushiName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("This name is already exists");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj
Normal file
17
SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,11 @@
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarContracts.BindingModels
|
||||
{
|
||||
public class ComponentBindingModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using SushiBarDataModels.Enums;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarContracts.BindingModels
|
||||
{
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int SushiId { get; set; }
|
||||
public string SushiName { get; set; } = string.Empty;
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Unknown;
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarContracts.BindingModels
|
||||
{
|
||||
public class StoreBindingModel : IStoreModel
|
||||
{
|
||||
public string StoreName { 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; }
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarContracts.BindingModels
|
||||
{
|
||||
public class SushiBindingModel : ISushiModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string SushiName { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> SushiComponents { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IComponentLogic
|
||||
{
|
||||
List<ComponentViewModel>? ReadList(ComponentSearchModel? model);
|
||||
ComponentViewModel? ReadElement(ComponentSearchModel model);
|
||||
bool Create(ComponentBindingModel model);
|
||||
bool Update(ComponentBindingModel model);
|
||||
bool Delete(ComponentBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IOrderLogic
|
||||
{
|
||||
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||
bool CreateOrder(OrderBindingModel model);
|
||||
bool TakeOrderInWork(OrderBindingModel model);
|
||||
bool FinishOrder(OrderBindingModel model);
|
||||
bool DeliveryOrder(OrderBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IStoreLogic
|
||||
{
|
||||
List<StoreViewModel>? ReadList(StoreSearchModel? model);
|
||||
StoreViewModel? ReadElement(StoreSearchModel model);
|
||||
bool Create(StoreBindingModel model);
|
||||
bool Update(StoreBindingModel model);
|
||||
bool Delete(StoreBindingModel model);
|
||||
bool SupplySushi(StoreSearchModel model, ISushiModel sushi, int quantity);
|
||||
bool CheckToSupply(ISushiModel sushi, int quantity);
|
||||
bool SellSushi(ISushiModel model, int quantity);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface ISushiLogic
|
||||
{
|
||||
List<SushiViewModel>? ReadList(SushiSearchModel? model);
|
||||
SushiViewModel? ReadElement(SushiSearchModel model);
|
||||
bool Create(SushiBindingModel model);
|
||||
bool Update(SushiBindingModel model);
|
||||
bool Delete(SushiBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace SushiBarContracts.SearchModels
|
||||
{
|
||||
public class ComponentSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ComponentName { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
namespace SushiBarContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace SushiBarContracts.SearchModels
|
||||
{
|
||||
public class StoreSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? StoreName { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace SushiBarContracts.SearchModels
|
||||
{
|
||||
public class SushiSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? SushiName { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarContracts.StoragesContracts
|
||||
{
|
||||
public interface IComponentStorage
|
||||
{
|
||||
List<ComponentViewModel> GetFullList();
|
||||
List<ComponentViewModel> GetFilteredList(ComponentSearchModel model);
|
||||
ComponentViewModel? GetElement(ComponentSearchModel model);
|
||||
ComponentViewModel? Insert(ComponentBindingModel model);
|
||||
ComponentViewModel? Update(ComponentBindingModel model);
|
||||
ComponentViewModel? Delete(ComponentBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarContracts.StoragesContracts
|
||||
{
|
||||
public interface IOrderStorage
|
||||
{
|
||||
List<OrderViewModel> GetFullList();
|
||||
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||
OrderViewModel? GetElement(OrderSearchModel model);
|
||||
OrderViewModel? Insert(OrderBindingModel model);
|
||||
OrderViewModel? Update(OrderBindingModel model);
|
||||
OrderViewModel? Delete(OrderBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarContracts.StoragesContracts
|
||||
{
|
||||
public interface IStoreStorage
|
||||
{
|
||||
List<StoreViewModel> GetFullList();
|
||||
List<StoreViewModel> GetFilteredList(StoreSearchModel model);
|
||||
StoreViewModel? GetElement(StoreSearchModel model);
|
||||
StoreViewModel? Insert(StoreBindingModel model);
|
||||
StoreViewModel? Update(StoreBindingModel model);
|
||||
StoreViewModel? Delete(StoreBindingModel model);
|
||||
bool SellSushi(ISushiModel model, int quantity);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarContracts.StoragesContracts
|
||||
{
|
||||
public interface ISushiStorage
|
||||
{
|
||||
List<SushiViewModel> GetFullList();
|
||||
List<SushiViewModel> GetFilteredList(SushiSearchModel model);
|
||||
SushiViewModel? GetElement(SushiSearchModel model);
|
||||
SushiViewModel? Insert(SushiBindingModel model);
|
||||
SushiViewModel? Update(SushiBindingModel model);
|
||||
SushiViewModel? Delete(SushiBindingModel model);
|
||||
}
|
||||
}
|
13
SushiBar/SushiBarContracts/SushiBarContracts.csproj
Normal file
13
SushiBar/SushiBarContracts/SushiBarContracts.csproj
Normal 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="..\SushiBarModels\SushiBarDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
17
SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs
Normal file
17
SushiBar/SushiBarContracts/ViewModels/ComponentViewModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using SushiBarDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SushiBarContracts.ViewModels
|
||||
{
|
||||
public class ComponentViewModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Name of Component")]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Cost")]
|
||||
public double Cost { get; set; }
|
||||
|
||||
}
|
||||
}
|
32
SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs
Normal file
32
SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using SushiBarDataModels.Enums;
|
||||
using SushiBarDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SushiBarContracts.ViewModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Number")]
|
||||
public int Id { get; set; }
|
||||
public int SushiId { get; set; }
|
||||
|
||||
[DisplayName("Name of Product")]
|
||||
public string SushiName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Count")]
|
||||
public int Count { get; set; }
|
||||
|
||||
[DisplayName("Sum")]
|
||||
public double Sum { get; set; }
|
||||
|
||||
[DisplayName("Status")]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Unknown;
|
||||
|
||||
[DisplayName("Date Create")]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
|
||||
[DisplayName("Date Implement")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
}
|
||||
}
|
19
SushiBar/SushiBarContracts/ViewModels/StoreViewModel.cs
Normal file
19
SushiBar/SushiBarContracts/ViewModels/StoreViewModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using SushiBarDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SushiBarContracts.ViewModels
|
||||
{
|
||||
public class StoreViewModel : IStoreModel
|
||||
{
|
||||
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; init; } = string.Empty;
|
||||
[DisplayName("Address store")]
|
||||
public string StoreAddress { get; init; } = string.Empty;
|
||||
[DisplayName("Date opening")]
|
||||
public DateTime OpeningDate { get; init; } = DateTime.Now;
|
||||
}
|
||||
}
|
17
SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs
Normal file
17
SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using SushiBarDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SushiBarContracts.ViewModels
|
||||
{
|
||||
public class SushiViewModel : ISushiModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Name of Product")]
|
||||
public string SushiName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Cost")]
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> SushiComponents { get; set; } = new();
|
||||
}
|
||||
}
|
46
SushiBar/SushiBarFileImplement/DataFileSingleton.cs
Normal file
46
SushiBar/SushiBarFileImplement/DataFileSingleton.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
86
SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs
Normal file
86
SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
161
SushiBar/SushiBarFileImplement/Implements/StoreStorage.cs
Normal file
161
SushiBar/SushiBarFileImplement/Implements/StoreStorage.cs
Normal 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;
|
||||
}
|
||||
}
|
89
SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs
Normal file
89
SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
60
SushiBar/SushiBarFileImplement/Models/Component.cs
Normal file
60
SushiBar/SushiBarFileImplement/Models/Component.cs
Normal 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()));
|
||||
}
|
||||
}
|
97
SushiBar/SushiBarFileImplement/Models/Order.cs
Normal file
97
SushiBar/SushiBarFileImplement/Models/Order.cs
Normal 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()));
|
||||
}
|
||||
}
|
104
SushiBar/SushiBarFileImplement/Models/Store.cs
Normal file
104
SushiBar/SushiBarFileImplement/Models/Store.cs
Normal file
@ -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<int, int> _sushi = new();
|
||||
|
||||
public Dictionary<int, (ISushiModel, int)> 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())
|
||||
);
|
||||
}
|
||||
}
|
87
SushiBar/SushiBarFileImplement/Models/Suhsi.cs
Normal file
87
SushiBar/SushiBarFileImplement/Models/Suhsi.cs
Normal 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())
|
||||
);
|
||||
}
|
||||
}
|
13
SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj
Normal file
13
SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj
Normal 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>
|
11
SushiBar/SushiBarModels/Enums/OrderStatus.cs
Normal file
11
SushiBar/SushiBarModels/Enums/OrderStatus.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace SushiBarDataModels.Enums
|
||||
{
|
||||
public enum OrderStatus
|
||||
{
|
||||
Unknown = -1,
|
||||
Accepted = 0,
|
||||
Performed = 1,
|
||||
Ready = 2,
|
||||
Issued = 3
|
||||
}
|
||||
}
|
7
SushiBar/SushiBarModels/IId.cs
Normal file
7
SushiBar/SushiBarModels/IId.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace SushiBarDataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
8
SushiBar/SushiBarModels/Models/IComponentModel.cs
Normal file
8
SushiBar/SushiBarModels/Models/IComponentModel.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace SushiBarDataModels.Models
|
||||
{
|
||||
public interface IComponentModel : IId
|
||||
{
|
||||
string ComponentName { get; }
|
||||
double Cost { get; }
|
||||
}
|
||||
}
|
14
SushiBar/SushiBarModels/Models/IOrderModel.cs
Normal file
14
SushiBar/SushiBarModels/Models/IOrderModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using SushiBarDataModels.Enums;
|
||||
|
||||
namespace SushiBarDataModels.Models
|
||||
{
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int SushiId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
}
|
||||
}
|
11
SushiBar/SushiBarModels/Models/IStoreModel.cs
Normal file
11
SushiBar/SushiBarModels/Models/IStoreModel.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace SushiBarDataModels.Models
|
||||
{
|
||||
public interface IStoreModel : IId
|
||||
{
|
||||
public string StoreName { get; }
|
||||
public string StoreAddress { get; }
|
||||
DateTime OpeningDate { get; }
|
||||
Dictionary<int, (ISushiModel, int)> Sushis { get; }
|
||||
public int maxSushi { get; }
|
||||
}
|
||||
}
|
9
SushiBar/SushiBarModels/Models/ISushiModel.cs
Normal file
9
SushiBar/SushiBarModels/Models/ISushiModel.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace SushiBarDataModels.Models
|
||||
{
|
||||
public interface ISushiModel : IId
|
||||
{
|
||||
string SushiName { get; }
|
||||
double Price { get; }
|
||||
Dictionary<int, (IComponentModel, int)> SushiComponents { get; }
|
||||
}
|
||||
}
|
9
SushiBar/SushiBarModels/SushiBarDataModels.csproj
Normal file
9
SushiBar/SushiBarModels/SushiBarDataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
26
SushiBar/SushibarListImplement/DataListSingleton.cs
Normal file
26
SushiBar/SushibarListImplement/DataListSingleton.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using SushibarListImplement.Models;
|
||||
|
||||
namespace SushibarListImplement
|
||||
{
|
||||
public class DataListSingleton
|
||||
{
|
||||
private static DataListSingleton? _instance;
|
||||
public List<Component> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Sushi> Sushi { get; set; }
|
||||
public List<Store> Stores { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Sushi = new List<Sushi>();
|
||||
Stores = new List<Store>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
_instance ??= new DataListSingleton();
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
102
SushiBar/SushibarListImplement/Implements/ComponentStorage.cs
Normal file
102
SushiBar/SushibarListImplement/Implements/ComponentStorage.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushibarListImplement.Models;
|
||||
|
||||
namespace SushibarListImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public ComponentStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<ComponentViewModel>();
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
result.Add(component.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
var result = new List<ComponentViewModel>();
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
if (component.ComponentName.Contains(model.ComponentName))
|
||||
{
|
||||
result.Add(component.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.ComponentName) &&
|
||||
component.ComponentName == model.ComponentName) ||
|
||||
(model.Id.HasValue && component.Id == model.Id))
|
||||
{
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
if (model.Id <= component.Id)
|
||||
{
|
||||
model.Id = component.Id + 1;
|
||||
}
|
||||
}
|
||||
Component? newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Components.Add(newComponent);
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
if (component.Id == model.Id)
|
||||
{
|
||||
component.Update(model);
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Components.Count; i++)
|
||||
{
|
||||
if (_source.Components[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Components[i];
|
||||
_source.Components.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
106
SushiBar/SushibarListImplement/Implements/OrderStorage.cs
Normal file
106
SushiBar/SushibarListImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,106 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushibarListImplement.Models;
|
||||
|
||||
namespace SushibarListImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public OrderStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Sushi.Count; i++)
|
||||
{
|
||||
if (_source.Orders[i].Id == model.Id)
|
||||
{
|
||||
Order order = _source.Orders[i];
|
||||
_source.Orders.RemoveAt(i);
|
||||
return order.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (Order order in _source.Orders)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
return order.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
List<OrderViewModel> list = new();
|
||||
if (model.Id == 0)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
foreach (Order order in _source.Orders)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
list.Add(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
List<OrderViewModel> list = new();
|
||||
foreach (Order order in _source.Orders)
|
||||
{
|
||||
list.Add(order.GetViewModel);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (Order order in _source.Orders)
|
||||
{
|
||||
if (model.Id <= order.Id)
|
||||
{
|
||||
model.Id = order.Id;
|
||||
}
|
||||
}
|
||||
Order? newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Orders.Add(newOrder);
|
||||
return newOrder.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
foreach (Order order in _source.Orders)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
order.Update(model);
|
||||
return order.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
124
SushiBar/SushibarListImplement/Implements/StoreStorage.cs
Normal file
124
SushiBar/SushibarListImplement/Implements/StoreStorage.cs
Normal file
@ -0,0 +1,124 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
using SushibarListImplement.Models;
|
||||
|
||||
namespace SushibarListImplement.Implements
|
||||
{
|
||||
public class StoreStorage : IStoreStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public StoreStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
public StoreViewModel? Delete(StoreBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Stores.Count; ++i)
|
||||
{
|
||||
if (_source.Stores[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Stores[i];
|
||||
_source.Stores.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var store in _source.Stores)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.StoreName) && store.StoreName == model.StoreName) || (model.Id.HasValue && store.Id == model.Id))
|
||||
{
|
||||
return store.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<StoreViewModel> GetFilteredList(StoreSearchModel model)
|
||||
{
|
||||
var result = new List<StoreViewModel>();
|
||||
|
||||
if (string.IsNullOrEmpty(model.StoreName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach (var store in _source.Stores)
|
||||
{
|
||||
if (store.StoreName.Contains(model.StoreName))
|
||||
{
|
||||
result.Add(store.GetViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<StoreViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<StoreViewModel>();
|
||||
|
||||
foreach (var store in _source.Stores)
|
||||
{
|
||||
result.Add(store.GetViewModel);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public StoreViewModel? Insert(StoreBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
|
||||
foreach (var store in _source.Stores)
|
||||
{
|
||||
if (model.Id <= store.Id)
|
||||
{
|
||||
model.Id = store.Id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
var newStore = Store.Create(model);
|
||||
|
||||
if (newStore == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_source.Stores.Add(newStore);
|
||||
|
||||
return newStore.GetViewModel;
|
||||
}
|
||||
|
||||
public StoreViewModel? Update(StoreBindingModel model)
|
||||
{
|
||||
foreach (var store in _source.Stores)
|
||||
{
|
||||
if (store.Id == model.Id)
|
||||
{
|
||||
store.Update(model);
|
||||
return store.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
102
SushiBar/SushibarListImplement/Implements/SushiStorage.cs
Normal file
102
SushiBar/SushibarListImplement/Implements/SushiStorage.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushibarListImplement.Models;
|
||||
|
||||
namespace SushibarListImplement.Implements
|
||||
{
|
||||
public class SushiStorage : ISushiStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public SushiStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
public List<SushiViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<SushiViewModel>();
|
||||
foreach (var sushi in _source.Sushi)
|
||||
{
|
||||
result.Add(sushi.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<SushiViewModel> GetFilteredList(SushiSearchModel model)
|
||||
{
|
||||
var result = new List<SushiViewModel>();
|
||||
if (string.IsNullOrEmpty(model.SushiName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var sushi in _source.Sushi)
|
||||
{
|
||||
if (sushi.SushiName.Contains(model.SushiName))
|
||||
{
|
||||
result.Add(sushi.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public SushiViewModel? GetElement(SushiSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.SushiName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var sushi in _source.Sushi)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.SushiName) &&
|
||||
sushi.SushiName == model.SushiName) ||
|
||||
(model.Id.HasValue && sushi.Id == model.Id))
|
||||
{
|
||||
return sushi.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public SushiViewModel? Insert(SushiBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var sushi in _source.Sushi)
|
||||
{
|
||||
if (model.Id <= sushi.Id)
|
||||
{
|
||||
model.Id = sushi.Id + 1;
|
||||
}
|
||||
}
|
||||
Sushi? newComponent = Sushi.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Sushi.Add(newComponent);
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
public SushiViewModel? Update(SushiBindingModel model)
|
||||
{
|
||||
foreach (var sushi in _source.Sushi)
|
||||
{
|
||||
if (sushi.Id == model.Id)
|
||||
{
|
||||
sushi.Update(model);
|
||||
return sushi.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public SushiViewModel? Delete(SushiBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Sushi.Count; i++)
|
||||
{
|
||||
if (_source.Sushi[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Sushi[i];
|
||||
_source.Sushi.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
44
SushiBar/SushibarListImplement/Models/Component.cs
Normal file
44
SushiBar/SushibarListImplement/Models/Component.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushibarListImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
|
||||
public double Cost { get; set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public static Component? Create(ComponentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
public void Update(ComponentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ComponentName = model.ComponentName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
}
|
||||
}
|
67
SushiBar/SushibarListImplement/Models/Order.cs
Normal file
67
SushiBar/SushibarListImplement/Models/Order.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Enums;
|
||||
using SushiBarDataModels.Models;
|
||||
using System.Reflection;
|
||||
|
||||
namespace SushibarListImplement.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; set; } = OrderStatus.Unknown;
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; } = null;
|
||||
|
||||
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 void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
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 OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
SushiId = SushiId,
|
||||
SushiName = SushiName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
};
|
||||
}
|
||||
}
|
53
SushiBar/SushibarListImplement/Models/Store.cs
Normal file
53
SushiBar/SushibarListImplement/Models/Store.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushibarListImplement.Models
|
||||
{
|
||||
public class Store : IStoreModel
|
||||
{
|
||||
public string StoreName { 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)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Store()
|
||||
{
|
||||
Id = model.Id,
|
||||
StoreName = model.StoreName,
|
||||
StoreAddress = model.StoreAddress,
|
||||
OpeningDate = model.OpeningDate,
|
||||
Sushis = new Dictionary<int, (ISushiModel, int)>()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(StoreBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
StoreName = model.StoreName;
|
||||
StoreAddress = model.StoreAddress;
|
||||
OpeningDate = model.OpeningDate;
|
||||
Sushis = model.Sushis;
|
||||
}
|
||||
|
||||
public StoreViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
StoreName = StoreName,
|
||||
StoreAddress = StoreAddress,
|
||||
OpeningDate = OpeningDate,
|
||||
Sushis = Sushis
|
||||
};
|
||||
}
|
||||
}
|
49
SushiBar/SushibarListImplement/Models/Sushi.cs
Normal file
49
SushiBar/SushibarListImplement/Models/Sushi.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushibarListImplement.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, (IComponentModel, int)> SushiComponents
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new Dictionary<int, (IComponentModel, int)>();
|
||||
public static Sushi? Create(SushiBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Sushi()
|
||||
{
|
||||
Id = model.Id,
|
||||
SushiName = model.SushiName,
|
||||
Price = model.Price,
|
||||
SushiComponents = model.SushiComponents
|
||||
};
|
||||
}
|
||||
public void Update(SushiBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SushiName = model.SushiName;
|
||||
Price = model.Price;
|
||||
SushiComponents = model.SushiComponents;
|
||||
}
|
||||
public SushiViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
SushiName = SushiName,
|
||||
Price = Price,
|
||||
SushiComponents = SushiComponents
|
||||
};
|
||||
}
|
||||
}
|
14
SushiBar/SushibarListImplement/SushibarListImplement.csproj
Normal file
14
SushiBar/SushibarListImplement/SushibarListImplement.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
|
||||
<ProjectReference Include="..\SushiBarModels\SushiBarDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user