Compare commits
9 Commits
LabWork_2
...
LabWork_2_
| Author | SHA1 | Date | |
|---|---|---|---|
| 48e89f3b9f | |||
| a44b0f052d | |||
| 40a93a182a | |||
| a46c723d58 | |||
| 153d212184 | |||
| 4b9f66ba35 | |||
| b7ccba8acc | |||
| 665aaab1a6 | |||
| ae4eef9254 |
62
SushiBar/SushiBar/FormMain.Designer.cs
generated
62
SushiBar/SushiBar/FormMain.Designer.cs
generated
@@ -31,13 +31,16 @@
|
||||
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.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.sushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
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();
|
||||
@@ -65,11 +68,33 @@
|
||||
//
|
||||
this.directoryToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.componentsToolStripMenuItem,
|
||||
this.sushiToolStripMenuItem});
|
||||
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);
|
||||
@@ -120,25 +145,33 @@
|
||||
this.buttonReload.UseVisualStyleBackColor = true;
|
||||
this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click);
|
||||
//
|
||||
// componentsToolStripMenuItem
|
||||
// buttonReplenishment
|
||||
//
|
||||
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
|
||||
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.componentsToolStripMenuItem.Text = "Components";
|
||||
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
|
||||
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);
|
||||
//
|
||||
// sushiToolStripMenuItem
|
||||
// ButtonSell
|
||||
//
|
||||
this.sushiToolStripMenuItem.Name = "sushiToolStripMenuItem";
|
||||
this.sushiToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.sushiToolStripMenuItem.Text = "Sushi";
|
||||
this.sushiToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click);
|
||||
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);
|
||||
@@ -170,5 +203,8 @@
|
||||
private Button buttonReload;
|
||||
private ToolStripMenuItem componentsToolStripMenuItem;
|
||||
private ToolStripMenuItem sushiToolStripMenuItem;
|
||||
private ToolStripMenuItem storeToolStripMenuItem;
|
||||
private Button buttonReplenishment;
|
||||
private Button ButtonSell;
|
||||
}
|
||||
}
|
||||
@@ -170,5 +170,35 @@ namespace SushiBar
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
2
SushiBar/SushiBar/FormSushi.Designer.cs
generated
2
SushiBar/SushiBar/FormSushi.Designer.cs
generated
@@ -168,7 +168,7 @@
|
||||
//
|
||||
// ID
|
||||
//
|
||||
this.ID.HeaderText = "Id";
|
||||
this.ID.HeaderText = "ID";
|
||||
this.ID.Name = "ID";
|
||||
this.ID.Visible = false;
|
||||
//
|
||||
|
||||
@@ -35,6 +35,8 @@ namespace SushiBar
|
||||
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>();
|
||||
@@ -42,6 +44,10 @@ namespace SushiBar
|
||||
services.AddTransient<FormSushi>();
|
||||
services.AddTransient<FormSushiComponent>();
|
||||
services.AddTransient<FormSushiMoreThenOne>();
|
||||
services.AddTransient<FormStores>();
|
||||
services.AddTransient<FormStore>();
|
||||
services.AddTransient<FormStoreReplenishment>();
|
||||
services.AddTransient<FormStoreSell>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,15 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IStoreLogic _storeLogic;
|
||||
private readonly ISushiStorage _sushiStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IStoreLogic storeLogic, ISushiStorage sushiStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_storeLogic = storeLogic;
|
||||
_sushiStorage = sushiStorage;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
@@ -78,12 +82,29 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
||||
_logger.LogWarning("Status update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (status == OrderStatus.Ready)
|
||||
{
|
||||
var sushi = _sushiStorage.GetElement(new() { Id = model.SushiId });
|
||||
if (sushi == null)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + status + " operation failed. Document not found.");
|
||||
return false;
|
||||
}
|
||||
if (!_storeLogic.CheckToSupply(sushi, model.Count))
|
||||
{
|
||||
_logger.LogWarning("Status update to " + status + " operation failed. Shop supply error.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
model.Status = status;
|
||||
model.DateImplement = order?.DateImplement;
|
||||
if (model.Status == OrderStatus.Ready)
|
||||
if (model.Status == OrderStatus.Issued)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
}
|
||||
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
model.Status--;
|
||||
|
||||
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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,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,8 @@
|
||||
namespace SushiBarContracts.SearchModels
|
||||
{
|
||||
public class StoreSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? StoreName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,11 @@ namespace SushiBarFileImplement
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string SushiFileName = "Sushi.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Sushi> Sushis { get; private set; }
|
||||
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();
|
||||
@@ -20,21 +22,20 @@ namespace SushiBarFileImplement
|
||||
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)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
||||
}
|
||||
return new List<T>();
|
||||
return File.Exists(filename) ? XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList() : new List<T>();
|
||||
}
|
||||
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
|
||||
private static void SaveData<T>(IReadOnlyCollection<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
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())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -78,8 +78,7 @@ namespace SushiBarFileImplement.Models
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("SushiName", SushiName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
new XElement("SushiComponents", Components.Select(x =>
|
||||
new XElement("ProductComponent",
|
||||
new XElement("SushiComponents", Components.Select(x => new XElement("ProductComponent",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value))
|
||||
).ToArray())
|
||||
|
||||
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; }
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,13 @@ namespace SushibarListImplement
|
||||
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()
|
||||
{
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user