lab6
This commit is contained in:
parent
94eb49d5de
commit
4e86563468
24
Bar/Bar/FormMain.Designer.cs
generated
24
Bar/Bar/FormMain.Designer.cs
generated
@ -39,10 +39,12 @@
|
||||
this.ComponentsStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.CocktailStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.ClientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.EmployersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.списокКомпонентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -112,7 +114,8 @@
|
||||
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.ToolStripMenu,
|
||||
this.отчётыToolStripMenuItem});
|
||||
this.отчётыToolStripMenuItem,
|
||||
this.запускРаботToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(1279, 28);
|
||||
@ -124,7 +127,8 @@
|
||||
this.ToolStripMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.ComponentsStripMenuItem,
|
||||
this.CocktailStripMenuItem,
|
||||
this.ClientsToolStripMenuItem});
|
||||
this.ClientsToolStripMenuItem,
|
||||
this.EmployersToolStripMenuItem});
|
||||
this.ToolStripMenu.Name = "ToolStripMenu";
|
||||
this.ToolStripMenu.Size = new System.Drawing.Size(117, 24);
|
||||
this.ToolStripMenu.Text = "Справочники";
|
||||
@ -150,6 +154,13 @@
|
||||
this.ClientsToolStripMenuItem.Text = "Клиенты";
|
||||
this.ClientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
|
||||
//
|
||||
// EmployersToolStripMenuItem
|
||||
//
|
||||
this.EmployersToolStripMenuItem.Name = "EmployersToolStripMenuItem";
|
||||
this.EmployersToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.EmployersToolStripMenuItem.Text = "Исполнители";
|
||||
this.EmployersToolStripMenuItem.Click += new System.EventHandler(this.EmployersToolStripMenuItem_Click);
|
||||
//
|
||||
// отчётыToolStripMenuItem
|
||||
//
|
||||
this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
@ -181,6 +192,13 @@
|
||||
this.списокЗаказовToolStripMenuItem.Text = "Список заказов";
|
||||
this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click);
|
||||
//
|
||||
// запускРаботToolStripMenuItem
|
||||
//
|
||||
this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem";
|
||||
this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(114, 24);
|
||||
this.запускРаботToolStripMenuItem.Text = "Запуск работ";
|
||||
this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
@ -221,5 +239,7 @@
|
||||
private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem;
|
||||
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
|
||||
private ToolStripMenuItem ClientsToolStripMenuItem;
|
||||
private ToolStripMenuItem запускРаботToolStripMenuItem;
|
||||
private ToolStripMenuItem EmployersToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using BarContracts.BusinessLogicsContracts;
|
||||
using BarView.Forms;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@ -10,13 +11,15 @@ namespace BarView
|
||||
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;
|
||||
public FormMain(ILogger<FormMain> Logger, IOrderLogic OrderLogic, IReportLogic ReportLogic, IWorkProcess WorkProcess)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_logger = Logger;
|
||||
_orderLogic = OrderLogic;
|
||||
_reportLogic = ReportLogic;
|
||||
_workProcess = WorkProcess;
|
||||
}
|
||||
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
@ -37,6 +40,7 @@ namespace BarView
|
||||
DataGridView.DataSource = List;
|
||||
DataGridView.Columns["CocktailId"].Visible = false;
|
||||
DataGridView.Columns["ClientId"].Visible = false;
|
||||
DataGridView.Columns["ImplementerId"].Visible = false;
|
||||
DataGridView.Columns["CocktailName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
|
||||
@ -207,5 +211,23 @@ namespace BarView
|
||||
Form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var ImplementerLogic = Program.ServiceProvider?.GetService(typeof(IImplementerLogic));
|
||||
_workProcess.DoWork((ImplementerLogic as IImplementerLogic)!, _orderLogic);
|
||||
|
||||
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
||||
private void EmployersToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
|
||||
|
||||
if (Service is FormImplementers Form)
|
||||
{
|
||||
Form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
173
Bar/Bar/Forms/FormImplementer.Designer.cs
generated
Normal file
173
Bar/Bar/Forms/FormImplementer.Designer.cs
generated
Normal file
@ -0,0 +1,173 @@
|
||||
namespace BarView.Forms
|
||||
{
|
||||
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()
|
||||
{
|
||||
FioTextBox = new TextBox();
|
||||
FioLabel = new Label();
|
||||
PasswordTextBox = new TextBox();
|
||||
PasswordLabel = new Label();
|
||||
WorkExperienceLabel = new Label();
|
||||
WorkExperienceNumericUpDown = new NumericUpDown();
|
||||
QualificationNumericUpDown = new NumericUpDown();
|
||||
QualificationLabel = new Label();
|
||||
CancelButton = new Button();
|
||||
SaveButton = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)WorkExperienceNumericUpDown).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)QualificationNumericUpDown).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// FioTextBox
|
||||
//
|
||||
FioTextBox.Location = new Point(137, 9);
|
||||
FioTextBox.Margin = new Padding(3, 2, 3, 2);
|
||||
FioTextBox.Name = "FioTextBox";
|
||||
FioTextBox.Size = new Size(335, 23);
|
||||
FioTextBox.TabIndex = 3;
|
||||
//
|
||||
// FioLabel
|
||||
//
|
||||
FioLabel.AutoSize = true;
|
||||
FioLabel.Location = new Point(10, 12);
|
||||
FioLabel.Name = "FioLabel";
|
||||
FioLabel.Size = new Size(112, 15);
|
||||
FioLabel.TabIndex = 2;
|
||||
FioLabel.Text = "ФИО исполнителя:";
|
||||
//
|
||||
// PasswordTextBox
|
||||
//
|
||||
PasswordTextBox.Location = new Point(137, 40);
|
||||
PasswordTextBox.Margin = new Padding(3, 2, 3, 2);
|
||||
PasswordTextBox.Name = "PasswordTextBox";
|
||||
PasswordTextBox.Size = new Size(335, 23);
|
||||
PasswordTextBox.TabIndex = 5;
|
||||
//
|
||||
// PasswordLabel
|
||||
//
|
||||
PasswordLabel.AutoSize = true;
|
||||
PasswordLabel.Location = new Point(10, 43);
|
||||
PasswordLabel.Name = "PasswordLabel";
|
||||
PasswordLabel.Size = new Size(52, 15);
|
||||
PasswordLabel.TabIndex = 4;
|
||||
PasswordLabel.Text = "Пароль:";
|
||||
//
|
||||
// WorkExperienceLabel
|
||||
//
|
||||
WorkExperienceLabel.AutoSize = true;
|
||||
WorkExperienceLabel.Location = new Point(10, 75);
|
||||
WorkExperienceLabel.Name = "WorkExperienceLabel";
|
||||
WorkExperienceLabel.Size = new Size(84, 15);
|
||||
WorkExperienceLabel.TabIndex = 6;
|
||||
WorkExperienceLabel.Text = "Опыт работы:";
|
||||
//
|
||||
// WorkExperienceNumericUpDown
|
||||
//
|
||||
WorkExperienceNumericUpDown.Location = new Point(137, 73);
|
||||
WorkExperienceNumericUpDown.Margin = new Padding(3, 2, 3, 2);
|
||||
WorkExperienceNumericUpDown.Name = "WorkExperienceNumericUpDown";
|
||||
WorkExperienceNumericUpDown.Size = new Size(108, 23);
|
||||
WorkExperienceNumericUpDown.TabIndex = 8;
|
||||
//
|
||||
// QualificationNumericUpDown
|
||||
//
|
||||
QualificationNumericUpDown.Location = new Point(137, 106);
|
||||
QualificationNumericUpDown.Margin = new Padding(3, 2, 3, 2);
|
||||
QualificationNumericUpDown.Name = "QualificationNumericUpDown";
|
||||
QualificationNumericUpDown.Size = new Size(108, 23);
|
||||
QualificationNumericUpDown.TabIndex = 10;
|
||||
//
|
||||
// QualificationLabel
|
||||
//
|
||||
QualificationLabel.AutoSize = true;
|
||||
QualificationLabel.Location = new Point(10, 108);
|
||||
QualificationLabel.Name = "QualificationLabel";
|
||||
QualificationLabel.Size = new Size(91, 15);
|
||||
QualificationLabel.TabIndex = 9;
|
||||
QualificationLabel.Text = "Квалификация:";
|
||||
//
|
||||
// CancelButton
|
||||
//
|
||||
CancelButton.Location = new Point(353, 142);
|
||||
CancelButton.Margin = new Padding(3, 2, 3, 2);
|
||||
CancelButton.Name = "CancelButton";
|
||||
CancelButton.Size = new Size(119, 30);
|
||||
CancelButton.TabIndex = 12;
|
||||
CancelButton.Text = "Отмена";
|
||||
CancelButton.UseVisualStyleBackColor = true;
|
||||
CancelButton.Click += CancelButton_Click;
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
SaveButton.Location = new Point(233, 142);
|
||||
SaveButton.Margin = new Padding(3, 2, 3, 2);
|
||||
SaveButton.Name = "SaveButton";
|
||||
SaveButton.Size = new Size(114, 30);
|
||||
SaveButton.TabIndex = 11;
|
||||
SaveButton.Text = "Сохранить";
|
||||
SaveButton.UseVisualStyleBackColor = true;
|
||||
SaveButton.Click += SaveButton_Click;
|
||||
//
|
||||
// FormImplementer
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(482, 183);
|
||||
Controls.Add(CancelButton);
|
||||
Controls.Add(SaveButton);
|
||||
Controls.Add(QualificationNumericUpDown);
|
||||
Controls.Add(QualificationLabel);
|
||||
Controls.Add(WorkExperienceNumericUpDown);
|
||||
Controls.Add(WorkExperienceLabel);
|
||||
Controls.Add(PasswordTextBox);
|
||||
Controls.Add(PasswordLabel);
|
||||
Controls.Add(FioTextBox);
|
||||
Controls.Add(FioLabel);
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "FormImplementer";
|
||||
Text = "Исполнитель";
|
||||
Load += FormImplementer_Load;
|
||||
((System.ComponentModel.ISupportInitialize)WorkExperienceNumericUpDown).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)QualificationNumericUpDown).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TextBox FioTextBox;
|
||||
private Label FioLabel;
|
||||
private TextBox PasswordTextBox;
|
||||
private Label PasswordLabel;
|
||||
private Label WorkExperienceLabel;
|
||||
private NumericUpDown WorkExperienceNumericUpDown;
|
||||
private NumericUpDown QualificationNumericUpDown;
|
||||
private Label QualificationLabel;
|
||||
private Button CancelButton;
|
||||
private Button SaveButton;
|
||||
}
|
||||
}
|
105
Bar/Bar/Forms/FormImplementer.cs
Normal file
105
Bar/Bar/Forms/FormImplementer.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicsContracts;
|
||||
using BarContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BarView.Forms
|
||||
{
|
||||
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 FormImplementer_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Получение исполнителя");
|
||||
|
||||
var View = _logic.ReadElement(new ImplementerSearchModel
|
||||
{
|
||||
Id = _id.Value
|
||||
});
|
||||
|
||||
if (View != null)
|
||||
{
|
||||
FioTextBox.Text = View.ImplementerFIO;
|
||||
PasswordTextBox.Text = View.Password;
|
||||
WorkExperienceNumericUpDown.Value = View.WorkExperience;
|
||||
QualificationNumericUpDown.Value = View.Qualification;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения исполнителя");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(FioTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(PasswordTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Сохранение исполнителя");
|
||||
|
||||
try
|
||||
{
|
||||
var Model = new ImplementerBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ImplementerFIO = FioTextBox.Text,
|
||||
Password = PasswordTextBox.Text,
|
||||
WorkExperience = (int)WorkExperienceNumericUpDown.Value,
|
||||
Qualification = (int)QualificationNumericUpDown.Value
|
||||
};
|
||||
|
||||
var OperationResult = _id.HasValue ? _logic.Update(Model) : _logic.Create(Model);
|
||||
if (!OperationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при создании или обновлении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения исполнителя");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
Bar/Bar/Forms/FormImplementer.resx
Normal file
120
Bar/Bar/Forms/FormImplementer.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
136
Bar/Bar/Forms/FormImplementers.Designer.cs
generated
Normal file
136
Bar/Bar/Forms/FormImplementers.Designer.cs
generated
Normal file
@ -0,0 +1,136 @@
|
||||
namespace BarView.Forms
|
||||
{
|
||||
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()
|
||||
{
|
||||
ToolsPanel = new Panel();
|
||||
RefreshButton = new Button();
|
||||
DeleteButton = new Button();
|
||||
UpdateButton = new Button();
|
||||
AddButton = new Button();
|
||||
DataGridView = new DataGridView();
|
||||
ToolsPanel.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// ToolsPanel
|
||||
//
|
||||
ToolsPanel.Controls.Add(RefreshButton);
|
||||
ToolsPanel.Controls.Add(DeleteButton);
|
||||
ToolsPanel.Controls.Add(UpdateButton);
|
||||
ToolsPanel.Controls.Add(AddButton);
|
||||
ToolsPanel.Location = new Point(532, 9);
|
||||
ToolsPanel.Margin = new Padding(3, 2, 3, 2);
|
||||
ToolsPanel.Name = "ToolsPanel";
|
||||
ToolsPanel.Size = new Size(116, 320);
|
||||
ToolsPanel.TabIndex = 3;
|
||||
//
|
||||
// RefreshButton
|
||||
//
|
||||
RefreshButton.Location = new Point(3, 126);
|
||||
RefreshButton.Margin = new Padding(3, 2, 3, 2);
|
||||
RefreshButton.Name = "RefreshButton";
|
||||
RefreshButton.Size = new Size(110, 27);
|
||||
RefreshButton.TabIndex = 3;
|
||||
RefreshButton.Text = "Обновить";
|
||||
RefreshButton.UseVisualStyleBackColor = true;
|
||||
RefreshButton.Click += RefreshButton_Click;
|
||||
//
|
||||
// DeleteButton
|
||||
//
|
||||
DeleteButton.Location = new Point(3, 84);
|
||||
DeleteButton.Margin = new Padding(3, 2, 3, 2);
|
||||
DeleteButton.Name = "DeleteButton";
|
||||
DeleteButton.Size = new Size(110, 27);
|
||||
DeleteButton.TabIndex = 2;
|
||||
DeleteButton.Text = "Удалить";
|
||||
DeleteButton.UseVisualStyleBackColor = true;
|
||||
DeleteButton.Click += DeleteButton_Click;
|
||||
//
|
||||
// UpdateButton
|
||||
//
|
||||
UpdateButton.Location = new Point(3, 42);
|
||||
UpdateButton.Margin = new Padding(3, 2, 3, 2);
|
||||
UpdateButton.Name = "UpdateButton";
|
||||
UpdateButton.Size = new Size(110, 27);
|
||||
UpdateButton.TabIndex = 1;
|
||||
UpdateButton.Text = "Изменить";
|
||||
UpdateButton.UseVisualStyleBackColor = true;
|
||||
UpdateButton.Click += UpdateButton_Click;
|
||||
//
|
||||
// AddButton
|
||||
//
|
||||
AddButton.Location = new Point(3, 2);
|
||||
AddButton.Margin = new Padding(3, 2, 3, 2);
|
||||
AddButton.Name = "AddButton";
|
||||
AddButton.Size = new Size(110, 27);
|
||||
AddButton.TabIndex = 0;
|
||||
AddButton.Text = "Добавить";
|
||||
AddButton.UseVisualStyleBackColor = true;
|
||||
AddButton.Click += AddButton_Click;
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
DataGridView.AllowUserToAddRows = false;
|
||||
DataGridView.AllowUserToDeleteRows = false;
|
||||
DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
DataGridView.Location = new Point(10, 9);
|
||||
DataGridView.Margin = new Padding(3, 2, 3, 2);
|
||||
DataGridView.Name = "DataGridView";
|
||||
DataGridView.ReadOnly = true;
|
||||
DataGridView.RowHeadersWidth = 51;
|
||||
DataGridView.RowTemplate.Height = 29;
|
||||
DataGridView.Size = new Size(516, 320);
|
||||
DataGridView.TabIndex = 2;
|
||||
//
|
||||
// FormImplementers
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(653, 338);
|
||||
Controls.Add(ToolsPanel);
|
||||
Controls.Add(DataGridView);
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "FormImplementers";
|
||||
Text = "Исполнители";
|
||||
Load += FormImplementers_Load;
|
||||
ToolsPanel.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Panel ToolsPanel;
|
||||
private Button RefreshButton;
|
||||
private Button DeleteButton;
|
||||
private Button UpdateButton;
|
||||
private Button AddButton;
|
||||
private DataGridView DataGridView;
|
||||
}
|
||||
}
|
111
Bar/Bar/Forms/FormImplementers.cs
Normal file
111
Bar/Bar/Forms/FormImplementers.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BarView.Forms
|
||||
{
|
||||
public partial class FormImplementers : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImplementerLogic _implementerLogic;
|
||||
|
||||
public FormImplementers(ILogger<FormImplementers> Logger, IImplementerLogic ImplementerLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_logger = Logger;
|
||||
_implementerLogic = ImplementerLogic;
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var List = _implementerLogic.ReadList(null);
|
||||
|
||||
if (List != null)
|
||||
{
|
||||
DataGridView.DataSource = List;
|
||||
DataGridView.Columns["Id"].Visible = false;
|
||||
DataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Загрузка исполнителей");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки исполнителей");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void FormImplementers_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void AddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
|
||||
|
||||
if (Service is FormImplementer Form)
|
||||
{
|
||||
if (Form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
|
||||
if (service is FormImplementer Form)
|
||||
{
|
||||
Form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (Form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Удаление исполнителя");
|
||||
|
||||
try
|
||||
{
|
||||
if (!_implementerLogic.Delete(new ImplementerBindingModel
|
||||
{
|
||||
Id = Id
|
||||
}))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления исполнителя");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
120
Bar/Bar/Forms/FormImplementers.resx
Normal file
120
Bar/Bar/Forms/FormImplementers.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -8,6 +8,8 @@ using BarView.Forms;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
using BarContracts.BusinessLogicsContracts;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
|
||||
|
||||
namespace BarView
|
||||
@ -41,12 +43,16 @@ namespace BarView
|
||||
Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
Services.AddTransient<ICocktailStorage, CocktailStorage>();
|
||||
|
||||
Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||
|
||||
Services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
Services.AddTransient<ICocktailLogic, CocktailLogic>();
|
||||
Services.AddTransient<IReportLogic, ReportLogic>();
|
||||
Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||
Services.AddTransient<IWorkProcess, WorkModeling>();
|
||||
|
||||
Services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
@ -62,6 +68,8 @@ namespace BarView
|
||||
Services.AddTransient<FormReportCocktailComponents>();
|
||||
Services.AddTransient<FormReportOrders>();
|
||||
Services.AddTransient<FormClients>();
|
||||
Services.AddTransient<FormImplementers>();
|
||||
Services.AddTransient<FormImplementer>();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicsContracts;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.StoragesContracts;
|
||||
using BarContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BarBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ImplementerLogic : IImplementerLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImplementerStorage _implementerStorage;
|
||||
|
||||
public ImplementerLogic(ILogger<IImplementerLogic> Logger, IImplementerStorage ImplementerStorage)
|
||||
{
|
||||
_logger = Logger;
|
||||
_implementerStorage = ImplementerStorage;
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel>? ReadList(ImplementerSearchModel? Model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ImplementerFIO: {ImplementerFIO}. Password: {Password}. Id: {Id}",
|
||||
Model?.ImplementerFIO, Model?.Password?.Length, 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 ImplementerViewModel? ReadElement(ImplementerSearchModel Model)
|
||||
{
|
||||
if (Model is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. ImplementerFIO: {ImplementerFIO}. Password: {Password}. Id: {Id}",
|
||||
Model?.ImplementerFIO, Model?.Password?.Length, 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 bool Create(ImplementerBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
|
||||
if (_implementerStorage.Insert(Model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ImplementerBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
|
||||
if (_implementerStorage.Update(Model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update 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;
|
||||
}
|
||||
|
||||
private void CheckModel(ImplementerBindingModel Model, bool WithParams = true)
|
||||
{
|
||||
if (Model == null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
if (!WithParams)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(Model.ImplementerFIO))
|
||||
throw new ArgumentNullException("Нет ФИО исполнителя", nameof(Model.ImplementerFIO));
|
||||
|
||||
if (string.IsNullOrEmpty(Model.Password))
|
||||
throw new ArgumentNullException("Нет пароля исполнителя", nameof(Model.Password));
|
||||
|
||||
if (Model.WorkExperience < 0)
|
||||
throw new ArgumentNullException("Стаж должен быть неотрицательным целым числом", nameof(Model.WorkExperience));
|
||||
|
||||
if (Model.Qualification < 0)
|
||||
throw new ArgumentNullException("Квалификация должна быть неотрицательным целым числом", nameof(Model.Qualification));
|
||||
|
||||
_logger.LogInformation("Implementer. ImplementerFIO: {ImplementerFIO}. Password: {Password}. WorkExperience: {WorkExperience}. Qualification: {Qualification}. Id: {Id}",
|
||||
Model.ImplementerFIO, Model.Password, Model.WorkExperience, Model.Qualification, Model.Id);
|
||||
|
||||
var Implementer = _implementerStorage.GetElement(new ImplementerSearchModel
|
||||
{
|
||||
ImplementerFIO = Model.ImplementerFIO
|
||||
});
|
||||
|
||||
if (Implementer != null && Implementer.Id != Model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Исполнитель с таким ФИО уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -76,6 +76,8 @@ namespace BarBusinessLogic.BusinessLogics
|
||||
}
|
||||
|
||||
Model.CocktailId = Order.CocktailId;
|
||||
Model.ClientId = Order.ClientId;
|
||||
if (!Model.ImplementerId.HasValue) Model.ImplementerId = Order.ImplementerId;
|
||||
Model.Count = Order.Count;
|
||||
Model.Sum = Order.Sum;
|
||||
Model.DateCreate = Order.DateCreate;
|
||||
@ -129,5 +131,27 @@ namespace BarBusinessLogic.BusinessLogics
|
||||
Model.CocktailId, Model.Count, Model.Sum, Model.Status, Model.DateCreate,
|
||||
Model.DateImplement, Model.Id);
|
||||
}
|
||||
|
||||
public OrderViewModel? ReadElement(OrderSearchModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. ClientId: {ClientId}. Status: {Status}. ImplementerId: {ImplementerId}. DateFrom: {DateFrom}. DateTo: {DateTo}. OrderId: {Id}",
|
||||
Model.ClientId, Model.Status, Model.ImplementerId, Model.DateFrom, Model.DateTo, Model.Id);
|
||||
|
||||
var Order = _orderStorage.GetElement(Model);
|
||||
|
||||
if (Order == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id: {Id}", Order.Id);
|
||||
return Order;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,153 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using BarContracts.BusinessLogicsContracts;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BarBusinessLogic.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 = OrderStatus.Accepted });
|
||||
var BeingProcessedOrders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.BeingProcessed });
|
||||
// in case there are BeingProcessed orders but no Accepted orders
|
||||
|
||||
if (Orders == null || BeingProcessedOrders == null || (Orders.Count == 0 && BeingProcessedOrders.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 || Implementer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await RunOrderInWork(Implementer);
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
foreach (var Order in Orders)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogDebug("WorkerWorkAsync. Worker {Id} try get order {Order}", Implementer.Id, Order.Id);
|
||||
|
||||
// TakeOrderInWork will fail when the worker tries to change status to BeingProcessed when the order is already BeingProcessed
|
||||
// which would happen when other worker already acquired that order
|
||||
bool AcquireResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||
{
|
||||
Id = Order.Id,
|
||||
ImplementerId = Implementer.Id
|
||||
});
|
||||
|
||||
if (!AcquireResult)
|
||||
{
|
||||
_logger.LogDebug("WorkerWorkAsync. Worker {Id} tried to get order {Order} but it's already acquired by other worker", Implementer.Id, Order.Id);
|
||||
continue;
|
||||
}
|
||||
|
||||
Thread.Sleep(Implementer.WorkExperience * _rnd.Next(100, 1000) * Order.Count);
|
||||
|
||||
_logger.LogDebug("WorkerWorkAsync. Worker {Id} finish order {Order}", Implementer.Id, Order.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = Order.Id
|
||||
});
|
||||
}
|
||||
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
|
||||
Thread.Sleep(Implementer.Qualification * _rnd.Next(10, 100));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task RunOrderInWork(ImplementerViewModel Implementer)
|
||||
{
|
||||
if (_orderLogic == null || Implementer == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var RunOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
|
||||
{
|
||||
ImplementerId = Implementer.Id,
|
||||
Status = OrderStatus.BeingProcessed
|
||||
}));
|
||||
|
||||
if (RunOrder == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogDebug("RunOrderInWork. Worker {Id} back to order {Order}", Implementer.Id, RunOrder.Id);
|
||||
Thread.Sleep(Implementer.WorkExperience * _rnd.Next(100, 300) * RunOrder.Count);
|
||||
|
||||
_logger.LogDebug("RunOrderInWork. 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace BarContracts.BindingModels
|
||||
{
|
||||
public class CocktailBindingModel : ICocktailModel
|
||||
public class CocktailBindingModel : ICocktailModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string CocktailName { get; set; } = string.Empty;
|
||||
|
@ -0,0 +1,17 @@
|
||||
using BarDataModels.Models;
|
||||
|
||||
namespace BarContracts.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; }
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ namespace BarContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public int CocktailId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Undefined;
|
||||
|
@ -3,9 +3,9 @@
|
||||
public class ReportBindingModel
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
|
||||
|
||||
public DateTime? DateFrom { get; set; }
|
||||
|
||||
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.ViewModels;
|
||||
|
||||
namespace BarContracts.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);
|
||||
}
|
||||
}
|
@ -11,5 +11,6 @@ namespace BarContracts.BusinessLogicContracts
|
||||
bool TakeOrderInWork(OrderBindingModel Model);
|
||||
bool FinishOrder(OrderBindingModel Model);
|
||||
bool DeliveryOrder(OrderBindingModel Model);
|
||||
OrderViewModel? ReadElement(OrderSearchModel Model);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
using BarContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace BarContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IWorkProcess
|
||||
{
|
||||
void DoWork(IImplementerLogic ImplementerLogic, IOrderLogic OrderLogic);
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
|
||||
namespace BarContracts.SearchModels
|
||||
namespace BarContracts.SearchModels
|
||||
{
|
||||
public class ComponentSearchModel
|
||||
{
|
||||
|
@ -0,0 +1,11 @@
|
||||
namespace BarContracts.SearchModels
|
||||
{
|
||||
public class ImplementerSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string? ImplementerFIO { get; set; }
|
||||
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
}
|
@ -1,12 +1,19 @@
|
||||
namespace BarContracts.SearchModels
|
||||
using BarDataModels.Enums;
|
||||
|
||||
namespace BarContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public OrderStatus? Status { get; set; }
|
||||
|
||||
public int? ImplementerId { get; set; }
|
||||
|
||||
public DateTime? DateFrom { get; set; }
|
||||
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.ViewModels;
|
||||
|
||||
namespace BarContracts.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);
|
||||
}
|
||||
}
|
@ -7,12 +7,12 @@ namespace BarContracts.ViewModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название Коктейля")]
|
||||
[DisplayName("Название Коктейльа")]
|
||||
public string CocktailName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
[DisplayName("Цена")]
|
||||
public double Price { get; set; }
|
||||
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> CocktailComponents
|
||||
{
|
||||
get;
|
||||
|
@ -7,10 +7,10 @@ namespace BarContracts.ViewModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название компонента")]
|
||||
[DisplayName("Название компонента")]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
using BarDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace BarContracts.ViewModels
|
||||
{
|
||||
public class ImplementerViewModel : IImplementerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("ФИО исполнителя")]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Стаж работы")]
|
||||
public int WorkExperience { get; set; }
|
||||
|
||||
[DisplayName("Квалификация")]
|
||||
public int Qualification { get; set; }
|
||||
}
|
||||
}
|
@ -2,34 +2,40 @@
|
||||
using BarDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
|
||||
namespace BarContracts.ViewModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
public int CocktailId { get; set; }
|
||||
|
||||
[DisplayName("Коктейль")]
|
||||
public string CocktailName { get; set; } = string.Empty;
|
||||
public int ClientId { get; set; }
|
||||
|
||||
public int ClientId { get; set; }
|
||||
|
||||
[DisplayName("Клиент")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
|
||||
public int? ImplementerId { get; set; }
|
||||
|
||||
[DisplayName("Исполнитель")]
|
||||
public string? ImplementerFIO { get; set; }
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
|
||||
|
||||
[DisplayName("Статус")]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Undefined;
|
||||
|
||||
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
|
||||
|
||||
[DisplayName("Дата выполнения")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
namespace BarContracts.ViewModels
|
||||
{
|
||||
public class ReportCocktailComponentViewModel
|
||||
{
|
||||
public string CocktailName { get; set; } = string.Empty;
|
||||
|
||||
public int TotalCount { get; set; }
|
||||
|
||||
public List<(string Component, int Count)> Components { get; set; } = new();
|
||||
}
|
||||
}
|
@ -3,13 +3,13 @@
|
||||
public class ReportOrdersViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
public DateTime DateCreate { get; set; }
|
||||
|
||||
|
||||
public string CocktailName { get; set; } = string.Empty;
|
||||
|
||||
|
||||
public double Sum { get; set; }
|
||||
|
||||
|
||||
public string Status { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
13
Bar/BarDataModels/BarDataModels/Models/IImplementerModel.cs
Normal file
13
Bar/BarDataModels/BarDataModels/Models/IImplementerModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace BarDataModels.Models
|
||||
{
|
||||
public interface IImplementerModel : IId
|
||||
{
|
||||
string ImplementerFIO { get; }
|
||||
|
||||
string Password { get; }
|
||||
|
||||
int WorkExperience { get; }
|
||||
|
||||
int Qualification { get; }
|
||||
}
|
||||
}
|
@ -27,5 +27,7 @@ namespace BarDatabaseImplement
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
|
||||
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,90 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.StoragesContracts;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDatabaseImplement.Models;
|
||||
|
||||
namespace BarDatabaseImplement.Implements
|
||||
{
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
return Context.Implementers.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ImplementerFIO))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var Context = new BarDatabase();
|
||||
return Context.Implementers.Where(x => x.ImplementerFIO.Contains(Model.ImplementerFIO)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ImplementerFIO) && !Model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
return Context.Implementers.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(Model.ImplementerFIO) && x.ImplementerFIO == Model.ImplementerFIO && (!string.IsNullOrEmpty(Model.Password) ? x.Password == Model.Password : true)) ||
|
||||
(Model.Id.HasValue && x.Id == Model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel Model)
|
||||
{
|
||||
var NewImplementer = Implementer.Create(Model);
|
||||
if (NewImplementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
Context.Implementers.Add(NewImplementer);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewImplementer.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel Model)
|
||||
{
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
var Implementer = Context.Implementers.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (Implementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Implementer.Update(Model);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Implementer.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel Model)
|
||||
{
|
||||
using var Context = new BarDatabase();
|
||||
|
||||
var Implementer = Context.Implementers.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
if (Implementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Context.Implementers.Remove(Implementer);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Implementer.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ namespace BarDatabaseImplement.Implements
|
||||
return Context.Orders
|
||||
.Include(x => x.Cocktail)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -29,6 +30,7 @@ namespace BarDatabaseImplement.Implements
|
||||
return Context.Orders
|
||||
.Include(x => x.Cocktail)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@ -37,14 +39,18 @@ namespace BarDatabaseImplement.Implements
|
||||
return Context.Orders
|
||||
.Include(x => x.Cocktail)
|
||||
.Include(x => x.Client)
|
||||
.Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId))
|
||||
.Include(x => x.Implementer)
|
||||
.Where(x => (Model.Id.HasValue && x.Id == Model.Id)
|
||||
|| (Model.ClientId.HasValue && x.ClientId == Model.ClientId)
|
||||
|| (Model.ImplementerId.HasValue && x.ImplementerId == Model.ImplementerId)
|
||||
|| (Model.Status.HasValue && x.Status == Model.Status))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
if (!Model.Id.HasValue && !Model.ImplementerId.HasValue && !Model.Status.HasValue)
|
||||
return null;
|
||||
|
||||
using var Context = new BarDatabase();
|
||||
@ -52,7 +58,9 @@ namespace BarDatabaseImplement.Implements
|
||||
return Context.Orders
|
||||
.Include(x => x.Cocktail)
|
||||
.Include(x => x.Client)
|
||||
.FirstOrDefault(x => Model.Id.HasValue && x.Id == Model.Id)?
|
||||
.Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => (Model.Id.HasValue && x.Id == Model.Id)
|
||||
|| (Model.ImplementerId.HasValue && Model.Status.HasValue && x.ImplementerId == Model.ImplementerId && x.Status == Model.Status))?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
@ -70,7 +78,7 @@ namespace BarDatabaseImplement.Implements
|
||||
Context.Orders.Add(NewOrder);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Context.Orders.Include(x => x.Cocktail).Include(x => x.Client).FirstOrDefault(x => x.Id == NewOrder.Id)?.GetViewModel;
|
||||
return Context.Orders.Include(x => x.Cocktail).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == NewOrder.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel Model)
|
||||
@ -84,13 +92,13 @@ namespace BarDatabaseImplement.Implements
|
||||
Order.Update(Model);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Context.Orders.Include(x => x.Cocktail).Include(x => x.Client).FirstOrDefault(x => x.Id == Model.Id)?.GetViewModel;
|
||||
return Context.Orders.Include(x => x.Cocktail).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == Model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel Model)
|
||||
{
|
||||
using var Context = new BarDatabase();
|
||||
var Order = Context.Orders.Include(x => x.Cocktail).Include(x => x.Client).FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
var Order = Context.Orders.Include(x => x.Cocktail).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
254
Bar/BarDatabaseImplement/BarDatabaseImplement/Migrations/20240621140852_2.Designer.cs
generated
Normal file
254
Bar/BarDatabaseImplement/BarDatabaseImplement/Migrations/20240621140852_2.Designer.cs
generated
Normal file
@ -0,0 +1,254 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using BarDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace BarDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(BarDatabase))]
|
||||
[Migration("20240621140852_2")]
|
||||
partial class _2
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ClientFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Cocktail", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("CocktailName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Cocktails");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.CocktailComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CocktailId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.ToTable("CocktailComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ImplementerFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Implementers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("CocktailId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int?>("ImplementerId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.HasIndex("ImplementerId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.CocktailComponent", b =>
|
||||
{
|
||||
b.HasOne("BarDatabaseImplement.Models.Cocktail", "Cocktail")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("CocktailId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BarDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("CocktailComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
|
||||
b.Navigation("Component");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("BarDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BarDatabaseImplement.Models.Cocktail", "Cocktail")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("CocktailId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BarDatabaseImplement.Models.Implementer", null)
|
||||
.WithMany("Order")
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Cocktail", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("CocktailComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Navigation("Order");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace BarDatabaseImplement.Migrations
|
||||
{
|
||||
public partial class _2 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "ImplementerId",
|
||||
table: "Orders",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Implementers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
ImplementerFIO = table.Column<string>(type: "text", nullable: false),
|
||||
Password = table.Column<string>(type: "text", nullable: false),
|
||||
WorkExperience = table.Column<int>(type: "integer", nullable: false),
|
||||
Qualification = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Implementers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ImplementerId",
|
||||
table: "Orders",
|
||||
column: "ImplementerId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Orders_Implementers_ImplementerId",
|
||||
table: "Orders",
|
||||
column: "ImplementerId",
|
||||
principalTable: "Implementers",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Orders_Implementers_ImplementerId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Implementers");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Orders_ImplementerId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ImplementerId",
|
||||
table: "Orders");
|
||||
}
|
||||
}
|
||||
}
|
@ -113,6 +113,33 @@ namespace BarDatabaseImplement.Migrations
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ImplementerFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Implementers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -136,6 +163,9 @@ namespace BarDatabaseImplement.Migrations
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.Property<int?>("ImplementerId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
@ -148,6 +178,8 @@ namespace BarDatabaseImplement.Migrations
|
||||
|
||||
b.HasIndex("CocktailId");
|
||||
|
||||
b.HasIndex("ImplementerId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
@ -184,6 +216,10 @@ namespace BarDatabaseImplement.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("BarDatabaseImplement.Models.Implementer", null)
|
||||
.WithMany("Order")
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Cocktail");
|
||||
@ -205,6 +241,11 @@ namespace BarDatabaseImplement.Migrations
|
||||
{
|
||||
b.Navigation("CocktailComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BarDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Navigation("Order");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace BarDatabaseImplement.Models
|
||||
{
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int WorkExperience { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Qualification { get; set; }
|
||||
|
||||
[ForeignKey("ImplementerId")]
|
||||
public virtual List<Order> Order { get; set; } = new();
|
||||
|
||||
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 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
|
||||
};
|
||||
}
|
||||
}
|
@ -19,7 +19,10 @@ namespace BarDatabaseImplement.Models
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public virtual Client Client { get; set; }
|
||||
|
||||
public int? ImplementerId { get; private set; }
|
||||
|
||||
public virtual Implementer? Implementer { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
@ -44,6 +47,7 @@ namespace BarDatabaseImplement.Models
|
||||
Id = Model.Id,
|
||||
CocktailId = Model.CocktailId,
|
||||
ClientId = Model.ClientId,
|
||||
ImplementerId = Model.ImplementerId,
|
||||
Count = Model.Count,
|
||||
Sum = Model.Sum,
|
||||
Status = Model.Status,
|
||||
@ -57,6 +61,7 @@ namespace BarDatabaseImplement.Models
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
ImplementerId = Model.ImplementerId;
|
||||
Status = Model.Status;
|
||||
DateImplement = Model.DateImplement;
|
||||
}
|
||||
@ -66,8 +71,10 @@ namespace BarDatabaseImplement.Models
|
||||
Id = Id,
|
||||
CocktailId = CocktailId,
|
||||
ClientId = ClientId,
|
||||
ImplementerId = ImplementerId,
|
||||
CocktailName = Cocktail.CocktailName,
|
||||
ClientFIO = Client.ClientFIO,
|
||||
ImplementerFIO = Implementer?.ImplementerFIO,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
108
Bar/BarRestApi/Controllers/ImplementerController.cs
Normal file
108
Bar/BarRestApi/Controllers/ImplementerController.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using BarContracts.BusinessLogicsContracts;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDataModels.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BarRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ImplementerController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IOrderLogic _order;
|
||||
|
||||
private readonly IImplementerLogic _logic;
|
||||
|
||||
public ImplementerController(IOrderLogic Order, IImplementerLogic Logic, ILogger<ImplementerController> Logger)
|
||||
{
|
||||
_logger = Logger;
|
||||
_order = Order;
|
||||
_logic = Logic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ImplementerViewModel? Login(string login, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new ImplementerSearchModel
|
||||
{
|
||||
ImplementerFIO = login,
|
||||
Password = password
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка авторизации сотрудника");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<OrderViewModel>? GetNewOrders()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _order.ReadList(new OrderSearchModel
|
||||
{
|
||||
Status = OrderStatus.Accepted
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения новых заказов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public OrderViewModel? GetImplementerOrder(int implementerId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _order.ReadElement(new OrderSearchModel
|
||||
{
|
||||
ImplementerId = implementerId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения текущего заказа исполнителя");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void TakeOrderInWork(OrderBindingModel Model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_order.TakeOrderInWork(Model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", Model.Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void FinishOrder(OrderBindingModel Model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_order.FinishOrder(Model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", Model.Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user