Compare commits
No commits in common. "e6dc60cd936c89cb0f5a78b38b05916a3a1ce753" and "411f4368076c6074dd320b70f8ffc9da405f99dd" have entirely different histories.
e6dc60cd93
...
411f436807
@ -3,17 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.4.33213.308
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlant", "AutomobilePlant\AutomobilePlant.csproj", "{970E66D6-3147-419D-98DC-9E05B10232B5}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlant", "AutomobilePlant\AutomobilePlant.csproj", "{970E66D6-3147-419D-98DC-9E05B10232B5}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantDataModels", "AutomobilePlantDataModels\AutomobilePlantDataModels.csproj", "{27B6E4A1-BB53-4AF6-AACA-099A40B64D60}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantDataModels", "AutomobilePlantDataModels\AutomobilePlantDataModels.csproj", "{27B6E4A1-BB53-4AF6-AACA-099A40B64D60}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantContracts", "AutomobilePlantContracts\AutomobilePlantContracts.csproj", "{2F1D0A55-2722-48B4-87D1-0440E74D6E0A}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantContracts", "AutomobilePlantContracts\AutomobilePlantContracts.csproj", "{2F1D0A55-2722-48B4-87D1-0440E74D6E0A}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantBusinessLogic", "AutomobilePlantBusinessLogic\AutomobilePlantBusinessLogic.csproj", "{CC4E3C20-ABA4-4A54-B992-B68D39A1236E}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantBusinessLogic", "AutomobilePlantBusinessLogic\AutomobilePlantBusinessLogic.csproj", "{CC4E3C20-ABA4-4A54-B992-B68D39A1236E}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantListImplements", "AutomobilePlantListImplements\AutomobilePlantListImplements.csproj", "{B27736FF-39E9-4DEC-BCB4-35ACAF5ECEB9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantFileImplement", "AutomobilePlantFileImplement\AutomobilePlantFileImplement.csproj", "{10818526-654C-4928-985F-9C02A2A02B15}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantListImplements", "AutomobilePlantListImplements\AutomobilePlantListImplements.csproj", "{B27736FF-39E9-4DEC-BCB4-35ACAF5ECEB9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -41,10 +39,6 @@ Global
|
||||
{B27736FF-39E9-4DEC-BCB4-35ACAF5ECEB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B27736FF-39E9-4DEC-BCB4-35ACAF5ECEB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B27736FF-39E9-4DEC-BCB4-35ACAF5ECEB9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{10818526-654C-4928-985F-9C02A2A02B15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{10818526-654C-4928-985F-9C02A2A02B15}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{10818526-654C-4928-985F-9C02A2A02B15}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{10818526-654C-4928-985F-9C02A2A02B15}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -17,7 +17,6 @@
|
||||
<ProjectReference Include="..\AutomobilePlantBusinessLogic\AutomobilePlantBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\AutomobilePlantContracts\AutomobilePlantContracts.csproj" />
|
||||
<ProjectReference Include="..\AutomobilePlantDataModels\AutomobilePlantDataModels.csproj" />
|
||||
<ProjectReference Include="..\AutomobilePlantFileImplement\AutomobilePlantFileImplement.csproj" />
|
||||
<ProjectReference Include="..\AutomobilePlantListImplements\AutomobilePlantListImplements.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
13
AutomobilePlant/AutomobilePlant/FormMain.Designer.cs
generated
13
AutomobilePlant/AutomobilePlant/FormMain.Designer.cs
generated
@ -40,7 +40,6 @@
|
||||
this.buttonSetToDone = new System.Windows.Forms.Button();
|
||||
this.buttonSetToFinish = new System.Windows.Forms.Button();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
this.buttonSellCars = new System.Windows.Forms.Button();
|
||||
this.menuStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -157,22 +156,11 @@
|
||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||
this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click);
|
||||
//
|
||||
// buttonSellCars
|
||||
//
|
||||
this.buttonSellCars.Location = new System.Drawing.Point(969, 218);
|
||||
this.buttonSellCars.Name = "buttonSellCars";
|
||||
this.buttonSellCars.Size = new System.Drawing.Size(194, 29);
|
||||
this.buttonSellCars.TabIndex = 7;
|
||||
this.buttonSellCars.Text = "Продажа автомобилей";
|
||||
this.buttonSellCars.UseVisualStyleBackColor = true;
|
||||
this.buttonSellCars.Click += new System.EventHandler(this.buttonSellCars_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1176, 450);
|
||||
this.Controls.Add(this.buttonSellCars);
|
||||
this.Controls.Add(this.buttonSupplyShop);
|
||||
this.Controls.Add(this.buttonUpdate);
|
||||
this.Controls.Add(this.buttonSetToFinish);
|
||||
@ -207,6 +195,5 @@
|
||||
private Button buttonUpdate;
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private Button buttonSupplyShop;
|
||||
private Button buttonSellCars;
|
||||
}
|
||||
}
|
@ -182,14 +182,5 @@ namespace AutomobilePlant
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSellCars_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell));
|
||||
if (service is FormShopSell form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
29
AutomobilePlant/AutomobilePlant/FormShop.Designer.cs
generated
29
AutomobilePlant/AutomobilePlant/FormShop.Designer.cs
generated
@ -36,12 +36,10 @@
|
||||
this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ColumnCarName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.openingDateLabel = new System.Windows.Forms.Label();
|
||||
this.openingDateTimePicker = new System.Windows.Forms.DateTimePicker();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.labelMaxCount = new System.Windows.Forms.Label();
|
||||
this.textBoxMaxCountCars = new System.Windows.Forms.TextBox();
|
||||
this.openingDateLabel = new System.Windows.Forms.Label();
|
||||
this.openingDateTimePicker = new System.Windows.Forms.DateTimePicker();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -84,11 +82,11 @@
|
||||
this.ColumnId,
|
||||
this.ColumnCarName,
|
||||
this.ColumnCount});
|
||||
this.dataGridView.Location = new System.Drawing.Point(14, 173);
|
||||
this.dataGridView.Location = new System.Drawing.Point(14, 127);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 51;
|
||||
this.dataGridView.RowTemplate.Height = 29;
|
||||
this.dataGridView.Size = new System.Drawing.Size(401, 265);
|
||||
this.dataGridView.Size = new System.Drawing.Size(401, 289);
|
||||
this.dataGridView.TabIndex = 10;
|
||||
//
|
||||
// ColumnId
|
||||
@ -149,28 +147,11 @@
|
||||
this.openingDateTimePicker.Size = new System.Drawing.Size(274, 27);
|
||||
this.openingDateTimePicker.TabIndex = 14;
|
||||
//
|
||||
// labelMaxCount
|
||||
//
|
||||
this.labelMaxCount.AutoSize = true;
|
||||
this.labelMaxCount.Location = new System.Drawing.Point(18, 128);
|
||||
this.labelMaxCount.Name = "labelMaxCount";
|
||||
this.labelMaxCount.Size = new System.Drawing.Size(216, 20);
|
||||
this.labelMaxCount.TabIndex = 13;
|
||||
this.labelMaxCount.Text = "Макс. количество авто";
|
||||
//
|
||||
// textBoxMaxCountCars
|
||||
//
|
||||
this.textBoxMaxCountCars.Location = new System.Drawing.Point(240, 128);
|
||||
this.textBoxMaxCountCars.Name = "textBoxMaxCountCars";
|
||||
this.textBoxMaxCountCars.Size = new System.Drawing.Size(175, 27);
|
||||
this.textBoxMaxCountCars.TabIndex = 14;
|
||||
// FormShop
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(445, 489);
|
||||
this.Controls.Add(this.textBoxMaxCountCars);
|
||||
this.Controls.Add(this.labelMaxCount);
|
||||
this.Controls.Add(this.openingDateTimePicker);
|
||||
this.Controls.Add(this.openingDateLabel);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
@ -203,7 +184,5 @@
|
||||
private DataGridViewTextBoxColumn ColumnCount;
|
||||
private Label openingDateLabel;
|
||||
private DateTimePicker openingDateTimePicker;
|
||||
private Label labelMaxCount;
|
||||
private TextBox textBoxMaxCountCars;
|
||||
}
|
||||
}
|
@ -47,7 +47,6 @@ namespace AutomobilePlant
|
||||
textBoxAddress.Text = view.Address;
|
||||
openingDateTimePicker.Value = view.OpeningDate;
|
||||
_shopCars = view.ShopCars ?? new Dictionary<int, (ICarModel, int)>();
|
||||
textBoxMaxCountCars.Text = view.MaxCountCars.ToString();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
@ -95,12 +94,6 @@ namespace AutomobilePlant
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(textBoxMaxCountCars.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните макс. количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Сохранение магазина");
|
||||
|
||||
try
|
||||
@ -111,8 +104,7 @@ namespace AutomobilePlant
|
||||
Name = textBoxName.Text,
|
||||
Address = textBoxAddress.Text,
|
||||
OpeningDate = openingDateTimePicker.Value.Date,
|
||||
MaxCountCars = Convert.ToInt32(textBoxMaxCountCars.Text),
|
||||
ShopCars = _shopCars
|
||||
ShopCars= _shopCars
|
||||
};
|
||||
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
|
119
AutomobilePlant/AutomobilePlant/FormShopSell.Designer.cs
generated
119
AutomobilePlant/AutomobilePlant/FormShopSell.Designer.cs
generated
@ -1,119 +0,0 @@
|
||||
namespace AutomobilePlant
|
||||
{
|
||||
partial class FormShopSell
|
||||
{
|
||||
/// <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.labelCount = new System.Windows.Forms.Label();
|
||||
this.labelCar = new System.Windows.Forms.Label();
|
||||
this.comboBoxCar = new System.Windows.Forms.ComboBox();
|
||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||
this.buttonSell = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
this.labelCount.AutoSize = true;
|
||||
this.labelCount.Location = new System.Drawing.Point(23, 76);
|
||||
this.labelCount.Name = "labelCount";
|
||||
this.labelCount.Size = new System.Drawing.Size(93, 20);
|
||||
this.labelCount.TabIndex = 1;
|
||||
this.labelCount.Text = "Количество:";
|
||||
//
|
||||
// labelCar
|
||||
//
|
||||
this.labelCar.AutoSize = true;
|
||||
this.labelCar.Location = new System.Drawing.Point(23, 24);
|
||||
this.labelCar.Name = "labelCar";
|
||||
this.labelCar.Size = new System.Drawing.Size(79, 20);
|
||||
this.labelCar.TabIndex = 2;
|
||||
this.labelCar.Text = "Автомобиль:";
|
||||
//
|
||||
// comboBoxCar
|
||||
//
|
||||
this.comboBoxCar.FormattingEnabled = true;
|
||||
this.comboBoxCar.Location = new System.Drawing.Point(124, 24);
|
||||
this.comboBoxCar.Name = "comboBoxCar";
|
||||
this.comboBoxCar.Size = new System.Drawing.Size(278, 28);
|
||||
this.comboBoxCar.TabIndex = 4;
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
this.textBoxCount.Location = new System.Drawing.Point(124, 73);
|
||||
this.textBoxCount.Name = "textBoxCount";
|
||||
this.textBoxCount.Size = new System.Drawing.Size(158, 27);
|
||||
this.textBoxCount.TabIndex = 5;
|
||||
//
|
||||
// buttonSell
|
||||
//
|
||||
this.buttonSell.Location = new System.Drawing.Point(188, 142);
|
||||
this.buttonSell.Name = "buttonSell";
|
||||
this.buttonSell.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonSell.TabIndex = 6;
|
||||
this.buttonSell.Text = "Продажа";
|
||||
this.buttonSell.UseVisualStyleBackColor = true;
|
||||
this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(308, 142);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCancel.TabIndex = 7;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// FormShopSell
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(459, 198);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSell);
|
||||
this.Controls.Add(this.textBoxCount);
|
||||
this.Controls.Add(this.comboBoxCar);
|
||||
this.Controls.Add(this.labelCar);
|
||||
this.Controls.Add(this.labelCount);
|
||||
this.Name = "FormShopSell";
|
||||
this.Text = "Продажа из магазина";
|
||||
this.Load += new System.EventHandler(this.FormShopSell_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
private Label labelCount;
|
||||
private Label labelCar;
|
||||
private ComboBox comboBoxCar;
|
||||
private TextBox textBoxCount;
|
||||
private Button buttonSell;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.BusinessLogicContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
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 AutomobilePlant
|
||||
{
|
||||
public partial class FormShopSell : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICarLogic _logicCar;
|
||||
private readonly IShopLogic _logicShop;
|
||||
|
||||
public FormShopSell(ILogger<FormShopSell> logger, ICarLogic logicCar, IShopLogic logicShop)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicCar = logicCar;
|
||||
_logicShop = logicShop;
|
||||
}
|
||||
|
||||
private void FormShopSell_Load(object sender, EventArgs e)
|
||||
{
|
||||
_logger.LogInformation("Загрузка авто для продажи");
|
||||
try
|
||||
{
|
||||
var list = _logicCar.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxCar.DisplayMember = "CarName";
|
||||
comboBoxCar.ValueMember = "Id";
|
||||
comboBoxCar.DataSource = list;
|
||||
comboBoxCar.SelectedItem = null;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка авто");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSell_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxCar.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите авто", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Создание продажи");
|
||||
try
|
||||
{
|
||||
var operationResult = _logicShop.SellCar(
|
||||
new CarBindingModel
|
||||
{
|
||||
Id = Convert.ToInt32(comboBoxCar.SelectedValue)
|
||||
},
|
||||
Convert.ToInt32(textBoxCount.Text)
|
||||
);
|
||||
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 buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -1,7 +1,7 @@
|
||||
using AutomobilePlantBusinessLogic.BusinessLogics;
|
||||
using AutomobilePlantContracts.BusinessLogicContracts;
|
||||
using AutomobilePlantContracts.StorageContracts;
|
||||
using AutomobilePlantFileImplement.Implements;
|
||||
using AutomobilePlantListImplements.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
@ -48,7 +48,6 @@ namespace AutomobilePlant
|
||||
services.AddTransient<FormShop>();
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormShopSupply>();
|
||||
services.AddTransient<FormShopSell>();
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ using AutomobilePlantContracts.SearchModels;
|
||||
using AutomobilePlantContracts.StorageContracts;
|
||||
using AutomobilePlantContracts.ViewModels;
|
||||
using AutomobilePlantDataModels.Enums;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -18,17 +17,11 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
private readonly IShopLogic _shopLogic;
|
||||
private readonly ICarStorage _carStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, ICarStorage carStorage, IShopStorage shopStorage)
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_shopLogic = shopLogic;
|
||||
_carStorage = carStorage;
|
||||
_shopStorage = shopStorage;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
@ -79,20 +72,6 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
if (newStatus == OrderStatus.Готов)
|
||||
{
|
||||
var car = _carStorage.GetElement(new CarSearchModel() { Id = model.CarId });
|
||||
if (car == null)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Document not found.");
|
||||
return false;
|
||||
}
|
||||
if (CheckThenSupplyMany(car, model.Count) == false)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Shop supply error.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
model.Status = newStatus;
|
||||
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
|
||||
if (_orderStorage.Update(model) == null)
|
||||
@ -104,67 +83,6 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CheckThenSupplyMany(ICarModel car, int count)
|
||||
{
|
||||
if (count <= 0)
|
||||
{
|
||||
_logger.LogWarning("Check then supply operation error. Car count < 0.");
|
||||
return false;
|
||||
}
|
||||
|
||||
int freeSpace = 0;
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
freeSpace += shop.MaxCountCars;
|
||||
foreach (var c in shop.ShopCars)
|
||||
{
|
||||
freeSpace -= c.Value.Item2;
|
||||
}
|
||||
}
|
||||
|
||||
if (freeSpace - count < 0)
|
||||
{
|
||||
_logger.LogWarning("Check then supply operation error. There's no place for new cars in shops.");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
freeSpace = shop.MaxCountCars;
|
||||
foreach (var c in shop.ShopCars)
|
||||
{
|
||||
freeSpace -= c.Value.Item2;
|
||||
}
|
||||
if (freeSpace == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (freeSpace - count >= 0)
|
||||
{
|
||||
if (_shopLogic.SupplyCars(new() { Id = shop.Id }, car, count)) count = 0;
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Supply error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (freeSpace - count < 0)
|
||||
{
|
||||
if (_shopLogic.SupplyCars(new() { Id = shop.Id }, car, freeSpace)) count -= freeSpace;
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Supply error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Выполняется);
|
||||
|
@ -8,7 +8,6 @@ using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -89,39 +88,26 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
|
||||
_logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name);
|
||||
|
||||
var countCars = 0;
|
||||
foreach (var c in shopElement.ShopCars)
|
||||
if (shopElement.ShopCars.TryGetValue(car.Id, out var sameCar))
|
||||
{
|
||||
countCars += c.Value.Item2;
|
||||
}
|
||||
if (shopElement.MaxCountCars - countCars >= count)
|
||||
{
|
||||
if (shopElement.ShopCars.TryGetValue(car.Id, out var sameCar))
|
||||
{
|
||||
shopElement.ShopCars[car.Id] = (car, sameCar.Item2 + count);
|
||||
_logger.LogInformation("Same car found by supply. Added {0} of {1} in {2} shop", count, car.CarName, shopElement.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
shopElement.ShopCars[car.Id] = (car, count);
|
||||
_logger.LogInformation("New car added by supply. Added {0} of {1} in {2} shop", count, car.CarName, shopElement.Name);
|
||||
}
|
||||
_shopStorage.Update(new()
|
||||
{
|
||||
Id = shopElement.Id,
|
||||
Name = shopElement.Name,
|
||||
Address = shopElement.Address,
|
||||
OpeningDate = shopElement.OpeningDate,
|
||||
ShopCars = shopElement.ShopCars,
|
||||
MaxCountCars = shopElement.MaxCountCars
|
||||
});
|
||||
shopElement.ShopCars[car.Id] = (car, sameCar.Item2 + count);
|
||||
_logger.LogInformation("Same car found by supply. Added {0} of {1} in {2} shop", count, car.CarName, shopElement.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Required shop is overflowed");
|
||||
return false;
|
||||
shopElement.ShopCars[car.Id] = (car, count);
|
||||
_logger.LogInformation("New car added by supply. Added {0} of {1} in {2} shop", count, car.CarName, shopElement.Name);
|
||||
}
|
||||
|
||||
_shopStorage.Update(new()
|
||||
{
|
||||
Id = shopElement.Id,
|
||||
Name = shopElement.Name,
|
||||
Address = shopElement.Address,
|
||||
OpeningDate = shopElement.OpeningDate,
|
||||
ShopCars = shopElement.ShopCars
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -138,11 +124,6 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SellCar(ICarModel car, int count)
|
||||
{
|
||||
return _shopStorage.SellCar(car, count);
|
||||
}
|
||||
|
||||
public bool Update(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
@ -186,11 +167,6 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
throw new ArgumentNullException("Нет названия магазина!", nameof(model.Name));
|
||||
}
|
||||
|
||||
if (model.MaxCountCars < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Магазин с отрицательным количеством максимального количества авто!");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Shop. Name: {0}, Address: {1}, ID: {2}", model.Name, model.Address, model.Id);
|
||||
|
||||
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||
|
@ -18,6 +18,5 @@ namespace AutomobilePlantContracts.BindingModels
|
||||
public DateTime OpeningDate { get; set; }
|
||||
|
||||
public Dictionary<int, (ICarModel, int)> ShopCars { get; set; }
|
||||
public int MaxCountCars { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,5 @@ namespace AutomobilePlantContracts.BusinessLogicContracts
|
||||
bool Update(ShopBindingModel model);
|
||||
bool Delete(ShopBindingModel model);
|
||||
bool SupplyCars(ShopSearchModel model, ICarModel car, int count);
|
||||
bool SellCar(ICarModel document, int count);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.SearchModels;
|
||||
using AutomobilePlantContracts.ViewModels;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -18,6 +17,5 @@ namespace AutomobilePlantContracts.StorageContracts
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
bool SellCar(ICarModel model, int count);
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,5 @@ namespace AutomobilePlantContracts.ViewModels
|
||||
public DateTime OpeningDate { get; set; }
|
||||
|
||||
public Dictionary<int, (ICarModel, int)> ShopCars { get; set; } = new();
|
||||
|
||||
[DisplayName("Макс. автомобилей в магазине")]
|
||||
public int MaxCountCars { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,5 @@ namespace AutomobilePlantDataModels.Models
|
||||
string Address { get; }
|
||||
DateTime OpeningDate { get; }
|
||||
Dictionary<int, (ICarModel, int)> ShopCars { get; }
|
||||
int MaxCountCars { get; }
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutomobilePlantContracts\AutomobilePlantContracts.csproj" />
|
||||
<ProjectReference Include="..\AutomobilePlantDataModels\AutomobilePlantDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,61 +0,0 @@
|
||||
using AutomobilePlantFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutomobilePlantFileImplement
|
||||
{
|
||||
public class DataFileSingleton
|
||||
{
|
||||
private static DataFileSingleton? instance;
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string CarFileName = "Car.xml";
|
||||
private readonly string ShopFileName = "Shop.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Car> Cars { get; private set; }
|
||||
public List<Shop> Shops { get; private set; }
|
||||
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new DataFileSingleton();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||
public void SaveCars() => SaveData(Cars, CarFileName, "Cars", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Cars = LoadData(CarFileName, "Car", x => Car.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||
}
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
||||
}
|
||||
return new List<T>();
|
||||
}
|
||||
|
||||
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.SearchModels;
|
||||
using AutomobilePlantContracts.StorageContracts;
|
||||
using AutomobilePlantContracts.ViewModels;
|
||||
using AutomobilePlantFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutomobilePlantFileImplement.Implements
|
||||
{
|
||||
public class CarStorage : ICarStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public CarStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public CarViewModel? GetElement(CarSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.CarName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Cars
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.CarName) && x.CarName == model.CarName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<CarViewModel> GetFilteredList(CarSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.CarName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Cars
|
||||
.Where(x => x.CarName.Contains(model.CarName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<CarViewModel> GetFullList()
|
||||
{
|
||||
return source.Cars.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public CarViewModel? Insert(CarBindingModel model)
|
||||
{
|
||||
model.Id = source.Cars.Count > 0 ? source.Cars.Max(x => x.Id) + 1 : 1;
|
||||
var newCar = Car.Create(model);
|
||||
if (newCar == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Cars.Add(newCar);
|
||||
source.SaveCars();
|
||||
return newCar.GetViewModel;
|
||||
}
|
||||
|
||||
public CarViewModel? Update(CarBindingModel model)
|
||||
{
|
||||
var car = source.Cars.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (car == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
car.Update(model);
|
||||
source.SaveCars();
|
||||
return car.GetViewModel;
|
||||
}
|
||||
public CarViewModel? Delete(CarBindingModel model)
|
||||
{
|
||||
var car = source.Cars.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (car == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Cars.Remove(car);
|
||||
source.SaveCars();
|
||||
return car.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.SearchModels;
|
||||
using AutomobilePlantContracts.StorageContracts;
|
||||
using AutomobilePlantContracts.ViewModels;
|
||||
using AutomobilePlantFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantFileImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public ComponentStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Components
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Components
|
||||
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
return source.Components.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Components.Add(newComponent);
|
||||
source.SaveComponents();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
source.SaveComponents();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Components.Remove(component);
|
||||
source.SaveComponents();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.SearchModels;
|
||||
using AutomobilePlantContracts.StorageContracts;
|
||||
using AutomobilePlantContracts.ViewModels;
|
||||
using AutomobilePlantFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantFileImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public OrderStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return GetViewModel(source.Orders
|
||||
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)));
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Orders
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => GetViewModel(x))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders.Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Orders.Add(newOrder);
|
||||
source.SaveOrders();
|
||||
return GetViewModel(newOrder);
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
return GetViewModel(order);
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Orders.Remove(order);
|
||||
source.SaveOrders();
|
||||
return GetViewModel(order);
|
||||
}
|
||||
|
||||
private OrderViewModel GetViewModel(Order order)
|
||||
{
|
||||
var viewModel = order.GetViewModel;
|
||||
var car = source.Cars.FirstOrDefault(x => x.Id == order.CarId);
|
||||
if (car != null)
|
||||
{
|
||||
viewModel.CarName = car.CarName;
|
||||
}
|
||||
return viewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,155 +0,0 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.SearchModels;
|
||||
using AutomobilePlantContracts.StorageContracts;
|
||||
using AutomobilePlantContracts.ViewModels;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using AutomobilePlantFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantFileImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public ShopStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Shops
|
||||
.Select(x => x.GetViewModel)
|
||||
.Where(x => x.Name.Contains(model.Name ?? string.Empty))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
return source.Shops.Select(shop => shop.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
|
||||
var newShop = Shop.Create(model);
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Shops.Add(newShop);
|
||||
source.SaveShops();
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
shop.Update(model);
|
||||
source.SaveShops();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Shops.Remove(shop);
|
||||
source.SaveShops();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
|
||||
public bool SellCar(ICarModel model, int count)
|
||||
{
|
||||
// переделать под linq
|
||||
|
||||
var car = source.Cars.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
var countStore = count;
|
||||
|
||||
if (car == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var shop in source.Shops)
|
||||
{
|
||||
foreach (var c in shop.ShopCars)
|
||||
{
|
||||
if (c.Value.Item1.Id == car.Id)
|
||||
{
|
||||
count -= c.Value.Item2;
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
count = countStore;
|
||||
|
||||
for (int i = 0; i < source.Shops.Count; i++)
|
||||
{
|
||||
var shop = source.Shops[i];
|
||||
var cars = shop.ShopCars;
|
||||
|
||||
foreach (var c in cars.Where(x => x.Value.Item1.Id == car.Id))
|
||||
{
|
||||
var min = Math.Min(c.Value.Item2, count);
|
||||
cars[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min);
|
||||
count -= min;
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
shop.Update(new ShopBindingModel
|
||||
{
|
||||
Id = shop.Id,
|
||||
Name = shop.Name,
|
||||
Address = shop.Address,
|
||||
OpeningDate = shop.OpeningDate,
|
||||
MaxCountCars = shop.MaxCountCars,
|
||||
ShopCars = cars
|
||||
});
|
||||
source.SaveShops();
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.ViewModels;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutomobilePlantFileImplement.Models
|
||||
{
|
||||
public class Car : ICarModel
|
||||
{
|
||||
public string CarName { get; private set; } = string.Empty;
|
||||
|
||||
public double Price { get; private set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public Dictionary<int, int> Components { get; private set; } = new();
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _carComponents = null;
|
||||
public Dictionary<int, (IComponentModel, int)> CarComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_carComponents == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_carComponents = Components.ToDictionary(
|
||||
x => x.Key,
|
||||
y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)
|
||||
);
|
||||
}
|
||||
return _carComponents;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Car? Create(CarBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Car()
|
||||
{
|
||||
Id = model.Id,
|
||||
CarName = model.CarName,
|
||||
Price = model.Price,
|
||||
Components = model.CarComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
|
||||
public static Car? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Car()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
CarName = element.Element("CarName")!.Value,
|
||||
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||
Components = element.Element("CarComponents")!.Elements("CarComponent").ToDictionary(
|
||||
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value)
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(CarBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CarName = model.CarName;
|
||||
Price = model.Price;
|
||||
Components = model.CarComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_carComponents = null;
|
||||
}
|
||||
|
||||
public CarViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
CarName = CarName,
|
||||
Price = Price,
|
||||
CarComponents = CarComponents
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Car",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("CarName", CarName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
new XElement("CarComponents", Components.Select(x =>
|
||||
new XElement("CarComponent",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value)))
|
||||
.ToArray()));
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.ViewModels;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutomobilePlantFileImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public string ComponentName { get; private set; } = String.Empty;
|
||||
public double Cost { get; set; }
|
||||
public int Id { get; private set; }
|
||||
|
||||
public static Component? Create(ComponentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public static Component? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ComponentName = element.Element("ComponentName")!.Value,
|
||||
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ComponentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ComponentName = model.ComponentName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Component",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ComponentName", ComponentName),
|
||||
new XElement("Cost", Cost.ToString())
|
||||
);
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.ViewModels;
|
||||
using AutomobilePlantDataModels.Enums;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutomobilePlantFileImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int CarId { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order
|
||||
{
|
||||
CarId = model.CarId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
Id = model.Id,
|
||||
};
|
||||
}
|
||||
|
||||
public static Order? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
CarId = Convert.ToInt32(element.Element("CarId")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
CarId = CarId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
Id = Id,
|
||||
Status = Status,
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("CarId", CarId.ToString()),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", Status.ToString()),
|
||||
new XElement("DateCreate", DateCreate.ToString()),
|
||||
new XElement("DateImplement", DateImplement.ToString())
|
||||
);
|
||||
}
|
||||
}
|
@ -1,122 +0,0 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.ViewModels;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutomobilePlantFileImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
|
||||
public int MaxCountCars { get; private set; }
|
||||
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
|
||||
public Dictionary<int, int> Cars { get; private set; } = new();
|
||||
|
||||
private Dictionary<int, (ICarModel, int)>? _shopCars = null;
|
||||
|
||||
public Dictionary<int, (ICarModel, int)> ShopCars
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopCars == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_shopCars = Cars.ToDictionary(
|
||||
x => x.Key,
|
||||
y => ((source.Cars.FirstOrDefault(z => z.Id == y.Key) as ICarModel)!, y.Value)
|
||||
);
|
||||
}
|
||||
return _shopCars;
|
||||
}
|
||||
}
|
||||
|
||||
public static Shop? Create(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Address = model.Address,
|
||||
MaxCountCars = model.MaxCountCars,
|
||||
OpeningDate = model.OpeningDate,
|
||||
Cars = model.ShopCars.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
|
||||
public static Shop? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Shop()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
Name = element.Element("Name")!.Value,
|
||||
Address = element.Element("Address")!.Value,
|
||||
MaxCountCars = Convert.ToInt32(element.Element("MaxCountCars")!.Value),
|
||||
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
|
||||
Cars = element.Element("ShopCars")!.Elements("ShopCar").ToDictionary(
|
||||
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value)
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void Update(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
Address = model.Address;
|
||||
OpeningDate = model.OpeningDate;
|
||||
MaxCountCars = model.MaxCountCars;
|
||||
if (model.ShopCars.Count > 0)
|
||||
{
|
||||
Cars = model.ShopCars.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_shopCars = null;
|
||||
}
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Address = Address,
|
||||
OpeningDate = OpeningDate,
|
||||
ShopCars = ShopCars,
|
||||
MaxCountCars = MaxCountCars
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Shop",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("Name", Name),
|
||||
new XElement("Address", Address),
|
||||
new XElement("MaxCountCars", MaxCountCars),
|
||||
new XElement("OpeningDate", OpeningDate.ToString()),
|
||||
new XElement("ShopCars", Cars.Select(x =>
|
||||
new XElement("ShopCar",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value)))
|
||||
.ToArray()));
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ using AutomobilePlantContracts.SearchModels;
|
||||
using AutomobilePlantContracts.StorageContracts;
|
||||
using AutomobilePlantContracts.ViewModels;
|
||||
using AutomobilePlantListImplements.Models;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -123,10 +122,5 @@ namespace AutomobilePlantListImplements.Implements
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool SellCar(ICarModel model, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,6 @@ namespace AutomobilePlantListImplements.Models
|
||||
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
|
||||
public int MaxCountCars { get; private set; }
|
||||
|
||||
public Dictionary<int, (ICarModel, int)> ShopCars { get; private set; } = new();
|
||||
|
||||
public static Shop? Create(ShopBindingModel model)
|
||||
@ -36,7 +34,6 @@ namespace AutomobilePlantListImplements.Models
|
||||
Name = model.Name,
|
||||
Address = model.Address,
|
||||
OpeningDate = model.OpeningDate,
|
||||
MaxCountCars = model.MaxCountCars,
|
||||
ShopCars = new()
|
||||
};
|
||||
}
|
||||
@ -52,7 +49,6 @@ namespace AutomobilePlantListImplements.Models
|
||||
Address = model.Address;
|
||||
OpeningDate = model.OpeningDate;
|
||||
ShopCars = model.ShopCars;
|
||||
MaxCountCars= model.MaxCountCars;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
@ -61,8 +57,7 @@ namespace AutomobilePlantListImplements.Models
|
||||
Name = Name,
|
||||
Address = Address,
|
||||
OpeningDate = OpeningDate,
|
||||
ShopCars = ShopCars,
|
||||
MaxCountCars = MaxCountCars
|
||||
ShopCars = ShopCars
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user