Compare commits
29 Commits
LabWork_5_
...
LabWork_8_
| Author | SHA1 | Date | |
|---|---|---|---|
| 2f9a01c0a6 | |||
| a9ab63ad6d | |||
| 9fc04a1d19 | |||
| cf431df304 | |||
| a35d2e05c7 | |||
| 0b6a621b48 | |||
| 3ba1703499 | |||
| d20613c3bb | |||
| 312e209cf0 | |||
| 71124169ee | |||
| c69c8ba18c | |||
| fb3d255c3a | |||
| a1fd4cff58 | |||
| 68cb1e64d1 | |||
| 324abc8c74 | |||
| 8fdc5bc1cc | |||
| 655b808c3c | |||
| fe06793f3c | |||
| 2c4cb0dbb2 | |||
| 542742e2ce | |||
| 63ba7d1a44 | |||
| 3db1002d0f | |||
| 6c683db8e9 | |||
| 6f8741b69c | |||
| d075650fc4 | |||
| 90526748c5 | |||
| bbf06c417e | |||
| 055e45b191 | |||
| 003c54db7d |
@@ -33,6 +33,7 @@ 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
|
||||
{DB81A759-B157-477C-9281-EE358968519D}.Debug|Any CPU.Deploy.0 = Debug|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
|
||||
@@ -61,6 +62,7 @@ Global
|
||||
{0ADB6C71-701C-43A7-869C-A92D7C36C4EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0ADB6C71-701C-43A7-869C-A92D7C36C4EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0ADB6C71-701C-43A7-869C-A92D7C36C4EC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0ADB6C71-701C-43A7-869C-A92D7C36C4EC}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{BF58D50B-0408-4124-8CD3-1D5DFEE83104}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BF58D50B-0408-4124-8CD3-1D5DFEE83104}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BF58D50B-0408-4124-8CD3-1D5DFEE83104}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@@ -69,6 +71,7 @@ Global
|
||||
{7D14BA90-5923-45CE-9245-EB6686B5B8F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7D14BA90-5923-45CE-9245-EB6686B5B8F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7D14BA90-5923-45CE-9245-EB6686B5B8F6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BF58D50B-0408-4124-8CD3-1D5DFEE83104}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
11
SushiBar/SushiBar/App.config
Normal file
11
SushiBar/SushiBar/App.config
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="SmtpClientHost" value="smtp.gmail.com" />
|
||||
<add key="SmtpClientPort" value="587" />
|
||||
<add key="PopHost" value="pop.gmail.com" />
|
||||
<add key="PopPort" value="995" />
|
||||
<add key="MailLogin" value="sushibarulyanosk7@gmail.com" />
|
||||
<add key="MailPassword" value="qwzj uqlx uukp bpmc" />
|
||||
</appSettings>
|
||||
</configuration>
|
||||
@@ -2,6 +2,7 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using System.Windows.Forms;
|
||||
using SushiBarContracts.Attributes;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
@@ -21,13 +22,7 @@ namespace SushiBar
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ClientFio"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Load clients");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.Attributes;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.DI;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
@@ -18,57 +20,48 @@ namespace SushiBar
|
||||
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||
if (service is FormComponent form)
|
||||
var service = DependencyManager.Instance.Resolve<FormComponent>();
|
||||
if (service is not { }) return;
|
||||
if (service.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonEdit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
if (dataGridView.SelectedRows.Count != 1) return;
|
||||
var service = DependencyManager.Instance.Resolve<FormComponent>();
|
||||
if (service is not { }) return;
|
||||
service.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (service.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
if (dataGridView.SelectedRows.Count != 1) return;
|
||||
if (MessageBox.Show("Delete record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) !=
|
||||
DialogResult.Yes) return;
|
||||
var id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Delete component");
|
||||
try
|
||||
{
|
||||
if (MessageBox.Show("Delete record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
if (!_logic.Delete(new ComponentBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
{
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,13 +79,7 @@ namespace SushiBar
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Load components");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -95,7 +95,8 @@ namespace SushiBar
|
||||
ClientId = Convert.ToInt32(comboBoxClients.SelectedValue),
|
||||
SushiName = comboBoxSushi.Text,
|
||||
Count = Convert.ToInt32(textBoxCount.Text),
|
||||
Sum = Convert.ToDouble(textBoxSum.Text)
|
||||
Sum = Convert.ToDouble(textBoxSum.Text),
|
||||
ImplementerId = null
|
||||
}) ;
|
||||
if (!operationResult)
|
||||
{
|
||||
|
||||
167
SushiBar/SushiBar/FormImplementer.Designer.cs
generated
Normal file
167
SushiBar/SushiBar/FormImplementer.Designer.cs
generated
Normal file
@@ -0,0 +1,167 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class FormImplementer
|
||||
{
|
||||
/// <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.label1 = new System.Windows.Forms.Label();
|
||||
this.textBoxFio = new System.Windows.Forms.TextBox();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.textBoxPassword = new System.Windows.Forms.TextBox();
|
||||
this.numericUpDownExp = new System.Windows.Forms.NumericUpDown();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.numericUpDownQul = new System.Windows.Forms.NumericUpDown();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownExp)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownQul)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(12, 9);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(25, 15);
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "FIO";
|
||||
//
|
||||
// textBoxFio
|
||||
//
|
||||
this.textBoxFio.Location = new System.Drawing.Point(43, 6);
|
||||
this.textBoxFio.Name = "textBoxFio";
|
||||
this.textBoxFio.Size = new System.Drawing.Size(196, 23);
|
||||
this.textBoxFio.TabIndex = 1;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(12, 41);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(57, 15);
|
||||
this.label2.TabIndex = 2;
|
||||
this.label2.Text = "Password";
|
||||
//
|
||||
// textBoxPassword
|
||||
//
|
||||
this.textBoxPassword.Location = new System.Drawing.Point(75, 38);
|
||||
this.textBoxPassword.Name = "textBoxPassword";
|
||||
this.textBoxPassword.Size = new System.Drawing.Size(164, 23);
|
||||
this.textBoxPassword.TabIndex = 3;
|
||||
//
|
||||
// numericUpDownExp
|
||||
//
|
||||
this.numericUpDownExp.Location = new System.Drawing.Point(113, 67);
|
||||
this.numericUpDownExp.Name = "numericUpDownExp";
|
||||
this.numericUpDownExp.Size = new System.Drawing.Size(126, 23);
|
||||
this.numericUpDownExp.TabIndex = 4;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(12, 69);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(95, 15);
|
||||
this.label3.TabIndex = 5;
|
||||
this.label3.Text = "Work Experience";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(12, 98);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(75, 15);
|
||||
this.label4.TabIndex = 6;
|
||||
this.label4.Text = "Qualification";
|
||||
//
|
||||
// numericUpDownQul
|
||||
//
|
||||
this.numericUpDownQul.Location = new System.Drawing.Point(93, 96);
|
||||
this.numericUpDownQul.Name = "numericUpDownQul";
|
||||
this.numericUpDownQul.Size = new System.Drawing.Size(146, 23);
|
||||
this.numericUpDownQul.TabIndex = 7;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(12, 126);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(114, 23);
|
||||
this.buttonSave.TabIndex = 8;
|
||||
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(132, 126);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(107, 23);
|
||||
this.buttonCancel.TabIndex = 9;
|
||||
this.buttonCancel.Text = "Cancel";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// FormImplementer
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(245, 157);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.numericUpDownQul);
|
||||
this.Controls.Add(this.label4);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.numericUpDownExp);
|
||||
this.Controls.Add(this.textBoxPassword);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.textBoxFio);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Name = "FormImplementer";
|
||||
this.Text = "FormImplementer";
|
||||
this.Load += new System.EventHandler(this.FormImplementer_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownExp)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownQul)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label label1;
|
||||
private TextBox textBoxFio;
|
||||
private Label label2;
|
||||
private TextBox textBoxPassword;
|
||||
private NumericUpDown numericUpDownExp;
|
||||
private Label label3;
|
||||
private Label label4;
|
||||
private NumericUpDown numericUpDownQul;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
||||
108
SushiBar/SushiBar/FormImplementer.cs
Normal file
108
SushiBar/SushiBar/FormImplementer.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
public partial class FormImplementer : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImplementerLogic _logic;
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormImplementer(ILogger<FormImplementer> logger, IImplementerLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxPassword.Text))
|
||||
{
|
||||
MessageBox.Show("Fill password", "Error",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxFio.Text))
|
||||
{
|
||||
MessageBox.Show("Fill fio", "Error",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Saving");
|
||||
try
|
||||
{
|
||||
var model = new ImplementerBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ImplementerFio = textBoxFio.Text,
|
||||
Password = textBoxPassword.Text,
|
||||
Qualification = (int)numericUpDownQul.Value,
|
||||
WorkExperience = (int)numericUpDownExp.Value,
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Error on saving. Additional info below");
|
||||
}
|
||||
MessageBox.Show("Good", "Info",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on save");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void FormImplementer_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Getting implementer");
|
||||
var view = _logic.ReadElement(new ImplementerSearchModel
|
||||
{
|
||||
Id = _id.Value
|
||||
});
|
||||
if (view != null)
|
||||
{
|
||||
textBoxFio.Text = view.ImplementerFio;
|
||||
textBoxPassword.Text = view.Password;
|
||||
numericUpDownQul.Value = view.Qualification;
|
||||
numericUpDownExp.Value = view.WorkExperience;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on getting implementer");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
SushiBar/SushiBar/FormImplementer.resx
Normal file
60
SushiBar/SushiBar/FormImplementer.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/FormImplementers.Designer.cs
generated
Normal file
114
SushiBar/SushiBar/FormImplementers.Designer.cs
generated
Normal file
@@ -0,0 +1,114 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class FormImplementers
|
||||
{
|
||||
/// <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.buttonDelete = 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(648, 426);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(666, 12);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(122, 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(666, 41);
|
||||
this.buttonEdit.Name = "buttonEdit";
|
||||
this.buttonEdit.Size = new System.Drawing.Size(122, 23);
|
||||
this.buttonEdit.TabIndex = 2;
|
||||
this.buttonEdit.Text = "Edit";
|
||||
this.buttonEdit.UseVisualStyleBackColor = true;
|
||||
this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click);
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
this.buttonDelete.Location = new System.Drawing.Point(666, 70);
|
||||
this.buttonDelete.Name = "buttonDelete";
|
||||
this.buttonDelete.Size = new System.Drawing.Size(122, 23);
|
||||
this.buttonDelete.TabIndex = 3;
|
||||
this.buttonDelete.Text = "Delete";
|
||||
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||
this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
|
||||
//
|
||||
// buttonReload
|
||||
//
|
||||
this.buttonReload.Location = new System.Drawing.Point(666, 99);
|
||||
this.buttonReload.Name = "buttonReload";
|
||||
this.buttonReload.Size = new System.Drawing.Size(122, 23);
|
||||
this.buttonReload.TabIndex = 4;
|
||||
this.buttonReload.Text = "Reload";
|
||||
this.buttonReload.UseVisualStyleBackColor = true;
|
||||
this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click);
|
||||
//
|
||||
// FormImplementers
|
||||
//
|
||||
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.buttonDelete);
|
||||
this.Controls.Add(this.buttonEdit);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Name = "FormImplementers";
|
||||
this.Text = "FormImplementers";
|
||||
this.Load += new System.EventHandler(this.FormImplementers_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonAdd;
|
||||
private Button buttonEdit;
|
||||
private Button buttonDelete;
|
||||
private Button buttonReload;
|
||||
}
|
||||
}
|
||||
96
SushiBar/SushiBar/FormImplementers.cs
Normal file
96
SushiBar/SushiBar/FormImplementers.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.Attributes;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.DI;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
public partial class FormImplementers : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImplementerLogic _logic;
|
||||
public FormImplementers(ILogger<FormImplementers> logger, IImplementerLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = DependencyManager.Instance.Resolve<FormImplementer>();
|
||||
if (service.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonEdit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count != 1) return;
|
||||
var service = DependencyManager.Instance.Resolve<FormImplementer>();
|
||||
service.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (service.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonDelete_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");
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new ImplementerBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
{
|
||||
throw new Exception("Error on delete. Addtional info below");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on delete");
|
||||
MessageBox.Show(ex.Message, "Error",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonReload_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void FormImplementers_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Load implementers");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on load");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
SushiBar/SushiBar/FormImplementers.resx
Normal file
60
SushiBar/SushiBar/FormImplementers.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>
|
||||
89
SushiBar/SushiBar/FormMails.Designer.cs
generated
Normal file
89
SushiBar/SushiBar/FormMails.Designer.cs
generated
Normal file
@@ -0,0 +1,89 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class FormMails
|
||||
{
|
||||
/// <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.PrevButton = new System.Windows.Forms.Button();
|
||||
this.NextButton = 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(776, 426);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
this.dataGridView.RowHeaderMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DataGridView_RowHeaderMouseDoubleClick);
|
||||
//
|
||||
// PrevButton
|
||||
//
|
||||
this.PrevButton.Location = new System.Drawing.Point(794, 415);
|
||||
this.PrevButton.Name = "PrevButton";
|
||||
this.PrevButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.PrevButton.TabIndex = 1;
|
||||
this.PrevButton.Text = "<";
|
||||
this.PrevButton.UseVisualStyleBackColor = true;
|
||||
this.PrevButton.Click += new System.EventHandler(this.PrevButton_Click);
|
||||
//
|
||||
// NextButton
|
||||
//
|
||||
this.NextButton.Location = new System.Drawing.Point(794, 386);
|
||||
this.NextButton.Name = "NextButton";
|
||||
this.NextButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.NextButton.TabIndex = 2;
|
||||
this.NextButton.Text = ">";
|
||||
this.NextButton.UseVisualStyleBackColor = true;
|
||||
this.NextButton.Click += new System.EventHandler(this.NextButton_Click);
|
||||
//
|
||||
// FormMails
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(882, 450);
|
||||
this.Controls.Add(this.NextButton);
|
||||
this.Controls.Add(this.PrevButton);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Name = "FormMails";
|
||||
this.Text = "FormMails";
|
||||
this.Load += new System.EventHandler(this.FormMails_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button PrevButton;
|
||||
private Button NextButton;
|
||||
}
|
||||
}
|
||||
83
SushiBar/SushiBar/FormMails.cs
Normal file
83
SushiBar/SushiBar/FormMails.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.Attributes;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.DI;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBar;
|
||||
|
||||
public partial class FormMails : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMessageInfoLogic _logic;
|
||||
private int page = 1;
|
||||
private int pageSize = 3;
|
||||
|
||||
public FormMails(ILogger<FormMails> logger, IMessageInfoLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
LoadData();
|
||||
PrevButton.Enabled = false;
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Load mails");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on load mails");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void FormMails_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void NextButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
page++;
|
||||
LoadData();
|
||||
if (((List<MessageInfoViewModel>)dataGridView.DataSource).Count == 0)
|
||||
{
|
||||
_logger.LogWarning("Out of range messages");
|
||||
page--;
|
||||
NextButton.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
PrevButton.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void PrevButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (page == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
page--;
|
||||
LoadData();
|
||||
NextButton.Enabled = true;
|
||||
if (page == 1)
|
||||
{
|
||||
PrevButton.Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void DataGridView_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
|
||||
{
|
||||
var service = DependencyManager.Instance.Resolve<FormReplyMail>();
|
||||
service.MessageId = (string)dataGridView.Rows[e.RowIndex].Cells["MessageId"].Value;
|
||||
service.ShowDialog();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
60
SushiBar/SushiBar/FormMails.resx
Normal file
60
SushiBar/SushiBar/FormMails.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>
|
||||
223
SushiBar/SushiBar/FormMain.Designer.cs
generated
223
SushiBar/SushiBar/FormMain.Designer.cs
generated
@@ -34,10 +34,18 @@
|
||||
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.sushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.storesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.implementersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.listComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.componentsOnSushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.orderListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.storeListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.storeWorkloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.orderListWithGroupByToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.startWorkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.listOrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.createBackUpMenuItem = 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();
|
||||
@@ -45,10 +53,7 @@
|
||||
this.buttonReload = new System.Windows.Forms.Button();
|
||||
this.buttonSell = new System.Windows.Forms.Button();
|
||||
this.buttonSupply = new System.Windows.Forms.Button();
|
||||
this.storeListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.storeWorkloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.orderListWithGroupByToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.mailsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@@ -59,17 +64,20 @@
|
||||
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(796, 411);
|
||||
this.dataGridView.Size = new System.Drawing.Size(1277, 411);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.directoryToolStripMenuItem,
|
||||
this.reportsToolStripMenuItem});
|
||||
this.reportsToolStripMenuItem,
|
||||
this.startWorkToolStripMenuItem,
|
||||
this.createBackUpMenuItem,
|
||||
this.mailsToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(937, 24);
|
||||
this.menuStrip1.Size = new System.Drawing.Size(1421, 24);
|
||||
this.menuStrip1.TabIndex = 1;
|
||||
this.menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
@@ -79,8 +87,8 @@
|
||||
this.componentsToolStripMenuItem,
|
||||
this.sushiToolStripMenuItem,
|
||||
this.storesToolStripMenuItem,
|
||||
this.clientsToolStripMenuItem
|
||||
});
|
||||
this.clientsToolStripMenuItem,
|
||||
this.implementersToolStripMenuItem});
|
||||
this.directoryToolStripMenuItem.Name = "directoryToolStripMenuItem";
|
||||
this.directoryToolStripMenuItem.Size = new System.Drawing.Size(67, 20);
|
||||
this.directoryToolStripMenuItem.Text = "Directory";
|
||||
@@ -88,24 +96,38 @@
|
||||
// componentsToolStripMenuItem
|
||||
//
|
||||
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
|
||||
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(147, 22);
|
||||
this.componentsToolStripMenuItem.Text = "Components";
|
||||
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
|
||||
//
|
||||
// sushiToolStripMenuItem
|
||||
//
|
||||
this.sushiToolStripMenuItem.Name = "sushiToolStripMenuItem";
|
||||
this.sushiToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.sushiToolStripMenuItem.Size = new System.Drawing.Size(147, 22);
|
||||
this.sushiToolStripMenuItem.Text = "Sushi";
|
||||
this.sushiToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click);
|
||||
//
|
||||
// storesToolStripMenuItem
|
||||
//
|
||||
this.storesToolStripMenuItem.Name = "storesToolStripMenuItem";
|
||||
this.storesToolStripMenuItem.Size = new System.Drawing.Size(143, 22);
|
||||
this.storesToolStripMenuItem.Size = new System.Drawing.Size(147, 22);
|
||||
this.storesToolStripMenuItem.Text = "Stores";
|
||||
this.storesToolStripMenuItem.Click += new System.EventHandler(this.StoreToolStripMenuItem_Click);
|
||||
//
|
||||
// clientsToolStripMenuItem
|
||||
//
|
||||
this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
|
||||
this.clientsToolStripMenuItem.Size = new System.Drawing.Size(147, 22);
|
||||
this.clientsToolStripMenuItem.Text = "Clients";
|
||||
this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
|
||||
//
|
||||
// implementersToolStripMenuItem
|
||||
//
|
||||
this.implementersToolStripMenuItem.Name = "implementersToolStripMenuItem";
|
||||
this.implementersToolStripMenuItem.Size = new System.Drawing.Size(147, 22);
|
||||
this.implementersToolStripMenuItem.Text = "Implementers";
|
||||
this.implementersToolStripMenuItem.Click += new System.EventHandler(this.ImplementersToolStripMenuItem_Click);
|
||||
//
|
||||
// reportsToolStripMenuItem
|
||||
//
|
||||
this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
@@ -140,83 +162,6 @@
|
||||
this.orderListToolStripMenuItem.Text = "Order list";
|
||||
this.orderListToolStripMenuItem.Click += new System.EventHandler(this.ListOrdersToolStripMenuItem_Click);
|
||||
//
|
||||
// buttonCreateOrder
|
||||
//
|
||||
this.buttonCreateOrder.Location = new System.Drawing.Point(814, 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(814, 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(814, 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(814, 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(814, 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);
|
||||
//
|
||||
// clientsToolStripMenuItem
|
||||
//
|
||||
this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
|
||||
this.clientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.clientsToolStripMenuItem.Text = "Clients";
|
||||
this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
|
||||
//
|
||||
// buttonSell
|
||||
//
|
||||
this.buttonSell.Location = new System.Drawing.Point(814, 415);
|
||||
this.buttonSell.Name = "buttonSell";
|
||||
this.buttonSell.Size = new System.Drawing.Size(111, 23);
|
||||
this.buttonSell.TabIndex = 7;
|
||||
this.buttonSell.Text = "Sell";
|
||||
this.buttonSell.UseVisualStyleBackColor = true;
|
||||
this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click);
|
||||
//
|
||||
// buttonSupply
|
||||
//
|
||||
this.buttonSupply.Location = new System.Drawing.Point(814, 386);
|
||||
this.buttonSupply.Name = "buttonSupply";
|
||||
this.buttonSupply.Size = new System.Drawing.Size(111, 23);
|
||||
this.buttonSupply.TabIndex = 8;
|
||||
this.buttonSupply.Text = "Supply";
|
||||
this.buttonSupply.UseVisualStyleBackColor = true;
|
||||
this.buttonSupply.Click += new System.EventHandler(this.ButtonReplenishment_Click);
|
||||
//
|
||||
// storeListToolStripMenuItem
|
||||
//
|
||||
this.storeListToolStripMenuItem.Name = "storeListToolStripMenuItem";
|
||||
@@ -238,11 +183,105 @@
|
||||
this.orderListWithGroupByToolStripMenuItem.Text = "Order list with group by";
|
||||
this.orderListWithGroupByToolStripMenuItem.Click += new System.EventHandler(this.OrderListWithGroupByToolStripMenuItem_Click);
|
||||
//
|
||||
// startWorkToolStripMenuItem
|
||||
//
|
||||
this.startWorkToolStripMenuItem.Name = "startWorkToolStripMenuItem";
|
||||
this.startWorkToolStripMenuItem.Size = new System.Drawing.Size(72, 20);
|
||||
this.startWorkToolStripMenuItem.Text = "Start work";
|
||||
this.startWorkToolStripMenuItem.Click += new System.EventHandler(this.StartWorkToolStripMenuItem_Click);
|
||||
|
||||
this.createBackUpMenuItem.Name = "createBackUpMenuItem";
|
||||
this.createBackUpMenuItem.Size = new System.Drawing.Size(72, 20);
|
||||
this.createBackUpMenuItem.Text = "Create backup";
|
||||
this.createBackUpMenuItem.Click += new System.EventHandler(this.CreateBackupStripMenuItem_Click);
|
||||
//
|
||||
// listOrdersToolStripMenuItem
|
||||
//
|
||||
this.listOrdersToolStripMenuItem.Name = "listOrdersToolStripMenuItem";
|
||||
this.listOrdersToolStripMenuItem.Size = new System.Drawing.Size(32, 19);
|
||||
//
|
||||
// buttonCreateOrder
|
||||
//
|
||||
this.buttonCreateOrder.Location = new System.Drawing.Point(1295, 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(1295, 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(1295, 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(1295, 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(1295, 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);
|
||||
//
|
||||
// buttonSell
|
||||
//
|
||||
this.buttonSell.Location = new System.Drawing.Point(1302, 415);
|
||||
this.buttonSell.Name = "buttonSell";
|
||||
this.buttonSell.Size = new System.Drawing.Size(111, 23);
|
||||
this.buttonSell.TabIndex = 7;
|
||||
this.buttonSell.Text = "Sell";
|
||||
this.buttonSell.UseVisualStyleBackColor = true;
|
||||
this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click);
|
||||
//
|
||||
// buttonSupply
|
||||
//
|
||||
this.buttonSupply.Location = new System.Drawing.Point(1302, 386);
|
||||
this.buttonSupply.Name = "buttonSupply";
|
||||
this.buttonSupply.Size = new System.Drawing.Size(111, 23);
|
||||
this.buttonSupply.TabIndex = 8;
|
||||
this.buttonSupply.Text = "Supply";
|
||||
this.buttonSupply.UseVisualStyleBackColor = true;
|
||||
this.buttonSupply.Click += new System.EventHandler(this.ButtonReplenishment_Click);
|
||||
//
|
||||
// mailsToolStripMenuItem
|
||||
//
|
||||
this.mailsToolStripMenuItem.Name = "mailsToolStripMenuItem";
|
||||
this.mailsToolStripMenuItem.Size = new System.Drawing.Size(47, 20);
|
||||
this.mailsToolStripMenuItem.Text = "Mails";
|
||||
this.mailsToolStripMenuItem.Click += new System.EventHandler(this.MailsToolStripMenuItem_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(937, 450);
|
||||
this.ClientSize = new System.Drawing.Size(1425, 450);
|
||||
this.Controls.Add(this.buttonSupply);
|
||||
this.Controls.Add(this.buttonSell);
|
||||
this.Controls.Add(this.buttonReload);
|
||||
@@ -288,5 +327,9 @@
|
||||
private ToolStripMenuItem storeListToolStripMenuItem;
|
||||
private ToolStripMenuItem storeWorkloadToolStripMenuItem;
|
||||
private ToolStripMenuItem orderListWithGroupByToolStripMenuItem;
|
||||
private ToolStripMenuItem startWorkToolStripMenuItem;
|
||||
private ToolStripMenuItem createBackUpMenuItem;
|
||||
private ToolStripMenuItem implementersToolStripMenuItem;
|
||||
private ToolStripMenuItem mailsToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarBusinessLogic.BusinessLogics;
|
||||
using SushiBarContracts.Attributes;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.DI;
|
||||
using SushiBarDataModels.Enums;
|
||||
|
||||
namespace SushiBar
|
||||
@@ -12,43 +14,34 @@ namespace SushiBar
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
private readonly IReportLogic _reportLogic;
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
|
||||
private readonly IWorkProcess _workProcess;
|
||||
private readonly IBackUpLogic _backUpLogic;
|
||||
|
||||
public FormMain(ILogger<FormMain> logger,
|
||||
IOrderLogic orderLogic,
|
||||
IReportLogic reportLogic,
|
||||
IWorkProcess workProcess,
|
||||
IBackUpLogic backUpLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_orderLogic = orderLogic;
|
||||
_reportLogic = reportLogic;
|
||||
_workProcess = workProcess;
|
||||
_backUpLogic = backUpLogic;
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Load components");
|
||||
try
|
||||
{
|
||||
var list = _orderLogic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["SushiId"].Visible = false;
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns["ClientFio"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error on load orders");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null));
|
||||
}
|
||||
|
||||
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||
if (service is FormCreateOrder form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
LoadData();
|
||||
}
|
||||
var service = DependencyManager.Instance.Resolve<FormCreateOrder>();
|
||||
service.ShowDialog();
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void ButtonSubmit_Click(object sender, EventArgs e)
|
||||
@@ -86,67 +79,63 @@ namespace SushiBar
|
||||
|
||||
private void ButtonReady_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
if (dataGridView.SelectedRows.Count != 1) return;
|
||||
var id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Order №{id}. Change status on -Ready",id);
|
||||
try
|
||||
{
|
||||
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() ?? "",
|
||||
ClientFio = dataGridView.SelectedRows[0].Cells["ClientFio"].Value.ToString() ?? "",
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString() ?? "Unknown"),
|
||||
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)
|
||||
{
|
||||
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() ?? "",
|
||||
ClientFio = dataGridView.SelectedRows[0].Cells["ClientFio"].Value.ToString() ?? "",
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString() ?? "Unknown"),
|
||||
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);
|
||||
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)
|
||||
if (dataGridView.SelectedRows.Count != 1) return;
|
||||
var id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Order №{id}. Change status on -Issued", id);
|
||||
try
|
||||
{
|
||||
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()),
|
||||
ClientFio = dataGridView.SelectedRows[0].Cells["ClientFio"].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)
|
||||
{
|
||||
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()),
|
||||
ClientFio = dataGridView.SelectedRows[0].Cells["ClientFio"].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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,21 +151,14 @@ namespace SushiBar
|
||||
|
||||
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||
if (service is FormComponents form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
var service = DependencyManager.Instance.Resolve<FormComponents>();
|
||||
service.ShowDialog();
|
||||
}
|
||||
|
||||
private void SushiToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSushiMoreThenOne));
|
||||
|
||||
if (service is FormSushiMoreThenOne form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
var service = DependencyManager.Instance.Resolve<FormSushiMoreThenOne>();
|
||||
service.ShowDialog();
|
||||
}
|
||||
|
||||
private void ListComponentsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
@@ -192,59 +174,50 @@ namespace SushiBar
|
||||
|
||||
private void ComponentsOnSushiToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSushiOnComponents));
|
||||
if (service is FormSushiOnComponents form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
var service = DependencyManager.Instance.Resolve<FormSushiOnComponents>();
|
||||
service.ShowDialog();
|
||||
}
|
||||
|
||||
private void ListOrdersToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
|
||||
if (service is FormReportOrders form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
var service = DependencyManager.Instance.Resolve<FormReportOrders>();
|
||||
service.ShowDialog();
|
||||
}
|
||||
|
||||
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
|
||||
if (service is FormClients form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
var service = DependencyManager.Instance.Resolve<FormClients>();
|
||||
service.ShowDialog();
|
||||
}
|
||||
|
||||
private void StartWorkToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
_workProcess.DoWork(DependencyManager.Instance.Resolve<IImplementerLogic>(), _orderLogic);
|
||||
MessageBox.Show("Process work is started", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
||||
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = DependencyManager.Instance.Resolve<FormImplementers>();
|
||||
service.ShowDialog();
|
||||
}
|
||||
|
||||
private void StoreToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStores));
|
||||
|
||||
if (service is FormStores form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
var service = DependencyManager.Instance.Resolve<FormStores>();
|
||||
service.ShowDialog();
|
||||
}
|
||||
|
||||
private void ButtonReplenishment_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment));
|
||||
|
||||
if (service is FormStoreReplenishment form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
var service = DependencyManager.Instance.Resolve<FormStoreReplenishment>();
|
||||
service.ShowDialog();
|
||||
}
|
||||
|
||||
private void ButtonSell_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStoreSell));
|
||||
|
||||
if (service is FormStoreSell form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
var service = DependencyManager.Instance.Resolve<FormStoreSell>();
|
||||
service.ShowDialog();
|
||||
}
|
||||
|
||||
private void StoreListToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
@@ -260,21 +233,34 @@ namespace SushiBar
|
||||
|
||||
private void StoreWorkloadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStoreWorkload));
|
||||
|
||||
if (service is FormStoreWorkload form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
var service = DependencyManager.Instance.Resolve<FormStoreWorkload>();
|
||||
service.ShowDialog();
|
||||
}
|
||||
|
||||
private void OrderListWithGroupByToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrdersGroupByDate));
|
||||
var service = DependencyManager.Instance.Resolve<FormReportOrdersGroupByDate>();
|
||||
service.ShowDialog();
|
||||
}
|
||||
|
||||
if (service is FormReportOrdersGroupByDate form)
|
||||
private void MailsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = DependencyManager.Instance.Resolve<FormMails>();
|
||||
service.ShowDialog();
|
||||
}
|
||||
|
||||
private void CreateBackupStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
form.ShowDialog();
|
||||
var fbd = new FolderBrowserDialog();
|
||||
if (fbd.ShowDialog() != DialogResult.OK) return;
|
||||
_backUpLogic.CreateBackUp(new BackUpSaveBindingModel { FolderName = fbd.SelectedPath });
|
||||
MessageBox.Show("Backup is ready", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
122
SushiBar/SushiBar/FormReplyMail.Designer.cs
generated
Normal file
122
SushiBar/SushiBar/FormReplyMail.Designer.cs
generated
Normal file
@@ -0,0 +1,122 @@
|
||||
namespace SushiBar
|
||||
{
|
||||
partial class FormReplyMail
|
||||
{
|
||||
/// <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.labelClient = new System.Windows.Forms.Label();
|
||||
this.labelOrder = new System.Windows.Forms.Label();
|
||||
this.ReplyText = new System.Windows.Forms.RichTextBox();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.buttonReply = new System.Windows.Forms.Button();
|
||||
this.buttonClose = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// labelClient
|
||||
//
|
||||
this.labelClient.AutoSize = true;
|
||||
this.labelClient.Location = new System.Drawing.Point(12, 9);
|
||||
this.labelClient.Name = "labelClient";
|
||||
this.labelClient.Size = new System.Drawing.Size(38, 15);
|
||||
this.labelClient.TabIndex = 0;
|
||||
this.labelClient.Text = "label1";
|
||||
//
|
||||
// labelOrder
|
||||
//
|
||||
this.labelOrder.AutoSize = true;
|
||||
this.labelOrder.Location = new System.Drawing.Point(12, 38);
|
||||
this.labelOrder.Name = "labelOrder";
|
||||
this.labelOrder.Size = new System.Drawing.Size(38, 15);
|
||||
this.labelOrder.TabIndex = 1;
|
||||
this.labelOrder.Text = "label2";
|
||||
//
|
||||
// ReplyText
|
||||
//
|
||||
this.ReplyText.Location = new System.Drawing.Point(12, 88);
|
||||
this.ReplyText.Name = "ReplyText";
|
||||
this.ReplyText.Size = new System.Drawing.Size(776, 315);
|
||||
this.ReplyText.TabIndex = 2;
|
||||
this.ReplyText.Text = "";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(12, 70);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(59, 15);
|
||||
this.label3.TabIndex = 3;
|
||||
this.label3.Text = "Reply text";
|
||||
//
|
||||
// buttonReply
|
||||
//
|
||||
this.buttonReply.Location = new System.Drawing.Point(12, 415);
|
||||
this.buttonReply.Name = "buttonReply";
|
||||
this.buttonReply.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonReply.TabIndex = 4;
|
||||
this.buttonReply.Text = "Reply";
|
||||
this.buttonReply.UseVisualStyleBackColor = true;
|
||||
this.buttonReply.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// buttonClose
|
||||
//
|
||||
this.buttonClose.Location = new System.Drawing.Point(93, 415);
|
||||
this.buttonClose.Name = "buttonClose";
|
||||
this.buttonClose.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonClose.TabIndex = 5;
|
||||
this.buttonClose.Text = "Close";
|
||||
this.buttonClose.UseVisualStyleBackColor = true;
|
||||
this.buttonClose.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// FormReplyMail
|
||||
//
|
||||
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.buttonClose);
|
||||
this.Controls.Add(this.buttonReply);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.ReplyText);
|
||||
this.Controls.Add(this.labelOrder);
|
||||
this.Controls.Add(this.labelClient);
|
||||
this.Name = "FormReplyMail";
|
||||
this.Text = "FormReplyMail";
|
||||
this.Load += new System.EventHandler(this.FormReplyMail_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelClient;
|
||||
private Label labelOrder;
|
||||
private RichTextBox ReplyText;
|
||||
private Label label3;
|
||||
private Button buttonReply;
|
||||
private Button buttonClose;
|
||||
}
|
||||
}
|
||||
80
SushiBar/SushiBar/FormReplyMail.cs
Normal file
80
SushiBar/SushiBar/FormReplyMail.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarBusinessLogic.MailWorker;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
namespace SushiBar
|
||||
{
|
||||
public partial class FormReplyMail : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly AbstractMailWorker _mailWorker;
|
||||
private readonly IMessageInfoLogic _logic;
|
||||
private MessageInfoViewModel? _message = null;
|
||||
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
|
||||
public FormReplyMail(ILogger<FormReplyMail> logger,
|
||||
AbstractMailWorker mailWorker,
|
||||
IMessageInfoLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_mailWorker = mailWorker;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
_mailWorker.MailSendAsync(new MailSendInfoBindingModel
|
||||
{
|
||||
MailAddress = _message.SenderName,
|
||||
Subject = _message.Subject,
|
||||
Text = ReplyText.Text,
|
||||
});
|
||||
_logic.Update(new MessageInfoBindingModel
|
||||
{
|
||||
MessageId = MessageId,
|
||||
Reply = ReplyText.Text,
|
||||
IsRead = true,
|
||||
});
|
||||
MessageBox.Show("Mail sended", "Sending mail", MessageBoxButtons.OK);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void FormReplyMail_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_message = _logic.ReadElement(new MessageInfoSearchModel
|
||||
{
|
||||
MessageId = MessageId
|
||||
});
|
||||
Text += $"For {_message.SenderName}";
|
||||
labelClient.Text = _message.Subject;
|
||||
labelOrder.Text = _message.Body;
|
||||
if (!_message.IsRead)
|
||||
{
|
||||
_logic.Update(new MessageInfoBindingModel
|
||||
{
|
||||
MessageId = MessageId,
|
||||
IsRead = true,
|
||||
Reply = _message.Reply
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
SushiBar/SushiBar/FormReplyMail.resx
Normal file
60
SushiBar/SushiBar/FormReplyMail.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,6 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.DI;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
@@ -41,14 +42,10 @@ namespace SushiBar
|
||||
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStore));
|
||||
|
||||
if (service is FormStore form)
|
||||
var service = DependencyManager.Instance.Resolve<FormStore>();
|
||||
if (service.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,19 +81,14 @@ namespace SushiBar
|
||||
|
||||
private void ButtonChange_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
if (dataGridView.SelectedRows.Count != 1) return;
|
||||
var service = DependencyManager.Instance.Resolve<FormStore>();
|
||||
|
||||
service.id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
||||
if (service.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.DI;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
@@ -27,15 +28,13 @@ namespace SushiBar
|
||||
_logger.LogInformation("Load components");
|
||||
try
|
||||
{
|
||||
if (_sushiComponents != null)
|
||||
if (_sushiComponents == null) return;
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var pc in _sushiComponents)
|
||||
{
|
||||
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();
|
||||
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
|
||||
}
|
||||
textBoxPrice.Text = CalcPrice().ToString();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -82,7 +81,7 @@ namespace SushiBar
|
||||
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent));
|
||||
var service = DependencyManager.Instance.Resolve<FormSushiComponent>();
|
||||
if (service is FormSushiComponent form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
@@ -109,7 +108,7 @@ namespace SushiBar
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent));
|
||||
var service = DependencyManager.Instance.Resolve<FormSushiComponent>();
|
||||
if (service is FormSushiComponent form)
|
||||
{
|
||||
int id =
|
||||
@@ -184,7 +183,7 @@ namespace SushiBar
|
||||
SushiComponents = _sushiComponents
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||
_logic.Create(model);
|
||||
_logic.Create(model);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Error on saving. Additional info below.");
|
||||
|
||||
@@ -10,14 +10,8 @@ namespace SushiBar
|
||||
private readonly List<ComponentViewModel>? _list;
|
||||
public int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(comboBoxComponent.SelectedValue);
|
||||
}
|
||||
set
|
||||
{
|
||||
comboBoxComponent.SelectedValue = value;
|
||||
}
|
||||
get => Convert.ToInt32(comboBoxComponent.SelectedValue);
|
||||
set => comboBoxComponent.SelectedValue = value;
|
||||
}
|
||||
public IComponentModel? ComponentModel
|
||||
{
|
||||
@@ -39,21 +33,19 @@ namespace SushiBar
|
||||
}
|
||||
public int Count
|
||||
{
|
||||
get { return Convert.ToInt32(textBoxCount.Text); }
|
||||
set { textBoxCount.Text = value.ToString(); }
|
||||
get => 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;
|
||||
}
|
||||
if (_list == null) return;
|
||||
comboBoxComponent.DisplayMember = "ComponentName";
|
||||
comboBoxComponent.ValueMember = "Id";
|
||||
comboBoxComponent.DataSource = _list;
|
||||
comboBoxComponent.SelectedItem = null;
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.Attributes;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.DI;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
@@ -19,14 +21,7 @@ namespace SushiBar
|
||||
{
|
||||
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;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Load sushi");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -38,54 +33,43 @@ namespace SushiBar
|
||||
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSushi));
|
||||
if (service is FormSushi form)
|
||||
var service = DependencyManager.Instance.Resolve<FormSushi>();
|
||||
if (service.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonEdit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
if (dataGridView.SelectedRows.Count != 1) return;
|
||||
var service = DependencyManager.Instance.Resolve<FormSushi>();
|
||||
service.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (service.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
if (dataGridView.SelectedRows.Count != 1) return;
|
||||
if (MessageBox.Show("Delete record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) !=
|
||||
DialogResult.Yes) return;
|
||||
var id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Delete sushi");
|
||||
try
|
||||
{
|
||||
if (MessageBox.Show("Delete record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
if (!_logic.Delete(new SushiBindingModel { Id = id }))
|
||||
{
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,25 +22,23 @@ namespace SushiBar
|
||||
{
|
||||
Filter = "xlsx|*.xlsx"
|
||||
};
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
if (dialog.ShowDialog() != DialogResult.OK) return;
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.SaveProductComponentToExcelFile(new
|
||||
_logic.SaveProductComponentToExcelFile(new
|
||||
ReportBindingModel
|
||||
{
|
||||
FileName = dialog.FileName
|
||||
});
|
||||
_logger.LogInformation("Saving list sushi on components");
|
||||
_logger.LogInformation("Saving list sushi on components");
|
||||
|
||||
MessageBox.Show("Success", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения списка изделий по компонентам");
|
||||
MessageBox.Show("Success", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения списка изделий по компонентам");
|
||||
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,19 +47,16 @@ namespace SushiBar
|
||||
try
|
||||
{
|
||||
var dict = _logic.GetSushi();
|
||||
if (dict != null)
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var elem in dict)
|
||||
{
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var elem in dict)
|
||||
dataGridView.Rows.Add(elem.SushiName, "", "");
|
||||
foreach (var listElem in elem.Components)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { elem.SushiName, "", "" });
|
||||
foreach (var listElem in elem.Components)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
|
||||
}
|
||||
dataGridView.Rows.Add(new object[] { "Count", "", elem.TotalCount });
|
||||
dataGridView.Rows.Add(Array.Empty<object>());
|
||||
dataGridView.Rows.Add("", listElem.Item1, listElem.Item2);
|
||||
}
|
||||
dataGridView.Rows.Add("Count", "", elem.TotalCount);
|
||||
dataGridView.Rows.Add(Array.Empty<object>());
|
||||
}
|
||||
_logger.LogInformation("Load list sushi on components");
|
||||
}
|
||||
|
||||
@@ -1,68 +1,84 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
using SushiBarBusinessLogic.BusinessLogics;
|
||||
using SushiBarBusinessLogic.MailWorker;
|
||||
using SushiBarBusinessLogic.OfficePackage;
|
||||
using SushiBarBusinessLogic.OfficePackage.Implements;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarDatabaseImplement.Implements;
|
||||
using SushiBarContracts.DI;
|
||||
|
||||
namespace SushiBar
|
||||
namespace SushiBar;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
internal static class Program
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
[STAThread]
|
||||
static void Main()
|
||||
ApplicationConfiguration.Initialize();
|
||||
InitDependency();
|
||||
try
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddLogging(option =>
|
||||
var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
|
||||
mailSender?.MailConfig(new MailConfigBindingModel
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
MailLogin =
|
||||
System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ??
|
||||
string.Empty,
|
||||
MailPassword =
|
||||
System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ??
|
||||
string.Empty,
|
||||
SmtpClientHost =
|
||||
System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ??
|
||||
string.Empty,
|
||||
SmtpClientPort = Convert
|
||||
.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]),
|
||||
PopHost =
|
||||
System.Configuration.ConfigurationManager.AppSettings["PopHost"] ??
|
||||
string.Empty,
|
||||
PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"])
|
||||
});
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<ISushiStorage, SushiStorage>();
|
||||
services.AddTransient<IClientStorage, ClientStorage>();
|
||||
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<ISushiLogic, SushiLogic>();
|
||||
services.AddTransient<IReportLogic, ReportLogic>();
|
||||
services.AddTransient<IClientLogic, ClientLogic>();
|
||||
|
||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
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<FormReportOrders>();
|
||||
services.AddTransient<FormSushiOnComponents>();
|
||||
services.AddTransient<FormStores>();
|
||||
services.AddTransient<FormStore>();
|
||||
services.AddTransient<FormStoreReplenishment>();
|
||||
services.AddTransient<FormStoreSell>();
|
||||
services.AddTransient<FormStoreWorkload>();
|
||||
services.AddTransient<FormReportOrdersGroupByDate>();
|
||||
services.AddTransient<FormClients>();
|
||||
var timer = new System.Threading.Timer(MailCheck!, null, 0, 100000);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
var logger = DependencyManager.Instance.Resolve<ILogger>();
|
||||
logger?.LogError(ex, "Error on working w/ email");
|
||||
}
|
||||
|
||||
Application.Run(DependencyManager.Instance.Resolve<FormMain>());
|
||||
}
|
||||
|
||||
private static void InitDependency()
|
||||
{
|
||||
DependencyManager.InitDependency();
|
||||
|
||||
DependencyManager.Instance.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
|
||||
DependencyManager.Instance.RegisterType<FormMain>();
|
||||
DependencyManager.Instance.RegisterType<FormComponent>();
|
||||
DependencyManager.Instance.RegisterType<FormComponents>();
|
||||
DependencyManager.Instance.RegisterType<FormCreateOrder>();
|
||||
DependencyManager.Instance.RegisterType<FormSushi>();
|
||||
DependencyManager.Instance.RegisterType<FormSushiComponent>();
|
||||
DependencyManager.Instance.RegisterType<FormSushiMoreThenOne>();
|
||||
DependencyManager.Instance.RegisterType<FormSushiOnComponents>();
|
||||
DependencyManager.Instance.RegisterType<FormReportOrders>();
|
||||
DependencyManager.Instance.RegisterType<FormClients>();
|
||||
DependencyManager.Instance.RegisterType<FormImplementers>();
|
||||
DependencyManager.Instance.RegisterType<FormImplementer>();
|
||||
DependencyManager.Instance.RegisterType<FormStores>();
|
||||
DependencyManager.Instance.RegisterType<FormStore>();
|
||||
DependencyManager.Instance.RegisterType<FormStoreSell>();
|
||||
DependencyManager.Instance.RegisterType<FormStoreWorkload>();
|
||||
DependencyManager.Instance.RegisterType<FormStoreReplenishment>();
|
||||
DependencyManager.Instance.RegisterType<FormMails>();
|
||||
}
|
||||
|
||||
private static void MailCheck(object obj) =>
|
||||
DependencyManager.Instance.Resolve<AbstractMailWorker>()?.MailCheck();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using SushiBarBusinessLogic.BusinessLogics;
|
||||
using SushiBarBusinessLogic.MailWorker;
|
||||
using SushiBarBusinessLogic.OfficePackage;
|
||||
using SushiBarBusinessLogic.OfficePackage.Implements;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.DI;
|
||||
|
||||
namespace SushiBarBusinessLogic;
|
||||
|
||||
public class BusinessLogicImplementationExtension : ILogicImplementationExtension
|
||||
{
|
||||
public int Priority => 0;
|
||||
|
||||
public void RegisterServices()
|
||||
{
|
||||
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
|
||||
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
|
||||
DependencyManager.Instance.RegisterType<ISushiLogic, SushiLogic>();
|
||||
DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
|
||||
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
|
||||
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
|
||||
DependencyManager.Instance.RegisterType<IStoreLogic, StoreLogic>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(isSingle: true);
|
||||
}
|
||||
}
|
||||
87
SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs
Normal file
87
SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System.IO.Compression;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarDataModels;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogics;
|
||||
|
||||
public class BackUpLogic : IBackUpLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBackUpInfo _backUpInfo;
|
||||
|
||||
public BackUpLogic(ILogger<BackUpLogic> logger, IBackUpInfo backUpInfo)
|
||||
{
|
||||
_logger = logger;
|
||||
_backUpInfo = backUpInfo;
|
||||
}
|
||||
|
||||
public void CreateBackUp(BackUpSaveBindingModel model)
|
||||
{
|
||||
_logger.LogDebug("Clear folder");
|
||||
var dirInfo = new DirectoryInfo(model.FolderName);
|
||||
|
||||
if (dirInfo.Exists)
|
||||
{
|
||||
foreach (var file in dirInfo.GetFiles())
|
||||
{
|
||||
file.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogDebug("Delete archive");
|
||||
var fileName = $"{model.FolderName}.zip";
|
||||
|
||||
if (File.Exists(fileName)) File.Delete(fileName);
|
||||
|
||||
_logger.LogDebug("Get assembly");
|
||||
var typeIId = typeof(IId);
|
||||
var assembly = typeIId.Assembly;
|
||||
|
||||
if (assembly == null)
|
||||
{
|
||||
throw new ArgumentNullException("Not found", nameof(assembly));
|
||||
}
|
||||
|
||||
var types = assembly.GetTypes();
|
||||
var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
_logger.LogDebug("Find {count} types", types.Length);
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (!type.IsInterface || type.GetInterface(typeIId.Name) == null) continue;
|
||||
var modelType = _backUpInfo.GetTypeByModelInterface(type.Name);
|
||||
|
||||
if (modelType == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Not fount model {type.Name}");
|
||||
}
|
||||
|
||||
_logger.LogDebug("Call SaveToFile method for {name} type", type.Name);
|
||||
method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName });
|
||||
}
|
||||
|
||||
_logger.LogDebug("Create zip and remove folder");
|
||||
ZipFile.CreateFromDirectory(model.FolderName, fileName);
|
||||
dirInfo.Delete(true);
|
||||
}
|
||||
|
||||
private void SaveToFile<T>(string folderName) where T : class, new()
|
||||
{
|
||||
var records = _backUpInfo.GetList<T>();
|
||||
|
||||
if (records == null)
|
||||
{
|
||||
_logger.LogWarning("{type} type get null list", typeof(T).Name);
|
||||
return;
|
||||
}
|
||||
|
||||
var jsonFormatter = new DataContractJsonSerializer(typeof(List<T>));
|
||||
using var fs = new FileStream($"{folderName}/{typeof(T).Name}.json", FileMode.OpenOrCreate);
|
||||
jsonFormatter.WriteObject(fs, records);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
@@ -73,35 +74,33 @@ public class ClientLogic : IClientLogic
|
||||
private void CheckModel(ClientBindingModel? model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.ClientFio))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model.ClientFio), "FIO must be not null");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model.Email), "EMAIL must be not null");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model.Password), "PASSWORD must be not null");
|
||||
}
|
||||
|
||||
if (!Regex.IsMatch(model.Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$", RegexOptions.IgnoreCase))
|
||||
throw new ArgumentException("Invalid format for email", nameof(model.Email));
|
||||
|
||||
if (!Regex.IsMatch(model.Password, @"^^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$", RegexOptions.IgnoreCase))
|
||||
throw new ArgumentException("Invalid format for password", nameof(model.Password));
|
||||
|
||||
_logger.LogInformation("Client .FIO:{ClientFio} .EMAIL:{Email} .Password:{Password} .Id:{Id}", model.ClientFio, model.Email, model.Password, model.Id);
|
||||
var client = _clientStorage.GetElement(new ClientSearchModel()
|
||||
var client = _clientStorage.GetElement(new ClientSearchModel
|
||||
{
|
||||
Email = model.Email
|
||||
});
|
||||
|
||||
if (client != null && client.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Email is already exists");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ImplementerLogic : IImplementerLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImplementerStorage _implementerStorage;
|
||||
public ImplementerLogic(ILogger<ImplementerLogic> logger, IImplementerStorage implementerStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_implementerStorage = implementerStorage;
|
||||
}
|
||||
|
||||
public bool Create(ImplementerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_implementerStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ImplementerBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_implementerStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? ReadElement(ImplementerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. FIO:{FIO}.Id:{ Id}",
|
||||
model.ImplementerFio, model.Id);
|
||||
var element = _implementerStorage.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<ImplementerViewModel>? ReadList(ImplementerSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. FIO:{FIO}.Id:{ Id} ", model?.ImplementerFio, model?.Id);
|
||||
var list = (model == null) ? _implementerStorage.GetFullList() :
|
||||
_implementerStorage.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(ImplementerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_implementerStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ImplementerBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.WorkExperience < 0)
|
||||
{
|
||||
throw new ArgumentException(nameof(model.WorkExperience));
|
||||
}
|
||||
if (model.Qualification < 0)
|
||||
{
|
||||
throw new ArgumentException(nameof(model.Qualification));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model.ImplementerFio));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ImplementerFio))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model.ImplementerFio));
|
||||
}
|
||||
_logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFio);
|
||||
var element = _implementerStorage.GetElement(new ImplementerSearchModel
|
||||
{
|
||||
ImplementerFio = model.ImplementerFio,
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Исполнитель с таким фио уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogics;
|
||||
|
||||
public class MessageInfoLogic : IMessageInfoLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMessageInfoStorage _messageStorage;
|
||||
|
||||
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_messageStorage = messageStorage;
|
||||
}
|
||||
|
||||
public bool Create(MessageInfoBindingModel model)
|
||||
{
|
||||
if (_messageStorage.Insert(model) != null) return true;
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. MessageId:{MessageId} .ClientId:{ClientId} .Page:{Page}",
|
||||
model?.MessageId,
|
||||
model?.ClientId,
|
||||
model.Page);
|
||||
var list = model == null ? _messageStorage.GetFullList() : _messageStorage.GetFilteredList(model);
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(MessageInfoBindingModel model)
|
||||
{
|
||||
if (_messageStorage.Update(model) != null) return true;
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? ReadElement(MessageInfoSearchModel model)
|
||||
{
|
||||
var res = _messageStorage.GetElement(model);
|
||||
if (res != null) return res;
|
||||
_logger.LogWarning("Read element operation failed");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarBusinessLogic.MailWorker;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
@@ -14,13 +15,39 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IStoreLogic _storeLogic;
|
||||
private readonly ISushiStorage _sushiStorage;
|
||||
private readonly AbstractMailWorker _mailWorker;
|
||||
private readonly IClientLogic _clientLogic;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IStoreLogic storeLogic, ISushiStorage sushiStorage)
|
||||
public OrderLogic(ILogger<OrderLogic> logger,
|
||||
IStoreLogic storeLogic,
|
||||
ISushiStorage sushiStorage,
|
||||
IOrderStorage orderStorage,
|
||||
AbstractMailWorker mailWorker,
|
||||
IClientLogic clientLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_storeLogic = storeLogic;
|
||||
_sushiStorage = sushiStorage;
|
||||
_mailWorker = mailWorker;
|
||||
_clientLogic = clientLogic;
|
||||
}
|
||||
|
||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
|
||||
var element = _orderStorage.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 CreateOrder(OrderBindingModel model)
|
||||
@@ -35,30 +62,32 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
||||
|
||||
model.Status = OrderStatus.Accepted;
|
||||
|
||||
if (_orderStorage.Insert(model) != null) return true;
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
var result = _orderStorage.Insert(model);
|
||||
if (result == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
SendOrderMessage(result.ClientId, $"Sushi Bar, Order №{result.Id}", $"Order №{result.Id} date {result.DateCreate} with sum on {result.Sum:0.00} accepted");
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
return UpdateStatus(model, OrderStatus.Ready);
|
||||
return UpdateStatus(model, OrderStatus.Issued);
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return UpdateStatus(model, OrderStatus.Issued);
|
||||
model.DateImplement = DateTime.Now;
|
||||
return UpdateStatus(model, OrderStatus.Ready);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -70,44 +99,47 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
||||
|
||||
private bool UpdateStatus(OrderBindingModel model, OrderStatus status)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel() { Id = model.Id });
|
||||
|
||||
if (model.Status + 1 != status)
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if ((int)order.Status + 1 != (int)status
|
||||
&& !(order.Status == OrderStatus.Waiting && status == OrderStatus.Ready))
|
||||
{
|
||||
_logger.LogWarning("Status update operation failed");
|
||||
return false;
|
||||
throw new InvalidOperationException($"Error on change status");
|
||||
}
|
||||
|
||||
if (status == OrderStatus.Ready)
|
||||
if (status is OrderStatus.Ready or OrderStatus.Waiting)
|
||||
{
|
||||
var sushi = _sushiStorage.GetElement(new() { Id = model.SushiId });
|
||||
if (sushi == null)
|
||||
var sushi = _sushiStorage.GetElement(new() { Id = order.SushiId });
|
||||
|
||||
if (sushi == null || !_storeLogic.CheckToSupply(sushi, order.Count))
|
||||
{
|
||||
_logger.LogWarning("Status update to " + status + " operation failed. Document not found.");
|
||||
return false;
|
||||
_logger.LogWarning($"Failed to fill magazines with product " +
|
||||
$"'{sushi?.SushiName ?? string.Empty}' " +
|
||||
$"from order {model.Id}");
|
||||
status = OrderStatus.Waiting;
|
||||
}
|
||||
if (!_storeLogic.CheckToSupply(sushi, model.Count))
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Status update to " + status + " operation failed. Shop supply error.");
|
||||
return false;
|
||||
status = OrderStatus.Ready;
|
||||
}
|
||||
}
|
||||
|
||||
model.Status = status;
|
||||
model.DateImplement = order?.DateImplement;
|
||||
if (model.Status == OrderStatus.Issued)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
}
|
||||
model.DateCreate = order.DateCreate;
|
||||
model.DateImplement ??= order.DateImplement;
|
||||
if (order.ImplementerId.HasValue)
|
||||
model.ImplementerId = order.ImplementerId;
|
||||
model.ClientId = order.ClientId;
|
||||
model.SushiId = order.SushiId;
|
||||
model.Sum = order.Sum;
|
||||
model.Count = order.Count;
|
||||
|
||||
if (_orderStorage.Update(model) == null)
|
||||
var result = _orderStorage.Update(model);
|
||||
if (result == null)
|
||||
{
|
||||
model.Status--;
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
SendOrderMessage(result.ClientId,
|
||||
$"Sushi Bar, Order №{result.Id}",
|
||||
$"Order №{model.Id} changed status on {result.Status}");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -131,5 +163,24 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
||||
throw new InvalidOperationException("This name is already exists");
|
||||
}
|
||||
}
|
||||
|
||||
private bool SendOrderMessage(int clientId, string subject, string text)
|
||||
{
|
||||
var client = _clientLogic.ReadElement(new ClientSearchModel { Id = clientId });
|
||||
|
||||
if (client == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_mailWorker.MailSendAsync(new MailSendInfoBindingModel
|
||||
{
|
||||
MailAddress = client.Email,
|
||||
Subject = subject,
|
||||
Text = text
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,95 +108,89 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Shop element found. ID: {0}, Name: {1}", store.Id, store.StoreName);
|
||||
_logger.LogInformation("Shop element found. ID: {0}, Name: {1}",
|
||||
store.Id, store.StoreName);
|
||||
var 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
|
||||
if (store.maxSushi - countSushi < quantity)
|
||||
{
|
||||
_logger.LogWarning("Required shop is overflowed");
|
||||
return false;
|
||||
}
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CheckToSupply(ISushiModel sushi, int quantity)
|
||||
{
|
||||
if (sushi == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(sushi));
|
||||
}
|
||||
|
||||
if (quantity <= 0)
|
||||
{
|
||||
_logger.LogWarning("Check then supply operation error. Document count < 0.");
|
||||
return false;
|
||||
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(quantity));
|
||||
}
|
||||
|
||||
int countSushi = 0;
|
||||
foreach (var store in _storeStorage.GetFullList())
|
||||
{
|
||||
countSushi += store.maxSushi;
|
||||
countSushi = store.Sushis.Values.Aggregate(countSushi, (current, valueTuple) => current - valueTuple.Item2);
|
||||
}
|
||||
var freePlaces = _storeStorage.GetFullList()
|
||||
.Select(x => x.maxSushi - x.Sushis
|
||||
.Select(p => p.Value.Item2).Sum()).Sum() - quantity;
|
||||
|
||||
if (countSushi - quantity < 0)
|
||||
if (freePlaces < 0)
|
||||
{
|
||||
_logger.LogWarning("Check then supply operation error. There's no place for new docs in stores.");
|
||||
_logger.LogInformation("AddReinforced. Failed to add reinforced to shop. It's full.");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var store in _storeStorage.GetFullList())
|
||||
{
|
||||
countSushi = store.Sushis.Values.Aggregate(store.maxSushi, (current, valueTuple) => current - valueTuple.Item2);
|
||||
if (countSushi == 0)
|
||||
var temp = Math
|
||||
.Min(quantity, store.maxSushi - store.Sushis.Select(x => x.Value.Item2)
|
||||
.Sum());
|
||||
|
||||
if (temp <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (countSushi - quantity >= 0)
|
||||
if (!SupplySushi(new StoreSearchModel { Id = store.Id }, sushi, temp))
|
||||
{
|
||||
if (SupplySushi(new() { Id = store.Id }, sushi, countSushi))
|
||||
countSushi = 0;
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Supply error");
|
||||
return false;
|
||||
}
|
||||
_logger.LogWarning("An error occurred while adding reinforced to shops");
|
||||
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)
|
||||
|
||||
quantity -= temp;
|
||||
|
||||
if (quantity == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SellSushi(ISushiModel model, int quantity)
|
||||
|
||||
151
SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs
Normal file
151
SushiBar/SushiBarBusinessLogic/BusinessLogics/WorkModeling.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using DocumentFormat.OpenXml.Drawing.Charts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Enums;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogics;
|
||||
|
||||
public class WorkModeling : IWorkProcess
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly Random _rnd;
|
||||
private IOrderLogic? _orderLogic;
|
||||
|
||||
public WorkModeling(ILogger<WorkModeling> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_rnd = new Random(1000);
|
||||
}
|
||||
|
||||
public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic)
|
||||
{
|
||||
_orderLogic = orderLogic;
|
||||
var implementers = implementerLogic.ReadList(null);
|
||||
if (implementers == null)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Implementers is null");
|
||||
return;
|
||||
}
|
||||
|
||||
var orders = _orderLogic.ReadList(new OrderSearchModel
|
||||
{
|
||||
Status = new() { OrderStatus.Accepted, OrderStatus.Performed, OrderStatus.Waiting }
|
||||
|
||||
});
|
||||
if (orders == null || orders.Count == 0)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Orders is null or empty");
|
||||
return;
|
||||
}
|
||||
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
|
||||
foreach (var implementer in implementers)
|
||||
{
|
||||
Task.Run(() => WorkerWorkAsync(implementer, orders));
|
||||
}
|
||||
}
|
||||
|
||||
private async Task WorkerWorkAsync(ImplementerViewModel implementer,
|
||||
List<OrderViewModel> orders)
|
||||
{
|
||||
if (_orderLogic == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
await Task.Run(() =>
|
||||
{
|
||||
foreach (var order
|
||||
in orders.Where(x => x.Status == OrderStatus.Waiting && x.ImplementerId == implementer.Id))
|
||||
{
|
||||
try
|
||||
{
|
||||
_orderLogic.FinishOrder(new OrderBindingModel { Id = order.Id });
|
||||
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await RunOrderInWork(implementer, orders);
|
||||
await Task.Run(() =>
|
||||
{
|
||||
foreach (var order
|
||||
in orders.Where(x => x.Status == OrderStatus.Accepted))
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
|
||||
_orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id,
|
||||
ImplementerId = implementer.Id
|
||||
});
|
||||
//Thread.Sleep(implementer.WorkExperience * _rnd.Next(10, 100) * order.Count);
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id
|
||||
});
|
||||
//Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task RunOrderInWork(ImplementerViewModel implementer, List<OrderViewModel> allOrders)
|
||||
{
|
||||
if (_orderLogic == null || allOrders.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Performed));
|
||||
if (runOrder == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
|
||||
|
||||
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = runOrder.Id
|
||||
});
|
||||
|
||||
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
||||
}
|
||||
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
|
||||
namespace SushiBarBusinessLogic.MailWorker;
|
||||
|
||||
public abstract class AbstractMailWorker
|
||||
{
|
||||
protected string _mailLogin = string.Empty;
|
||||
protected string _mailPassword = string.Empty;
|
||||
protected string _smtpClientHost = string.Empty;
|
||||
protected int _smtpClientPort;
|
||||
protected string _popHost = string.Empty;
|
||||
protected int _popPort;
|
||||
private readonly IMessageInfoLogic _messageInfoLogic;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientLogic _clientLogic;
|
||||
|
||||
public AbstractMailWorker(ILogger<AbstractMailWorker> logger,
|
||||
IMessageInfoLogic messageInfoLogic,
|
||||
IClientLogic clientLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_messageInfoLogic = messageInfoLogic;
|
||||
_clientLogic = clientLogic;
|
||||
}
|
||||
public void MailConfig(MailConfigBindingModel config)
|
||||
{
|
||||
_mailLogin = config.MailLogin;
|
||||
_mailPassword = config.MailPassword;
|
||||
_smtpClientHost = config.SmtpClientHost;
|
||||
_smtpClientPort = config.SmtpClientPort;
|
||||
_popHost = config.PopHost;
|
||||
_popPort = config.PopPort;
|
||||
_logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}",
|
||||
_mailLogin, _mailPassword, _smtpClientHost,
|
||||
_smtpClientPort, _popHost, _popPort);
|
||||
}
|
||||
public async void MailSendAsync(MailSendInfoBindingModel info)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_mailLogin) ||
|
||||
string.IsNullOrEmpty(_mailPassword))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(_smtpClientHost) ||
|
||||
_smtpClientPort == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(info.MailAddress) ||
|
||||
string.IsNullOrEmpty(info.Subject) ||
|
||||
string.IsNullOrEmpty(info.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress,
|
||||
info.Subject);
|
||||
await SendMailAsync(info);
|
||||
}
|
||||
public async void MailCheck()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_mailLogin) ||
|
||||
string.IsNullOrEmpty(_mailPassword))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(_popHost) || _popPort == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var list = await ReceiveMailAsync();
|
||||
_logger.LogDebug("Check Mail: {Count} new mails", list.Count);
|
||||
foreach (var mail in list)
|
||||
{
|
||||
mail.ClientId = _clientLogic.ReadElement(new ClientSearchModel { Email = mail.SenderName })?.Id;
|
||||
_messageInfoLogic.Create(mail);
|
||||
}
|
||||
}
|
||||
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
|
||||
protected abstract Task<List<MessageInfoBindingModel>> ReceiveMailAsync();
|
||||
}
|
||||
76
SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs
Normal file
76
SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
using MailKit.Net.Pop3;
|
||||
using MailKit.Security;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using AuthenticationException = System.Security.Authentication.AuthenticationException;
|
||||
|
||||
namespace SushiBarBusinessLogic.MailWorker;
|
||||
|
||||
public class MailKitWorker : AbstractMailWorker
|
||||
{
|
||||
public MailKitWorker(ILogger<MailKitWorker> logger,
|
||||
IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic)
|
||||
: base(logger, messageInfoLogic, clientLogic) {}
|
||||
|
||||
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
|
||||
{
|
||||
using var objMailMessage = new MailMessage();
|
||||
using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort);
|
||||
objMailMessage.From = new MailAddress(_mailLogin);
|
||||
objMailMessage.To.Add(new MailAddress(info.MailAddress));
|
||||
objMailMessage.Subject = info.Subject;
|
||||
objMailMessage.Body = info.Text;
|
||||
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
||||
objMailMessage.BodyEncoding = Encoding.UTF8;
|
||||
objSmtpClient.UseDefaultCredentials = false;
|
||||
objSmtpClient.EnableSsl = true;
|
||||
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
|
||||
try
|
||||
{
|
||||
await Task.Run(() => objSmtpClient.Send(objMailMessage));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
protected override async Task<List<MessageInfoBindingModel>> ReceiveMailAsync()
|
||||
{
|
||||
var list = new List<MessageInfoBindingModel>();
|
||||
using var client = new Pop3Client();
|
||||
await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
client.Connect(_popHost, _popPort, SecureSocketOptions.SslOnConnect);
|
||||
client.Authenticate(_mailLogin, _mailPassword);
|
||||
for (var i = 0; i < client.Count; i++)
|
||||
{
|
||||
var message = client.GetMessage(i);
|
||||
list.AddRange(message.From.Mailboxes.Select(mail => new MessageInfoBindingModel
|
||||
{
|
||||
DateDelivery = message.Date.DateTime,
|
||||
MessageId = message.MessageId,
|
||||
SenderName = mail.Address,
|
||||
Subject = message.Subject,
|
||||
Body = message.TextBody
|
||||
}));
|
||||
}
|
||||
}
|
||||
catch (AuthenticationException)
|
||||
{
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.Disconnect(true);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
|
||||
<PackageReference Include="MailKit" Version="4.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="PDFsharp-MigraDoc" Version="1.50.5147" />
|
||||
</ItemGroup>
|
||||
@@ -16,4 +17,8 @@
|
||||
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(targetDir)*.dll" "$(solutionDir)ImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -149,5 +149,18 @@ namespace SushiBarClientApi.Controllers
|
||||
var prod = APIClient.GetRequest<SushiViewModel>($"api/Main/GetProduct?sushiId={sushi}");
|
||||
return count * (prod?.Price ?? 1);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Mails(int page=1)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient
|
||||
.GetRequest<List<MessageInfoViewModel>>(
|
||||
$"api/client/GetMessages?clientId={APIClient.Client.Id}&page={page}"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
94
SushiBar/SushiBarClientApi/Views/Home/Mails.cshtml
Normal file
94
SushiBar/SushiBarClientApi/Views/Home/Mails.cshtml
Normal file
@@ -0,0 +1,94 @@
|
||||
@model List<SushiBarContracts.ViewModels.MessageInfoViewModel>
|
||||
@{
|
||||
ViewData["Title"] = "Mails";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Mail</h1>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Date
|
||||
</th>
|
||||
<th>
|
||||
Title
|
||||
</th>
|
||||
<th>
|
||||
Text
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.DateDelivery)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.Subject)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.Body)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="#" id="prev">Previous</a>
|
||||
</li>
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="#" id="next">Next</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<script>
|
||||
const url = document.location.href;
|
||||
const urlPart1 = url.split('=')[0];
|
||||
const urlParameter = url.split('=')[1];
|
||||
let parameter = parseInt(urlParameter);
|
||||
|
||||
const go = () => {
|
||||
window.location.href = window.location.protocol + "//" + window.location.host + `/Home/Mails?page=${parameter}`
|
||||
}
|
||||
|
||||
const paginationNext = document.getElementById("next")
|
||||
paginationNext.onclick = (e) => {
|
||||
e.preventDefault();
|
||||
if (isNaN(parameter)) {
|
||||
parameter = 1
|
||||
}
|
||||
parameter++;
|
||||
go();
|
||||
}
|
||||
|
||||
const paginationPrev = document.getElementById("prev")
|
||||
|
||||
if (isNaN(parameter) || parameter === 1) {
|
||||
paginationPrev.parentElement.classList.add("disabled");
|
||||
}
|
||||
|
||||
paginationPrev.onclick = (e) => {
|
||||
e.preventDefault();
|
||||
parameter--;
|
||||
if (parameter <= 0)
|
||||
parameter = 1
|
||||
go();
|
||||
}
|
||||
</script>
|
||||
@@ -23,13 +23,16 @@
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Index">Orders</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Privacy">My info</a>
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Privacy">PM</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Enter">Sign in</a>
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Mails">Mails</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Register">Sign up</a>
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Enter">Sign In</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Register">Sing Up</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
26
SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs
Normal file
26
SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace SushiBarContracts.Attributes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ColumnAttribute : Attribute
|
||||
{
|
||||
public ColumnAttribute(string title = "",
|
||||
bool visible = true,
|
||||
int width = 0,
|
||||
GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None,
|
||||
bool isUseAutoSize = false,
|
||||
string format = "")
|
||||
{
|
||||
Title = title;
|
||||
Visible = visible;
|
||||
Width = width;
|
||||
GridViewAutoSize = gridViewAutoSize;
|
||||
IsUseAutoSize = isUseAutoSize;
|
||||
Format = format;
|
||||
}
|
||||
public string Title { get; private set; }
|
||||
public bool Visible { get; private set; }
|
||||
public int Width { get; private set; }
|
||||
public GridViewAutoSize GridViewAutoSize { get; private set; }
|
||||
public bool IsUseAutoSize { get; private set; }
|
||||
public string Format { get; private set; }
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SushiBarContracts.Attributes;
|
||||
|
||||
public static class DataGridViewExtension
|
||||
{
|
||||
public static void FillAndConfigGrid<T>(this DataGridView grid, List<T>? data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
grid.DataSource = data;
|
||||
var type = typeof(T);
|
||||
var properties = type.GetProperties();
|
||||
foreach (DataGridViewColumn column in grid.Columns)
|
||||
{
|
||||
var property = properties.FirstOrDefault(x => x.Name == column.Name);
|
||||
if (property == null)
|
||||
{
|
||||
throw new InvalidOperationException($"In type {type.Name} not found references with {column.Name}");
|
||||
}
|
||||
var attribute = property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault();
|
||||
switch (attribute)
|
||||
{
|
||||
case null:
|
||||
throw new InvalidOperationException($"Not found attribute ColumnAttribute to property {property.Name}");
|
||||
case ColumnAttribute columnAttr:
|
||||
{
|
||||
column.DefaultCellStyle.Format = columnAttr.Format;
|
||||
column.HeaderText = columnAttr.Title;
|
||||
column.Visible = columnAttr.Visible;
|
||||
if (columnAttr.IsUseAutoSize)
|
||||
{
|
||||
column.AutoSizeMode =
|
||||
(DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode),
|
||||
columnAttr.GridViewAutoSize.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
column.Width = columnAttr.Width;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs
Normal file
13
SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace SushiBarContracts.Attributes;
|
||||
|
||||
public enum GridViewAutoSize
|
||||
{
|
||||
NotSet = 0,
|
||||
None = 1,
|
||||
ColumnHeader = 2,
|
||||
AllCellsExceptHeader = 4,
|
||||
AllCells = 6,
|
||||
DisplayedCellsExceptHeader = 8,
|
||||
DisplayedCells = 10,
|
||||
Fill = 16
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace SushiBarContracts.BindingModels;
|
||||
|
||||
public class BackUpSaveBindingModel
|
||||
{
|
||||
public string FolderName { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarContracts.BindingModels;
|
||||
|
||||
public class ImplementerBindingModel : IImplementerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ImplementerFio { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public int WorkExperience { get; set; }
|
||||
public int Qualification { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace SushiBarContracts.BindingModels;
|
||||
|
||||
public class MailConfigBindingModel
|
||||
{
|
||||
public string MailLogin { get; set; } = string.Empty;
|
||||
public string MailPassword { get; set; } = string.Empty;
|
||||
public string SmtpClientHost { get; set; } = string.Empty;
|
||||
public int SmtpClientPort { get; set; }
|
||||
public string PopHost { get; set; } = string.Empty;
|
||||
public int PopPort { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace SushiBarContracts.BindingModels;
|
||||
|
||||
public class MailSendInfoBindingModel
|
||||
{
|
||||
public string MailAddress { get; set; } = string.Empty;
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
public string Text { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarContracts.BindingModels;
|
||||
|
||||
public class MessageInfoBindingModel : IMessageInfoModel
|
||||
{
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
public int? ClientId { get; set; }
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
public DateTime DateDelivery { get; set; }
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
public string Body { get; set; } = string.Empty;
|
||||
public bool IsRead { get; set; }
|
||||
public string? Reply { get; set; }
|
||||
public int Id { get; }
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace SushiBarContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public int SushiId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
public string ClientFio { get; set; } = string.Empty;
|
||||
public string SushiName { get; set; } = string.Empty;
|
||||
public int Count { get; set; }
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
|
||||
namespace SushiBarContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IBackUpLogic
|
||||
{
|
||||
void CreateBackUp(BackUpSaveBindingModel model);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IImplementerLogic
|
||||
{
|
||||
List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model);
|
||||
ImplementerViewModel? ReadElement(ImplementerSearchModel model);
|
||||
bool Create(ImplementerBindingModel model);
|
||||
bool Update(ImplementerBindingModel model);
|
||||
bool Delete(ImplementerBindingModel model);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IMessageInfoLogic
|
||||
{
|
||||
List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
|
||||
bool Create(MessageInfoBindingModel model);
|
||||
bool Update(MessageInfoBindingModel model);
|
||||
MessageInfoViewModel? ReadElement(MessageInfoSearchModel model);
|
||||
}
|
||||
@@ -11,5 +11,6 @@ namespace SushiBarContracts.BusinessLogicsContracts
|
||||
bool TakeOrderInWork(OrderBindingModel model);
|
||||
bool FinishOrder(OrderBindingModel model);
|
||||
bool DeliveryOrder(OrderBindingModel model);
|
||||
OrderViewModel? ReadElement(OrderSearchModel model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace SushiBarContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IWorkProcess
|
||||
{
|
||||
void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
|
||||
}
|
||||
48
SushiBar/SushiBarContracts/DI/DependencyManager.cs
Normal file
48
SushiBar/SushiBarContracts/DI/DependencyManager.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SushiBarContracts.DI;
|
||||
|
||||
public class DependencyManager
|
||||
{
|
||||
private readonly IDependencyContainer _dependencyManager;
|
||||
private static DependencyManager? _manager;
|
||||
private static readonly object _locjObject = new();
|
||||
|
||||
private DependencyManager()
|
||||
{
|
||||
_dependencyManager = new UnityDependencyContainer();
|
||||
}
|
||||
|
||||
public static DependencyManager Instance { get {
|
||||
if (_manager != null)
|
||||
return
|
||||
_manager;
|
||||
lock (_locjObject) { _manager = new DependencyManager(); }
|
||||
return
|
||||
_manager; } }
|
||||
|
||||
public static void InitDependency()
|
||||
{
|
||||
var exts = ServiceProviderLoader.GetImplementationExtensions();
|
||||
foreach (var ext in exts)
|
||||
{
|
||||
if (ext == null)
|
||||
{
|
||||
throw new ArgumentNullException("Missing components to load module dependencies");
|
||||
}
|
||||
ext.RegisterServices();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddLogging(Action<ILoggingBuilder> configure) =>
|
||||
_dependencyManager.AddLogging(configure);
|
||||
|
||||
public void RegisterType<T, TU>(bool isSingle = false) where TU : class, T where T : class =>
|
||||
_dependencyManager.RegisterType<T, TU>(isSingle);
|
||||
|
||||
public void RegisterType<T>(bool isSingle = false) where T : class =>
|
||||
_dependencyManager.RegisterType<T>(isSingle);
|
||||
|
||||
public T Resolve<T>() =>
|
||||
_dependencyManager.Resolve<T>();
|
||||
}
|
||||
11
SushiBar/SushiBarContracts/DI/IDependencyContainer.cs
Normal file
11
SushiBar/SushiBarContracts/DI/IDependencyContainer.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SushiBarContracts.DI;
|
||||
|
||||
public interface IDependencyContainer
|
||||
{
|
||||
void AddLogging(Action<ILoggingBuilder> configure);
|
||||
void RegisterType<T, TU>(bool isSingle) where TU : class, T where T : class;
|
||||
void RegisterType<T>(bool isSingle) where T : class;
|
||||
T Resolve<T>();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace SushiBarContracts.DI;
|
||||
|
||||
public interface IImplementationExtension
|
||||
{
|
||||
public int Priority { get; }
|
||||
public void RegisterServices();
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace SushiBarContracts.DI;
|
||||
|
||||
public interface ILogicImplementationExtension : IImplementationExtension { }
|
||||
56
SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs
Normal file
56
SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SushiBarContracts.DI;
|
||||
|
||||
public class ServiceDependencyContainer : IDependencyContainer
|
||||
{
|
||||
private ServiceProvider? _serviceProvider;
|
||||
|
||||
private readonly ServiceCollection _serviceCollection;
|
||||
|
||||
public ServiceDependencyContainer()
|
||||
{
|
||||
_serviceCollection = new ServiceCollection();
|
||||
}
|
||||
|
||||
public void AddLogging(Action<ILoggingBuilder> configure)
|
||||
{
|
||||
_serviceCollection.AddLogging(configure);
|
||||
}
|
||||
|
||||
public void RegisterType<T, U>(bool isSingle) where U : class, T where T : class
|
||||
{
|
||||
if (isSingle)
|
||||
{
|
||||
_serviceCollection.AddSingleton<T, U>();
|
||||
}
|
||||
else
|
||||
{
|
||||
_serviceCollection.AddTransient<T, U>();
|
||||
}
|
||||
_serviceProvider = null;
|
||||
}
|
||||
|
||||
public void RegisterType<T>(bool isSingle) where T : class
|
||||
{
|
||||
if (isSingle)
|
||||
{
|
||||
_serviceCollection.AddSingleton<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
_serviceCollection.AddTransient<T>();
|
||||
}
|
||||
_serviceProvider = null;
|
||||
}
|
||||
|
||||
public T Resolve<T>()
|
||||
{
|
||||
if (_serviceProvider == null)
|
||||
{
|
||||
_serviceProvider = _serviceCollection.BuildServiceProvider();
|
||||
}
|
||||
return _serviceProvider.GetService<T>()!;
|
||||
}
|
||||
}
|
||||
56
SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs
Normal file
56
SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace SushiBarContracts.DI;
|
||||
|
||||
public static partial class ServiceProviderLoader
|
||||
{
|
||||
public static List<IImplementationExtension?> GetImplementationExtensions()
|
||||
{
|
||||
Type[] types =
|
||||
{
|
||||
typeof(ILogicImplementationExtension),
|
||||
typeof(IImplementationExtension)
|
||||
};
|
||||
var trueTypes = types.Select(x => (IImplementationExtension?)null).ToList();
|
||||
var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
|
||||
foreach (var file in files.Distinct())
|
||||
{
|
||||
Assembly asm = Assembly.LoadFrom(file);
|
||||
foreach (var t in asm.GetExportedTypes())
|
||||
{
|
||||
for (var i = 0; i < types.Length; i++)
|
||||
{
|
||||
if (t.IsClass && types[i].IsAssignableFrom(t))
|
||||
{
|
||||
if (trueTypes[i] == null)
|
||||
{
|
||||
trueTypes[i] = (IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newSource = (IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
if (newSource.Priority > trueTypes[i].Priority)
|
||||
{
|
||||
trueTypes[i] = newSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return trueTypes;
|
||||
}
|
||||
|
||||
private static string TryGetImplementationExtensionsFolder()
|
||||
{
|
||||
var directory = new
|
||||
DirectoryInfo(Directory.GetCurrentDirectory());
|
||||
while (directory != null && directory
|
||||
.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories)
|
||||
.All(x => x.Name != "ImplementationExtensions"))
|
||||
{
|
||||
directory = directory.Parent;
|
||||
}
|
||||
return $"{directory?.FullName}\\ImplementationExtensions";
|
||||
}
|
||||
}
|
||||
37
SushiBar/SushiBarContracts/DI/UnityDependencyContainer.cs
Normal file
37
SushiBar/SushiBarContracts/DI/UnityDependencyContainer.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Unity;
|
||||
using Unity.Microsoft.Logging;
|
||||
|
||||
namespace SushiBarContracts.DI;
|
||||
|
||||
public class UnityDependencyContainer : IDependencyContainer
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
|
||||
public UnityDependencyContainer()
|
||||
{
|
||||
_container = new UnityContainer();
|
||||
}
|
||||
|
||||
public void AddLogging(Action<ILoggingBuilder> configure)
|
||||
{
|
||||
var factory = LoggerFactory.Create(configure);
|
||||
_container.AddExtension(new LoggingExtension(factory));
|
||||
}
|
||||
|
||||
public void RegisterType<T>(bool isSingle) where T : class
|
||||
{
|
||||
_container.RegisterType<T>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
|
||||
|
||||
}
|
||||
|
||||
public T Resolve<T>()
|
||||
{
|
||||
return _container.Resolve<T>();
|
||||
}
|
||||
|
||||
void IDependencyContainer.RegisterType<T, U>(bool isSingle)
|
||||
{
|
||||
_container.RegisterType<T, U>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace SushiBarContracts.SearchModels;
|
||||
|
||||
public class ImplementerSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ImplementerFio { get; set; }
|
||||
public string? Password { get; set; }
|
||||
public int? WorkExperience { get; set; }
|
||||
public int? Qualification { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SushiBarContracts.SearchModels;
|
||||
|
||||
public class MessageInfoSearchModel
|
||||
{
|
||||
public string? MessageId { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
public int? Page { get; set; }
|
||||
public int? PageSize { get; set; }
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace SushiBarContracts.SearchModels
|
||||
using SushiBarDataModels.Enums;
|
||||
|
||||
namespace SushiBarContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
@@ -6,5 +8,7 @@
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
public List<OrderStatus> Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace SushiBarContracts.StoragesContracts;
|
||||
|
||||
public interface IBackUpInfo
|
||||
{
|
||||
List<T>? GetList<T>() where T : class, new();
|
||||
Type? GetTypeByModelInterface(string modelInterfaceName);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarContracts.StoragesContracts;
|
||||
|
||||
public interface IImplementerStorage
|
||||
{
|
||||
List<ImplementerViewModel> GetFullList();
|
||||
List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel? model);
|
||||
ImplementerViewModel? GetElement(ImplementerSearchModel? model);
|
||||
ImplementerViewModel? Insert(ImplementerBindingModel model);
|
||||
ImplementerViewModel? Update(ImplementerBindingModel model);
|
||||
ImplementerViewModel? Delete(ImplementerBindingModel model);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarContracts.StoragesContracts;
|
||||
|
||||
public interface IMessageInfoStorage
|
||||
{
|
||||
List<MessageInfoViewModel> GetFullList();
|
||||
List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model);
|
||||
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
|
||||
MessageInfoViewModel? Insert(MessageInfoBindingModel model);
|
||||
MessageInfoViewModel? Update(MessageInfoBindingModel model);
|
||||
}
|
||||
@@ -10,4 +10,16 @@
|
||||
<ProjectReference Include="..\SushiBarModels\SushiBarDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Windows.Forms">
|
||||
<HintPath>..\..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\6.0.8\System.Windows.Forms.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Unity" Version="5.11.10" />
|
||||
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
using System.ComponentModel;
|
||||
using SushiBarContracts.Attributes;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarContracts.ViewModels;
|
||||
|
||||
public class ClientViewModel : IClientModel
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public int Id { get; set; }
|
||||
[DisplayName("FIO client")]
|
||||
[Column("FIO client", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string ClientFio { get; set; } = string.Empty;
|
||||
[DisplayName("Email")]
|
||||
[Column("Email", width: 150)]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
[DisplayName("Password")]
|
||||
[Column("Password", width : 150)]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
using SushiBarDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
using SushiBarContracts.Attributes;
|
||||
|
||||
namespace SushiBarContracts.ViewModels
|
||||
{
|
||||
public class ComponentViewModel : IComponentModel
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Name of Component")]
|
||||
[Column("Name of Component", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Cost")]
|
||||
[Column("Cost", width: 80)]
|
||||
public double Cost { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.ComponentModel;
|
||||
using SushiBarContracts.Attributes;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarContracts.ViewModels;
|
||||
|
||||
public class ImplementerViewModel : IImplementerModel
|
||||
{
|
||||
[Column(visible : false)]
|
||||
public int Id { get; init; }
|
||||
[Column("Implementer FIO", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string ImplementerFio { get; set; } = string.Empty;
|
||||
[Column("Password", width: 150)]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[Column("Work Experience", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public int WorkExperience { get; set; }
|
||||
[Column("Qualification", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public int Qualification { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using SushiBarContracts.Attributes;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarContracts.ViewModels;
|
||||
|
||||
public class MessageInfoViewModel : IMessageInfoModel
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public string MessageId { get; set; }
|
||||
[Column(visible: false)]
|
||||
public int? ClientId { get; set; }
|
||||
[Column("Sender name", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)]
|
||||
public string SenderName { get; set; }
|
||||
[Column("Date delivery", width: 100)]
|
||||
public DateTime DateDelivery { get; set; }
|
||||
[Column("Subject", width:150)]
|
||||
public string Subject { get; set; }
|
||||
[Column("Body", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string Body { get; set; }
|
||||
public bool IsRead { get; set; }
|
||||
public string? Reply { get; set; }
|
||||
[Column(visible:false)]
|
||||
public int Id { get; }
|
||||
}
|
||||
@@ -1,36 +1,43 @@
|
||||
using SushiBarDataModels.Enums;
|
||||
using SushiBarDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
using SushiBarContracts.Attributes;
|
||||
|
||||
namespace SushiBarContracts.ViewModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Number")]
|
||||
[Column("Number", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public int Id { get; init; }
|
||||
|
||||
[Column(visible:false)]
|
||||
public int SushiId { get; init; }
|
||||
[Column(visible:false)]
|
||||
public int ClientId { get; init; }
|
||||
[Column(visible:false)]
|
||||
public int? ImplementerId { get; set; }
|
||||
|
||||
[DisplayName("Client FIO")]
|
||||
[Column("Client FIO", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string ClientFio { get; init; } = string.Empty;
|
||||
|
||||
[DisplayName("Name of Product")]
|
||||
[Column("Implementer FIO", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string ImplementerFio { get; set; } = string.Empty;
|
||||
|
||||
[Column("Name of Product", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public string SushiName { get; init; } = string.Empty;
|
||||
|
||||
[DisplayName("Count")]
|
||||
[Column("Count", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public int Count { get; set; }
|
||||
|
||||
[DisplayName("Sum")]
|
||||
[Column("Sum", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true, format: "0.00 $")]
|
||||
public double Sum { get; set; }
|
||||
|
||||
[DisplayName("Status")]
|
||||
[Column("Status", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Unknown;
|
||||
|
||||
[DisplayName("Date Create")]
|
||||
[Column("Date Create", width:100, format: "Date: dd/MM/yyyy")]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
|
||||
[DisplayName("Date Implement")]
|
||||
[Column("Date Implement", width:100, format: "dd/MM/yyyy")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace SushiBarContracts.ViewModels
|
||||
using SushiBarContracts.Attributes;
|
||||
|
||||
namespace SushiBarContracts.ViewModels
|
||||
{
|
||||
public class ReportOrdersViewModel
|
||||
{
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
using SushiBarDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
using SushiBarContracts.Attributes;
|
||||
|
||||
namespace SushiBarContracts.ViewModels
|
||||
{
|
||||
public class SushiViewModel : ISushiModel
|
||||
{
|
||||
[Column(visible:false)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Name of Product")]
|
||||
[Column("Name of Product", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string SushiName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Cost")]
|
||||
[Column("Cost", width:100)]
|
||||
public double Price { get; set; }
|
||||
[Column(visible:false)]
|
||||
public Dictionary<int, (IComponentModel, int)> SushiComponents { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using SushiBarContracts.DI;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarDatabaseImplement.Implements;
|
||||
|
||||
namespace SushiBarDatabaseImplement;
|
||||
|
||||
public class DatabaseImplementationExtension : IImplementationExtension
|
||||
{
|
||||
public int Priority => 2;
|
||||
|
||||
public void RegisterServices()
|
||||
{
|
||||
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
|
||||
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageStorage>();
|
||||
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||
DependencyManager.Instance.RegisterType<ISushiStorage, SushiStorage>();
|
||||
DependencyManager.Instance.RegisterType<IStoreStorage, StoreStorage>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
|
||||
}
|
||||
}
|
||||
26
SushiBar/SushiBarDatabaseImplement/Implements/BackUpInfo.cs
Normal file
26
SushiBar/SushiBarDatabaseImplement/Implements/BackUpInfo.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
|
||||
namespace SushiBarDatabaseImplement.Implements;
|
||||
|
||||
public class BackUpInfo : IBackUpInfo
|
||||
{
|
||||
public List<T>? GetList<T>() where T: class, new()
|
||||
{
|
||||
using var context = new SushiBarDatabase();
|
||||
return context.Set<T>().ToList();
|
||||
}
|
||||
|
||||
public Type? GetTypeByModelInterface(string modelInterfaceName)
|
||||
{
|
||||
var assembly = typeof(BackUpInfo).Assembly;
|
||||
var types = assembly.GetTypes();
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (type.IsClass && type.GetInterface(modelInterfaceName) != null)
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,13 @@ public class ClientStorage : IClientStorage
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
return context.Clients
|
||||
.FirstOrDefault(x => x.Email == model.Email)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
return context.Clients
|
||||
.FirstOrDefault(x => x.Email == model.Email && x.Password == model.Password)
|
||||
?.GetViewModel;
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDatabaseImplement.Models;
|
||||
|
||||
namespace SushiBarDatabaseImplement.Implements;
|
||||
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SushiBarDatabase();
|
||||
return context.Implementers
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel? model)
|
||||
{
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
var res = GetElement(model);
|
||||
return res != null ? new List<ImplementerViewModel> { res } : new List<ImplementerViewModel>();
|
||||
}
|
||||
|
||||
if (model.ImplementerFio == null) return new List<ImplementerViewModel>();
|
||||
using var context = new SushiBarDatabase();
|
||||
return context.Implementers
|
||||
.Where(x => x.ImplementerFio.Equals(model.ImplementerFio))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel? model)
|
||||
{
|
||||
using var context = new SushiBarDatabase();
|
||||
if (model.Id.HasValue)
|
||||
return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
if (model is { ImplementerFio: { }, Password: { } })
|
||||
return context.Implementers
|
||||
.FirstOrDefault(x => x.ImplementerFio.Equals(model.ImplementerFio)
|
||||
&& x.Password.Equals(model.Password))
|
||||
?.GetViewModel;
|
||||
return model.ImplementerFio != null ?
|
||||
context.Implementers
|
||||
.FirstOrDefault(x => x.ImplementerFio.Equals(model.ImplementerFio))?.GetViewModel :
|
||||
null;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarDatabase();
|
||||
var res = Implementer.Create(model);
|
||||
if (res == null) return res?.GetViewModel;
|
||||
context.Implementers.Add(res);
|
||||
context.SaveChanges();
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarDatabase();
|
||||
var res = context.Implementers
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (res == null) return res?.GetViewModel;
|
||||
res.Update(model);
|
||||
context.SaveChanges();
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarDatabase();
|
||||
var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (res == null) return res?.GetViewModel;
|
||||
context.Implementers.Remove(res);
|
||||
context.SaveChanges();
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDatabaseImplement.Models;
|
||||
|
||||
namespace SushiBarDatabaseImplement.Implements;
|
||||
|
||||
public class MessageStorage : IMessageInfoStorage
|
||||
{
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||
{
|
||||
if (model.MessageId == null)
|
||||
return null;
|
||||
using var context = new SushiBarDatabase();
|
||||
return context.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
using var context = new SushiBarDatabase();
|
||||
var res = context.Messages
|
||||
.Where(x => !model.ClientId.HasValue || x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
return model is not { Page: { }, PageSize: { } } ?
|
||||
res.ToList() :
|
||||
res.Skip((model.Page.Value - 1) * model.PageSize.Value).Take(model.PageSize.Value).ToList();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SushiBarDatabase();
|
||||
return context.Messages
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||
{
|
||||
var newMessage = Message.Create(model);
|
||||
if (newMessage == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SushiBarDatabase();
|
||||
context.Messages.Add(newMessage);
|
||||
context.SaveChanges();
|
||||
return newMessage.GetViewModel;
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarDatabase();
|
||||
var res = context.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId));
|
||||
if (res == null) return res?.GetViewModel;
|
||||
res.Update(model);
|
||||
context.SaveChanges();
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDatabaseImplement.Models;
|
||||
using SushiBarDataModels.Enums;
|
||||
|
||||
namespace SushiBarDatabaseImplement.Implements
|
||||
{
|
||||
@@ -33,30 +34,52 @@ namespace SushiBarDatabaseImplement.Implements
|
||||
using var context = new SushiBarDatabase();
|
||||
|
||||
return context.Orders
|
||||
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.FirstOrDefault(x =>
|
||||
(model.Status == null || model.Status != null && model.Status.Contains(x.Status)) &&
|
||||
model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId ||
|
||||
model.Id.HasValue && x.Id == model.Id
|
||||
)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel? model)
|
||||
{
|
||||
if (model is null)
|
||||
return new List<OrderViewModel>();
|
||||
|
||||
using var context = new SushiBarDatabase();
|
||||
if (model.ClientId.HasValue)
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Client)
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
var result = GetElement(model);
|
||||
return result != null ? new() { result } : new();
|
||||
}
|
||||
|
||||
return context.Orders
|
||||
.Include(x => x.Sushi)
|
||||
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
using var context = new SushiBarDatabase();
|
||||
IQueryable<Order>? queryWhere = null;
|
||||
|
||||
if (model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||
{
|
||||
queryWhere = context.Orders
|
||||
.Where(x => model.DateFrom <= x.DateCreate.Date &&
|
||||
x.DateCreate.Date <= model.DateTo);
|
||||
}
|
||||
else if (model.Status != null)
|
||||
{
|
||||
queryWhere = context.Orders
|
||||
.Where(x => model.Status.Contains(x.Status));
|
||||
}
|
||||
else if (model.ClientId.HasValue)
|
||||
{
|
||||
queryWhere = context.Orders
|
||||
.Where(x => x.ClientId == model.ClientId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return queryWhere
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
|
||||
@@ -12,8 +12,8 @@ using SushiBarDatabaseImplement;
|
||||
namespace SushiBarDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(SushiBarDatabase))]
|
||||
[Migration("20230425050030_lab5hard")]
|
||||
partial class lab5hard
|
||||
[Migration("20230505055203_lab8h")]
|
||||
partial class lab8h
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@@ -70,6 +70,69 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ImplementerFio")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Implementers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Message", b =>
|
||||
{
|
||||
b.Property<string>("MessageId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Body")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int?>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateDelivery")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<bool>("IsRead")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Reply")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("SenderName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Subject")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("MessageId");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.ToTable("Messages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -90,6 +153,9 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("ImplementerId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
@@ -107,6 +173,8 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("ImplementerId");
|
||||
|
||||
b.HasIndex("SushiId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
@@ -182,7 +250,7 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Sushi");
|
||||
b.ToTable("Sushis");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
|
||||
@@ -211,6 +279,15 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
b.ToTable("SushiComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Message", b =>
|
||||
{
|
||||
b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany()
|
||||
.HasForeignKey("ClientId");
|
||||
|
||||
b.Navigation("Client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client")
|
||||
@@ -219,6 +296,10 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SushiBarDatabaseImplement.Models.Implementer", "Implementer")
|
||||
.WithMany()
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("SushiId")
|
||||
@@ -227,6 +308,8 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Implementer");
|
||||
|
||||
b.Navigation("Sushi");
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||
namespace SushiBarDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class lab5hard : Migration
|
||||
public partial class lab8h : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
@@ -40,6 +40,22 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Implementers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ImplementerFio = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
WorkExperience = table.Column<int>(type: "int", nullable: false),
|
||||
Qualification = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Implementers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Stores",
|
||||
columns: table => new
|
||||
@@ -57,7 +73,7 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Sushi",
|
||||
name: "Sushis",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
@@ -67,7 +83,30 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Sushi", x => x.Id);
|
||||
table.PrimaryKey("PK_Sushis", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Messages",
|
||||
columns: table => new
|
||||
{
|
||||
MessageId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ClientId = table.Column<int>(type: "int", nullable: true),
|
||||
SenderName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
DateDelivery = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
Subject = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Body = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
IsRead = table.Column<bool>(type: "bit", nullable: false),
|
||||
Reply = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Messages", x => x.MessageId);
|
||||
table.ForeignKey(
|
||||
name: "FK_Messages_Clients_ClientId",
|
||||
column: x => x.ClientId,
|
||||
principalTable: "Clients",
|
||||
principalColumn: "Id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
@@ -78,6 +117,7 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
SushiId = table.Column<int>(type: "int", nullable: false),
|
||||
ClientId = table.Column<int>(type: "int", nullable: false),
|
||||
ImplementerId = table.Column<int>(type: "int", nullable: true),
|
||||
SushiName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
Sum = table.Column<double>(type: "float", nullable: false),
|
||||
@@ -95,9 +135,14 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Sushi_SushiId",
|
||||
name: "FK_Orders_Implementers_ImplementerId",
|
||||
column: x => x.ImplementerId,
|
||||
principalTable: "Implementers",
|
||||
principalColumn: "Id");
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Sushis_SushiId",
|
||||
column: x => x.SushiId,
|
||||
principalTable: "Sushi",
|
||||
principalTable: "Sushis",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
@@ -122,9 +167,9 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_StoreSushis_Sushi_SushiId",
|
||||
name: "FK_StoreSushis_Sushis_SushiId",
|
||||
column: x => x.SushiId,
|
||||
principalTable: "Sushi",
|
||||
principalTable: "Sushis",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
@@ -149,18 +194,28 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_SushiComponents_Sushi_SushiId",
|
||||
name: "FK_SushiComponents_Sushis_SushiId",
|
||||
column: x => x.SushiId,
|
||||
principalTable: "Sushi",
|
||||
principalTable: "Sushis",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Messages_ClientId",
|
||||
table: "Messages",
|
||||
column: "ClientId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ClientId",
|
||||
table: "Orders",
|
||||
column: "ClientId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ImplementerId",
|
||||
table: "Orders",
|
||||
column: "ImplementerId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_SushiId",
|
||||
table: "Orders",
|
||||
@@ -190,6 +245,9 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Messages");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
@@ -202,6 +260,9 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
migrationBuilder.DropTable(
|
||||
name: "Clients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Implementers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Stores");
|
||||
|
||||
@@ -209,7 +270,7 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Sushi");
|
||||
name: "Sushis");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,69 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ImplementerFio")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Implementers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Message", b =>
|
||||
{
|
||||
b.Property<string>("MessageId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Body")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int?>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateDelivery")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<bool>("IsRead")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Reply")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("SenderName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Subject")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("MessageId");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.ToTable("Messages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -87,6 +150,9 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("ImplementerId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
@@ -104,6 +170,8 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("ImplementerId");
|
||||
|
||||
b.HasIndex("SushiId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
@@ -179,7 +247,7 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Sushi");
|
||||
b.ToTable("Sushis");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
|
||||
@@ -208,6 +276,15 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
b.ToTable("SushiComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Message", b =>
|
||||
{
|
||||
b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany()
|
||||
.HasForeignKey("ClientId");
|
||||
|
||||
b.Navigation("Client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client")
|
||||
@@ -216,6 +293,10 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SushiBarDatabaseImplement.Models.Implementer", "Implementer")
|
||||
.WithMany()
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("SushiId")
|
||||
@@ -224,6 +305,8 @@ namespace SushiBarDatabaseImplement.Migrations
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Implementer");
|
||||
|
||||
b.Navigation("Sushi");
|
||||
});
|
||||
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.Serialization;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarDatabaseImplement.Models;
|
||||
|
||||
[DataContract]
|
||||
public class Client : IClientModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private init; }
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string ClientFio { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public static Client? Create(ClientBindingModel? model)
|
||||
|
||||
@@ -3,55 +3,59 @@ using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace SushiBarDatabaseImplement.Models
|
||||
namespace SushiBarDatabaseImplement.Models;
|
||||
|
||||
[DataContract]
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
[DataMember]
|
||||
public double Cost { get; set; }
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<SushiComponent> SushiComponent { get; set; } = new();
|
||||
public static Component? Create(ComponentBindingModel model)
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<SushiComponent> SushiComponent { get; set; } = new();
|
||||
public static Component? Create(ComponentBindingModel model)
|
||||
if (model == null)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
return null;
|
||||
}
|
||||
public static Component Create(ComponentViewModel model)
|
||||
return new Component()
|
||||
{
|
||||
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
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
public static Component Create(ComponentViewModel model)
|
||||
{
|
||||
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/SushiBarDatabaseImplement/Models/Implementer.cs
Normal file
67
SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.Serialization;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarDatabaseImplement.Models;
|
||||
|
||||
[DataContract]
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private init; }
|
||||
[Required] [DataMember] public string ImplementerFio { get; private set; } = string.Empty;
|
||||
[Required] [DataMember] public string Password { get; private set; } = string.Empty;
|
||||
[DataMember] public int WorkExperience { get; private set; }
|
||||
[DataMember] public int Qualification { get; private set; }
|
||||
|
||||
public static Implementer? Create(ImplementerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new Implementer
|
||||
{
|
||||
Id = model.Id,
|
||||
ImplementerFio = model.ImplementerFio,
|
||||
Password = model.Password,
|
||||
WorkExperience = model.WorkExperience,
|
||||
Qualification = model.Qualification
|
||||
};
|
||||
}
|
||||
|
||||
public static Implementer Create(ImplementerViewModel model)
|
||||
{
|
||||
return new Implementer()
|
||||
{
|
||||
Id = model.Id,
|
||||
ImplementerFio = model.ImplementerFio,
|
||||
Password = model.Password,
|
||||
WorkExperience = model.WorkExperience,
|
||||
Qualification = model.Qualification
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ImplementerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ImplementerFio = model.ImplementerFio;
|
||||
Password = model.Password;
|
||||
WorkExperience = model.WorkExperience;
|
||||
Qualification = model.Qualification;
|
||||
}
|
||||
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ImplementerFio = ImplementerFio,
|
||||
Password = Password,
|
||||
WorkExperience = WorkExperience,
|
||||
Qualification = Qualification
|
||||
};
|
||||
}
|
||||
68
SushiBar/SushiBarDatabaseImplement/Models/Message.cs
Normal file
68
SushiBar/SushiBarDatabaseImplement/Models/Message.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.Serialization;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarDatabaseImplement.Models;
|
||||
|
||||
[DataContract]
|
||||
public class Message : IMessageInfoModel
|
||||
{
|
||||
[Key]
|
||||
[DataMember]
|
||||
public string MessageId { get; private set; } = string.Empty;
|
||||
|
||||
public int Id { get; }
|
||||
public int? ClientId { get; private set; }
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string SenderName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
[DataMember]
|
||||
public DateTime DateDelivery { get; private set; } = DateTime.Now;
|
||||
[Required]
|
||||
public string Subject { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Body { get; private set; } = string.Empty;
|
||||
public bool IsRead { get; private set; }
|
||||
public string? Reply { get; private set; }
|
||||
|
||||
public virtual Client Client { get; set; }
|
||||
|
||||
public static Message? Create(MessageInfoBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Message
|
||||
{
|
||||
Body = model.Body,
|
||||
Subject = model.Subject,
|
||||
ClientId = model.ClientId,
|
||||
MessageId = model.MessageId,
|
||||
SenderName = model.SenderName,
|
||||
DateDelivery = model.DateDelivery,
|
||||
IsRead = model.IsRead
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(MessageInfoBindingModel model)
|
||||
{
|
||||
Reply = model.Reply;
|
||||
IsRead = model.IsRead;
|
||||
}
|
||||
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
{
|
||||
Body = Body,
|
||||
Subject = Subject,
|
||||
ClientId = ClientId,
|
||||
MessageId = MessageId,
|
||||
SenderName = SenderName,
|
||||
DateDelivery = DateDelivery,
|
||||
IsRead = IsRead,
|
||||
Reply = Reply
|
||||
};
|
||||
}
|
||||
@@ -3,77 +3,92 @@ using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Enums;
|
||||
using SushiBarDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace SushiBarDatabaseImplement.Models
|
||||
namespace SushiBarDatabaseImplement.Models;
|
||||
|
||||
[DataContract]
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int SushiId { get; private set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int ClientId { get; private set; }
|
||||
[DataMember]
|
||||
public int? ImplementerId { get; private set; }
|
||||
[DataMember]
|
||||
public string SushiName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public double Sum { get; private set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Unknown;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public virtual Sushi Sushi { get; set; }
|
||||
|
||||
public virtual Client Client { get; set; }
|
||||
|
||||
public virtual Implementer? Implementer { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int SushiId { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public string SushiName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
|
||||
[Required]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Unknown;
|
||||
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public virtual Sushi Sushi { get; set; }
|
||||
|
||||
public virtual Client Client { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
if (model == null)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Order
|
||||
{
|
||||
Id = model.Id,
|
||||
SushiId = model.SushiId,
|
||||
SushiName = model.SushiName,
|
||||
ClientId = model.ClientId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
};
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? model)
|
||||
return new Order
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Id = model.Id,
|
||||
SushiId = model.SushiId,
|
||||
SushiName = model.SushiName,
|
||||
ClientId = model.ClientId,
|
||||
ImplementerId = model.ImplementerId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
};
|
||||
}
|
||||
|
||||
SushiId = model.SushiId;
|
||||
SushiName = model.SushiName;
|
||||
ClientId = model.ClientId;
|
||||
Count = model.Count;
|
||||
Sum = model.Sum;
|
||||
Status = model.Status;
|
||||
DateCreate = model.DateCreate;
|
||||
DateImplement = model.DateImplement;
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SushiId = model.SushiId;
|
||||
SushiName = model.SushiName;
|
||||
ClientId = model.ClientId;
|
||||
ImplementerId = model.ImplementerId;
|
||||
Count = model.Count;
|
||||
Sum = model.Sum;
|
||||
Status = model.Status;
|
||||
DateCreate = model.DateCreate;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel { get
|
||||
{
|
||||
var context = new SushiBarDatabase();
|
||||
@@ -85,11 +100,13 @@ namespace SushiBarDatabaseImplement.Models
|
||||
Count = Count,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
ImplementerId = ImplementerId,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
ClientFio = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFio ?? string.Empty,
|
||||
SushiName = context.Sushi.FirstOrDefault(x => x.Id == SushiId)?.SushiName ?? string.Empty
|
||||
SushiName = context.Sushis.FirstOrDefault(x => x.Id == SushiId)?.SushiName ?? string.Empty,
|
||||
ImplementerFio = context.Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFio ?? string.Empty,
|
||||
};
|
||||
} }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,19 +80,19 @@ public class Store : IStoreModel
|
||||
|
||||
public void UpdateSushi(SushiBarDatabase context, StoreBindingModel model)
|
||||
{
|
||||
var StoreSushi = context.StoreSushis
|
||||
var storeSushi = context.StoreSushis
|
||||
.Where(rec => rec.StoreId == model.Id)
|
||||
.ToList();
|
||||
|
||||
if (StoreSushi.Count > 0)
|
||||
if (storeSushi.Count > 0)
|
||||
{
|
||||
context.StoreSushis
|
||||
.RemoveRange(StoreSushi
|
||||
.RemoveRange(storeSushi
|
||||
.Where(rec => !model.Sushis
|
||||
.ContainsKey(rec.SushiId)));
|
||||
|
||||
foreach (var updateSushi in
|
||||
StoreSushi.Where(x => model.Sushis.ContainsKey(x.SushiId)))
|
||||
storeSushi.Where(x => model.Sushis.ContainsKey(x.SushiId)))
|
||||
{
|
||||
updateSushi.Count = model.Sushis[updateSushi.SushiId].Item2;
|
||||
model.Sushis.Remove(updateSushi.SushiId);
|
||||
@@ -103,7 +103,7 @@ public class Store : IStoreModel
|
||||
{
|
||||
Sushi = context.Sushis.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2,
|
||||
}).Except(StoreSushi));
|
||||
}).Except(storeSushi));
|
||||
context.SaveChanges();
|
||||
_sushis = null;
|
||||
}
|
||||
|
||||
@@ -1,88 +1,92 @@
|
||||
using SushiBarDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.Serialization;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarDatabaseImplement.Models
|
||||
{
|
||||
public class Sushi : ISushiModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string SushiName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
private Dictionary<int, (IComponentModel, int)>? _sushiComponents = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> SushiComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
_sushiComponents ??= Components
|
||||
.ToDictionary(recPC => recPC.ComponentId, recPC =>
|
||||
(recPC.Component as IComponentModel, recPC.Count));
|
||||
return _sushiComponents;
|
||||
}
|
||||
}
|
||||
[ForeignKey("SushiId")]
|
||||
public virtual List<SushiComponent> Components { get; set; } = new();
|
||||
[ForeignKey("SushiId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
public static Sushi Create(SushiBarDatabase context, SushiBindingModel model)
|
||||
{
|
||||
return new Sushi()
|
||||
{
|
||||
Id = model.Id,
|
||||
SushiName = model.SushiName,
|
||||
Price = model.Price,
|
||||
Components = model.SushiComponents.Select(x => new SushiComponent
|
||||
{
|
||||
Component = context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(SushiBindingModel model)
|
||||
{
|
||||
SushiName = model.SushiName;
|
||||
Price = model.Price;
|
||||
}
|
||||
public SushiViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
SushiName = SushiName,
|
||||
Price = Price,
|
||||
SushiComponents = SushiComponents
|
||||
};
|
||||
public void UpdateComponents(SushiBarDatabase context, SushiBindingModel model)
|
||||
{
|
||||
var sushiComponents = context.SushiComponents.Where(rec => rec.SushiId == model.Id).ToList();
|
||||
if (sushiComponents is { Count: > 0 })
|
||||
{
|
||||
context.SushiComponents.RemoveRange(sushiComponents.Where(rec => !model.SushiComponents.ContainsKey(rec.ComponentId)));
|
||||
context.SaveChanges();
|
||||
|
||||
foreach (var updateComponent in sushiComponents)
|
||||
{
|
||||
updateComponent.Count = model.SushiComponents[updateComponent.ComponentId].Item2;
|
||||
model.SushiComponents.Remove(updateComponent.ComponentId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var sushi = context.Sushis.First(x => x.Id == Id);
|
||||
foreach (var pc in model.SushiComponents)
|
||||
{
|
||||
context.SushiComponents.Add(new SushiComponent
|
||||
{
|
||||
Sushi = sushi,
|
||||
Component = context.Components.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_sushiComponents = null;
|
||||
}
|
||||
namespace SushiBarDatabaseImplement.Models;
|
||||
|
||||
[DataContract]
|
||||
public class Sushi : ISushiModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string SushiName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
[DataMember]
|
||||
public double Price { get; set; }
|
||||
private Dictionary<int, (IComponentModel, int)>? _sushiComponents = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> SushiComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
_sushiComponents ??= Components
|
||||
.ToDictionary(recPC => recPC.ComponentId, recPC =>
|
||||
(recPC.Component as IComponentModel, recPC.Count));
|
||||
return _sushiComponents;
|
||||
}
|
||||
}
|
||||
}
|
||||
[ForeignKey("SushiId")]
|
||||
public virtual List<SushiComponent> Components { get; set; } = new();
|
||||
[ForeignKey("SushiId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
public static Sushi Create(SushiBarDatabase context, SushiBindingModel model)
|
||||
{
|
||||
return new Sushi()
|
||||
{
|
||||
Id = model.Id,
|
||||
SushiName = model.SushiName,
|
||||
Price = model.Price,
|
||||
Components = model.SushiComponents.Select(x => new SushiComponent
|
||||
{
|
||||
Component = context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(SushiBindingModel model)
|
||||
{
|
||||
SushiName = model.SushiName;
|
||||
Price = model.Price;
|
||||
}
|
||||
public SushiViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
SushiName = SushiName,
|
||||
Price = Price,
|
||||
SushiComponents = SushiComponents
|
||||
};
|
||||
public void UpdateComponents(SushiBarDatabase context, SushiBindingModel model)
|
||||
{
|
||||
var sushiComponents = context.SushiComponents.Where(rec => rec.SushiId == model.Id).ToList();
|
||||
if (sushiComponents != null && sushiComponents.Count > 0)
|
||||
{
|
||||
context.SushiComponents.RemoveRange(sushiComponents.Where(rec => !model.SushiComponents.ContainsKey(rec.ComponentId)));
|
||||
context.SaveChanges();
|
||||
|
||||
foreach (var updateComponent in sushiComponents)
|
||||
{
|
||||
updateComponent.Count = model.SushiComponents[updateComponent.ComponentId].Item2;
|
||||
model.SushiComponents.Remove(updateComponent.ComponentId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var sushi = context.Sushis.First(x => x.Id == Id);
|
||||
foreach (var pc in model.SushiComponents)
|
||||
{
|
||||
context.SushiComponents.Add(new SushiComponent
|
||||
{
|
||||
Sushi = sushi,
|
||||
Component = context.Components.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_sushiComponents = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SushiBarDatabaseImplement.Models
|
||||
namespace SushiBarDatabaseImplement.Models;
|
||||
|
||||
public class SushiComponent
|
||||
{
|
||||
public class SushiComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int SushiId { get; set; }
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Component Component { get; set; } = new();
|
||||
public virtual Sushi Sushi { get; set; } = new();
|
||||
}
|
||||
}
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int SushiId { get; set; }
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Component Component { get; set; } = new();
|
||||
public virtual Sushi Sushi { get; set; } = new();
|
||||
}
|
||||
@@ -14,12 +14,13 @@ namespace SushiBarDatabaseImplement
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Sushi> Sushi { set; get; }
|
||||
public virtual DbSet<Sushi> Sushis { set; get; }
|
||||
public virtual DbSet<SushiComponent> SushiComponents { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<Store> Stores { get; set; }
|
||||
public virtual DbSet<StoreSushi> StoreSushis { get; set; }
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
public virtual DbSet<Sushi> Sushis { get; set; }
|
||||
public virtual DbSet<Implementer> Implementers { get; set; }
|
||||
public virtual DbSet<Message> Messages { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,4 +19,8 @@
|
||||
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(targetDir)*.dll" "$(solutionDir)ImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -10,9 +10,14 @@ namespace SushiBarFileImplement
|
||||
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; }
|
||||
private readonly string ImplementerFileName = "Implementer.xml";
|
||||
private readonly string MessageFileName = "Message.xml";
|
||||
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Sushi> Sushis { get; private set; }
|
||||
public List<Implementer> Implementers { get; set; }
|
||||
public List<Message> Messages { get; set; }
|
||||
public List<Store> Stores { get; }
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
@@ -22,14 +27,19 @@ 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 SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
|
||||
public void SaveStores() => SaveData(Stores, StoreFileName, "Store", x => x.GetXElement);
|
||||
public void SaveMessages() => SaveData(Messages, MessageFileName, "Messages", 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)!)!;
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Sushis = LoadData(SushiFileName, "Sushi", x => Sushi.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
|
||||
Messages = LoadData(MessageFileName, "Messages", x => Message.Create(x)!)!;
|
||||
Stores = LoadData(StoreFileName, "Store", x => Store.Create(x)!)!;
|
||||
}
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarFileImplement.Models;
|
||||
|
||||
namespace SushiBarFileImplement.Implements;
|
||||
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
public ImplementerStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
return _source.Implementers.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return new List<ImplementerViewModel>();
|
||||
}
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
var res = GetElement(model);
|
||||
return res != null ?
|
||||
new List<ImplementerViewModel> { res } :
|
||||
new List<ImplementerViewModel>();
|
||||
}
|
||||
if (model.ImplementerFio != null)
|
||||
{
|
||||
return _source.Implementers
|
||||
.Where(x => x.ImplementerFio.Equals(model.ImplementerFio))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new List<ImplementerViewModel>();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel? model)
|
||||
{
|
||||
if (model.Id.HasValue)
|
||||
return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
if (model is { ImplementerFio: { }, Password: { } })
|
||||
return _source.Implementers
|
||||
.FirstOrDefault(x => x.ImplementerFio.Equals(model.ImplementerFio)
|
||||
&& x.Password.Equals(model.Password))
|
||||
?.GetViewModel;
|
||||
return model.ImplementerFio != null ?
|
||||
_source.Implementers
|
||||
.FirstOrDefault(x => x.ImplementerFio.Equals(model.ImplementerFio))?.GetViewModel :
|
||||
null;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||
{
|
||||
model.Id = _source.Implementers.Count > 0 ?
|
||||
_source.Implementers.Max(x => x.Id) + 1 :
|
||||
1;
|
||||
var res = Implementer.Create(model);
|
||||
if (res == null) return res?.GetViewModel;
|
||||
_source.Implementers.Add(res);
|
||||
_source.SaveImplementers();
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||
{
|
||||
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (res == null) return res?.GetViewModel;
|
||||
res.Update(model);
|
||||
_source.SaveImplementers();
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||
{
|
||||
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (res == null) return res?.GetViewModel;
|
||||
_source.Implementers.Remove(res);
|
||||
_source.SaveImplementers();
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarFileImplement.Models;
|
||||
|
||||
namespace SushiBarFileImplement.Implements;
|
||||
|
||||
public class MessageInfoStorage : IMessageInfoStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public MessageInfoStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||
{
|
||||
return model.MessageId == null ?
|
||||
null :
|
||||
source.Messages
|
||||
.FirstOrDefault(x => x.MessageId == model.MessageId)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
if (!model.ClientId.HasValue)
|
||||
return new List<MessageInfoViewModel>();
|
||||
return source.Messages
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
return source.Messages
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||
{
|
||||
var newMessage = Message.Create(model);
|
||||
if (newMessage == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Messages.Add(newMessage);
|
||||
source.SaveMessages();
|
||||
return newMessage.GetViewModel;
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
77
SushiBar/SushiBarFileImplement/Models/Implementer.cs
Normal file
77
SushiBar/SushiBarFileImplement/Models/Implementer.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System.Xml.Linq;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarFileImplement.Models;
|
||||
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ImplementerFio { get; private set; } = string.Empty;
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
public int WorkExperience { get; private set; }
|
||||
public int Qualification { get; private set; }
|
||||
|
||||
public static Implementer? Create(XElement? element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Implementer
|
||||
{
|
||||
ImplementerFio = element.Element("FIO")!.Value,
|
||||
Password = element.Element("Password")!.Value,
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value),
|
||||
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value),
|
||||
};
|
||||
}
|
||||
|
||||
public static Implementer? Create(ImplementerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Implementer
|
||||
{
|
||||
Id = model.Id,
|
||||
Password = model.Password,
|
||||
Qualification = model.Qualification,
|
||||
ImplementerFio = model.ImplementerFio,
|
||||
WorkExperience = model.WorkExperience,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Update(ImplementerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Password = model.Password;
|
||||
Qualification = model.Qualification;
|
||||
ImplementerFio = model.ImplementerFio;
|
||||
WorkExperience = model.WorkExperience;
|
||||
}
|
||||
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Password = Password,
|
||||
Qualification = Qualification,
|
||||
ImplementerFio = ImplementerFio,
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("Client",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("Password", Password),
|
||||
new XElement("FIO", ImplementerFio),
|
||||
new XElement("Qualification", Qualification),
|
||||
new XElement("WorkExperience", WorkExperience)
|
||||
);
|
||||
}
|
||||
75
SushiBar/SushiBarFileImplement/Models/Message.cs
Normal file
75
SushiBar/SushiBarFileImplement/Models/Message.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System.Xml.Linq;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarFileImplement.Models;
|
||||
|
||||
public class Message : IMessageInfoModel
|
||||
{
|
||||
public string MessageId { get; private set; } = string.Empty;
|
||||
public int? ClientId { get; private set; }
|
||||
public string SenderName { get; private set; } = string.Empty;
|
||||
public DateTime DateDelivery { get; private set; } = DateTime.Now;
|
||||
public string Subject { get; private set; } = string.Empty;
|
||||
public string Body { get; private set; } = string.Empty;
|
||||
|
||||
public static Message? Create(MessageInfoBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Message
|
||||
{
|
||||
Body = model.Body,
|
||||
Subject = model.Subject,
|
||||
DateDelivery = model.DateDelivery,
|
||||
SenderName = model.SenderName,
|
||||
ClientId = model.ClientId,
|
||||
MessageId = model.MessageId
|
||||
};
|
||||
}
|
||||
|
||||
public static Message? Create(XElement? element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Message
|
||||
{
|
||||
Body = element.Attribute("Body")!.Value,
|
||||
Subject = element.Attribute("Subject")!.Value,
|
||||
DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value),
|
||||
SenderName = element.Attribute("SenderName")!.Value,
|
||||
ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value),
|
||||
MessageId = element.Attribute("MessageId")!.Value,
|
||||
};
|
||||
}
|
||||
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
{
|
||||
Body = Body,
|
||||
Subject = Subject,
|
||||
DateDelivery = DateDelivery,
|
||||
SenderName = SenderName,
|
||||
ClientId = ClientId,
|
||||
MessageId = MessageId
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("MessageInfo",
|
||||
new XAttribute("Subject", Subject),
|
||||
new XAttribute("Body", Body),
|
||||
new XAttribute("ClientId", ClientId),
|
||||
new XAttribute("MessageId", MessageId),
|
||||
new XAttribute("SenderName", SenderName),
|
||||
new XAttribute("DateDelivery", DateDelivery)
|
||||
);
|
||||
|
||||
public int Id { get; }
|
||||
|
||||
public bool IsRead => throw new NotImplementedException();
|
||||
|
||||
public string? Reply => throw new NotImplementedException();
|
||||
}
|
||||
@@ -12,6 +12,7 @@ namespace SushiBarFileImplement.Models
|
||||
public string SushiName { get; private set; } = string.Empty;
|
||||
public int SushiId { get; private set; }
|
||||
public int ClientId { get; }
|
||||
public int? ImplementerId { get; set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Unknown;
|
||||
@@ -29,6 +30,7 @@ namespace SushiBarFileImplement.Models
|
||||
Id = model.Id,
|
||||
SushiId = model.SushiId,
|
||||
SushiName = model.SushiName,
|
||||
ImplementerId = model.ImplementerId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@@ -51,6 +53,7 @@ namespace SushiBarFileImplement.Models
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
|
||||
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null)
|
||||
};
|
||||
|
||||
@@ -67,6 +70,7 @@ namespace SushiBarFileImplement.Models
|
||||
}
|
||||
SushiId = model.SushiId;
|
||||
SushiName = model.SushiName;
|
||||
ImplementerId = model.ImplementerId;
|
||||
Count = model.Count;
|
||||
Sum = model.Sum;
|
||||
Status = model.Status;
|
||||
@@ -78,6 +82,9 @@ namespace SushiBarFileImplement.Models
|
||||
Id = Id,
|
||||
SushiId = SushiId,
|
||||
SushiName = SushiName,
|
||||
ImplementerFio = DataFileSingleton.GetInstance()
|
||||
.Implementers
|
||||
.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFio ?? string.Empty,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
@@ -89,6 +96,7 @@ namespace SushiBarFileImplement.Models
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("SushiName", SushiName),
|
||||
new XElement("SushiId", SushiId.ToString()),
|
||||
new XElement("ImplementerId", ImplementerId),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", Status.ToString()),
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
Accepted = 0,
|
||||
Performed = 1,
|
||||
Ready = 2,
|
||||
Issued = 3
|
||||
Issued = 3,
|
||||
Waiting = 4
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user