Новая реализация хранилища магазинов
This commit is contained in:
parent
1a02b213fd
commit
3923eacebd
@ -14,6 +14,7 @@ namespace AutomobilePlantContracts.BindingModels
|
|||||||
public string Adress { get; set; } = String.Empty ;
|
public string Adress { get; set; } = String.Empty ;
|
||||||
|
|
||||||
public DateTime DateOpen { get; set; } = new();
|
public DateTime DateOpen { get; set; } = new();
|
||||||
|
public int Fullness { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, (ICarModel, int)> Cars { get; set; } = new();
|
public Dictionary<int, (ICarModel, int)> Cars { get; set; } = new();
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using AutomobilePlantContracts.BindingModels;
|
using AutomobilePlantContracts.BindingModels;
|
||||||
using AutomobilePlantContracts.SearchModel;
|
using AutomobilePlantContracts.SearchModel;
|
||||||
using AutomobilePlantContracts.ViewModel;
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -13,6 +14,8 @@ namespace AutomobilePlantContracts.StoragesContracts
|
|||||||
{
|
{
|
||||||
List<CarShopViewModel> GetFullList();
|
List<CarShopViewModel> GetFullList();
|
||||||
List<CarShopViewModel> GetFilteredList(CarShopSearchModel model);
|
List<CarShopViewModel> GetFilteredList(CarShopSearchModel model);
|
||||||
|
bool CheckShop (CarShopSearchModel model);
|
||||||
|
bool TrySell (CarShopSearchModel model, ICarModel car);
|
||||||
CarShopViewModel? GetElement(CarShopSearchModel model);
|
CarShopViewModel? GetElement(CarShopSearchModel model);
|
||||||
CarShopViewModel? Insert(CarShopBindingModel model);
|
CarShopViewModel? Insert(CarShopBindingModel model);
|
||||||
CarShopViewModel? Update(CarShopBindingModel model);
|
CarShopViewModel? Update(CarShopBindingModel model);
|
||||||
|
@ -16,6 +16,8 @@ namespace AutomobilePlantContracts.ViewModel
|
|||||||
public string Adress { get; set; } = String.Empty;
|
public string Adress { get; set; } = String.Empty;
|
||||||
[DisplayName("Дата открытия")]
|
[DisplayName("Дата открытия")]
|
||||||
public DateTime DateOpen { get; set; } = new();
|
public DateTime DateOpen { get; set; } = new();
|
||||||
|
[DisplayName("Наполненность")]
|
||||||
|
public int Fullness { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, (ICarModel, int)> Cars { get; set; } = new();
|
public Dictionary<int, (ICarModel, int)> Cars { get; set; } = new();
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ namespace AutomobilePlantDataModels.Models
|
|||||||
string ShopName { get; }
|
string ShopName { get; }
|
||||||
string Adress { get; }
|
string Adress { get; }
|
||||||
DateTime DateOpen { get; }
|
DateTime DateOpen { get; }
|
||||||
|
int Fullness { get; }
|
||||||
Dictionary<int, (ICarModel, int)> Cars { get; }
|
Dictionary<int, (ICarModel, int)> Cars { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using AutomobilePlantContracts.SearchModel;
|
using AutomobilePlantContracts.SearchModel;
|
||||||
using AutomobilePlantContracts.StoragesContracts;
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
using AutomobilePlantContracts.ViewModel;
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
using AutomobilePlantListImplement.Models;
|
using AutomobilePlantListImplement.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -117,5 +118,15 @@ namespace AutomobilePlantListImplement.Implements
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool CheckShop(CarShopSearchModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TrySell(CarShopSearchModel model, ICarModel car)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ namespace AutomobilePlantListImplement.Models
|
|||||||
public string Adress { get; private set; } = String.Empty;
|
public string Adress { get; private set; } = String.Empty;
|
||||||
|
|
||||||
public DateTime DateOpen { get; private set; }
|
public DateTime DateOpen { get; private set; }
|
||||||
|
public int Fullness { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, (ICarModel, int)> Cars { get; private set; } = new ();
|
public Dictionary<int, (ICarModel, int)> Cars { get; private set; } = new ();
|
||||||
|
|
||||||
|
@ -28,9 +28,9 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||||
this.ShopNameLabel = new System.Windows.Forms.Label();
|
this.ShopNameLabel = new System.Windows.Forms.Label();
|
||||||
this.AdressLabel = new System.Windows.Forms.Label();
|
this.AdressLabel = new System.Windows.Forms.Label();
|
||||||
this.ShopNameTextBox = new System.Windows.Forms.TextBox();
|
this.ShopNameTextBox = new System.Windows.Forms.TextBox();
|
||||||
@ -44,8 +44,11 @@
|
|||||||
this.ComponentNameField = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
this.ComponentNameField = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
this.CountField = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
this.CountField = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
this.DateOpenPicker = new System.Windows.Forms.DateTimePicker();
|
this.DateOpenPicker = new System.Windows.Forms.DateTimePicker();
|
||||||
|
this.FullnessnumericUpDown = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.Fullness = new System.Windows.Forms.Label();
|
||||||
this.ComponentsGroupBox.SuspendLayout();
|
this.ComponentsGroupBox.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.FullnessnumericUpDown)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// ShopNameLabel
|
// ShopNameLabel
|
||||||
@ -132,38 +135,38 @@
|
|||||||
//
|
//
|
||||||
// DataGridView
|
// DataGridView
|
||||||
//
|
//
|
||||||
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
||||||
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
|
dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control;
|
||||||
dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
dataGridViewCellStyle4.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
|
dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText;
|
||||||
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
||||||
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||||
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
|
dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
|
||||||
this.DataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
|
this.DataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle4;
|
||||||
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||||
this.ID,
|
this.ID,
|
||||||
this.ComponentNameField,
|
this.ComponentNameField,
|
||||||
this.CountField});
|
this.CountField});
|
||||||
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
||||||
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
|
dataGridViewCellStyle5.BackColor = System.Drawing.SystemColors.Window;
|
||||||
dataGridViewCellStyle2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
dataGridViewCellStyle5.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
|
dataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.ControlText;
|
||||||
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
dataGridViewCellStyle5.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
||||||
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
dataGridViewCellStyle5.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||||
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
|
dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
|
||||||
this.DataGridView.DefaultCellStyle = dataGridViewCellStyle2;
|
this.DataGridView.DefaultCellStyle = dataGridViewCellStyle5;
|
||||||
this.DataGridView.Location = new System.Drawing.Point(7, 29);
|
this.DataGridView.Location = new System.Drawing.Point(7, 29);
|
||||||
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
this.DataGridView.Name = "DataGridView";
|
this.DataGridView.Name = "DataGridView";
|
||||||
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
||||||
dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control;
|
dataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Control;
|
||||||
dataGridViewCellStyle3.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
dataGridViewCellStyle6.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||||
dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
|
dataGridViewCellStyle6.ForeColor = System.Drawing.SystemColors.WindowText;
|
||||||
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
dataGridViewCellStyle6.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
||||||
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
dataGridViewCellStyle6.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||||
dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
|
dataGridViewCellStyle6.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
|
||||||
this.DataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
|
this.DataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle6;
|
||||||
this.DataGridView.RowHeadersWidth = 51;
|
this.DataGridView.RowHeadersWidth = 51;
|
||||||
this.DataGridView.RowTemplate.Height = 25;
|
this.DataGridView.RowTemplate.Height = 25;
|
||||||
this.DataGridView.Size = new System.Drawing.Size(641, 429);
|
this.DataGridView.Size = new System.Drawing.Size(641, 429);
|
||||||
@ -193,16 +196,34 @@
|
|||||||
//
|
//
|
||||||
// DateOpenPicker
|
// DateOpenPicker
|
||||||
//
|
//
|
||||||
this.DateOpenPicker.Location = new System.Drawing.Point(471, 8);
|
this.DateOpenPicker.Location = new System.Drawing.Point(495, 12);
|
||||||
this.DateOpenPicker.Name = "DateOpenPicker";
|
this.DateOpenPicker.Name = "DateOpenPicker";
|
||||||
this.DateOpenPicker.Size = new System.Drawing.Size(250, 27);
|
this.DateOpenPicker.Size = new System.Drawing.Size(250, 27);
|
||||||
this.DateOpenPicker.TabIndex = 6;
|
this.DateOpenPicker.TabIndex = 6;
|
||||||
//
|
//
|
||||||
|
// FullnessnumericUpDown
|
||||||
|
//
|
||||||
|
this.FullnessnumericUpDown.Location = new System.Drawing.Point(595, 57);
|
||||||
|
this.FullnessnumericUpDown.Name = "FullnessnumericUpDown";
|
||||||
|
this.FullnessnumericUpDown.Size = new System.Drawing.Size(150, 27);
|
||||||
|
this.FullnessnumericUpDown.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// Fullness
|
||||||
|
//
|
||||||
|
this.Fullness.AutoSize = true;
|
||||||
|
this.Fullness.Location = new System.Drawing.Point(469, 64);
|
||||||
|
this.Fullness.Name = "Fullness";
|
||||||
|
this.Fullness.Size = new System.Drawing.Size(103, 20);
|
||||||
|
this.Fullness.TabIndex = 8;
|
||||||
|
this.Fullness.Text = "Ограничение";
|
||||||
|
//
|
||||||
// FormShopCar
|
// FormShopCar
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(853, 664);
|
this.ClientSize = new System.Drawing.Size(853, 664);
|
||||||
|
this.Controls.Add(this.Fullness);
|
||||||
|
this.Controls.Add(this.FullnessnumericUpDown);
|
||||||
this.Controls.Add(this.DateOpenPicker);
|
this.Controls.Add(this.DateOpenPicker);
|
||||||
this.Controls.Add(this.ComponentsGroupBox);
|
this.Controls.Add(this.ComponentsGroupBox);
|
||||||
this.Controls.Add(this.AdressTextBox);
|
this.Controls.Add(this.AdressTextBox);
|
||||||
@ -215,6 +236,7 @@
|
|||||||
this.Load += new System.EventHandler(this.FormCar_Load);
|
this.Load += new System.EventHandler(this.FormCar_Load);
|
||||||
this.ComponentsGroupBox.ResumeLayout(false);
|
this.ComponentsGroupBox.ResumeLayout(false);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.FullnessnumericUpDown)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
@ -235,5 +257,7 @@
|
|||||||
private DataGridViewTextBoxColumn ComponentNameField;
|
private DataGridViewTextBoxColumn ComponentNameField;
|
||||||
private DataGridViewTextBoxColumn CountField;
|
private DataGridViewTextBoxColumn CountField;
|
||||||
private DateTimePicker DateOpenPicker;
|
private DateTimePicker DateOpenPicker;
|
||||||
|
private NumericUpDown FullnessnumericUpDown;
|
||||||
|
private Label Fullness;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -110,6 +110,7 @@ namespace AutomobilePlant
|
|||||||
ShopName = ShopNameTextBox.Text,
|
ShopName = ShopNameTextBox.Text,
|
||||||
DateOpen = DateOpenPicker.Value,
|
DateOpen = DateOpenPicker.Value,
|
||||||
Adress = AdressTextBox.Text,
|
Adress = AdressTextBox.Text,
|
||||||
|
Fullness = (int)FullnessnumericUpDown.Value,
|
||||||
Cars = _cars
|
Cars = _cars
|
||||||
};
|
};
|
||||||
var operationResult = _id.HasValue ? _logic.Update(model) :
|
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||||
|
@ -37,7 +37,7 @@ namespace AutomobilePlant
|
|||||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
services.AddTransient<ICarStorage, CarStorage>();
|
services.AddTransient<ICarStorage, CarStorage>();
|
||||||
services.AddTransient<ICarShopStorage, CarShopStorege>();
|
services.AddTransient<ICarShopStorage, CarShopStorage>();
|
||||||
|
|
||||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
|
@ -14,9 +14,11 @@ namespace AutomomilePlantFileImplement
|
|||||||
private readonly string ComponentFileName = "Component.xml";
|
private readonly string ComponentFileName = "Component.xml";
|
||||||
private readonly string OrderFileName = "Order.xml";
|
private readonly string OrderFileName = "Order.xml";
|
||||||
private readonly string CarFileName = "Car.xml";
|
private readonly string CarFileName = "Car.xml";
|
||||||
|
private readonly string CarShopFileName = "CarShop.xml";
|
||||||
public List<Component> Components { get; private set; }
|
public List<Component> Components { get; private set; }
|
||||||
public List<Order> Orders { get; private set; }
|
public List<Order> Orders { get; private set; }
|
||||||
public List<Car> Cars { get; private set; }
|
public List<Car> Cars { get; private set; }
|
||||||
|
public List<CarShop> CarShops { get; private set; }
|
||||||
public static DataFileSingleton GetInstance()
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
@ -29,6 +31,8 @@ namespace AutomomilePlantFileImplement
|
|||||||
"Components", x => x.GetXElement);
|
"Components", x => x.GetXElement);
|
||||||
public void SaveCars() => SaveData(Cars, CarFileName,
|
public void SaveCars() => SaveData(Cars, CarFileName,
|
||||||
"Cars", x => x.GetXElement);
|
"Cars", x => x.GetXElement);
|
||||||
|
public void SaveCarShops() => SaveData(CarShops, CarShopFileName,
|
||||||
|
"CarShops", x => x.GetXElement);
|
||||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x
|
||||||
=> x.GetXElement);
|
=> x.GetXElement);
|
||||||
private DataFileSingleton()
|
private DataFileSingleton()
|
||||||
@ -38,6 +42,7 @@ namespace AutomomilePlantFileImplement
|
|||||||
Cars = LoadData(CarFileName, "Car", x =>
|
Cars = LoadData(CarFileName, "Car", x =>
|
||||||
Car.Create(x)!)!;
|
Car.Create(x)!)!;
|
||||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
|
CarShops = LoadData(CarShopFileName, "CarShop", x => CarShop.Create(x)!)!;
|
||||||
}
|
}
|
||||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
|
||||||
Func<XElement, T> selectFunction)
|
Func<XElement, T> selectFunction)
|
||||||
|
@ -0,0 +1,96 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.SearchModel;
|
||||||
|
using AutomobilePlantContracts.StoragesContracts;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomomilePlantFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AutomomilePlantFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class CarShopStorage : ICarShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public CarShopStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public CarShopViewModel? Delete(CarShopBindingModel model)
|
||||||
|
{
|
||||||
|
var element = source.CarShops.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.CarShops.Remove(element);
|
||||||
|
source.SaveCarShops();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarShopViewModel? GetElement(CarShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.CarShops
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName ==
|
||||||
|
model.ShopName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CarShopViewModel> GetFilteredList(CarShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.CarShops
|
||||||
|
.Where(x => x.ShopName.Contains(model.ShopName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CarShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.CarShops
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarShopViewModel? Insert(CarShopBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.CarShops.Count > 0 ? source.CarShops.Max(x =>
|
||||||
|
x.Id) + 1 : 1;
|
||||||
|
var newCarShop = CarShop.Create(model);
|
||||||
|
if (newCarShop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.CarShops.Add(newCarShop);
|
||||||
|
source.SaveCarShops();
|
||||||
|
return newCarShop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarShopViewModel? Update(CarShopBindingModel model)
|
||||||
|
{
|
||||||
|
var shop = source.CarShops.FirstOrDefault(x => x.Id ==
|
||||||
|
model.Id);
|
||||||
|
if (shop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
shop.Update(model);
|
||||||
|
source.SaveCarShops();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
116
AutomobilePlant/AutomomilePlantFileImplement/Models/CarShop.cs
Normal file
116
AutomobilePlant/AutomomilePlantFileImplement/Models/CarShop.cs
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
using AutomobilePlantContracts.BindingModels;
|
||||||
|
using AutomobilePlantContracts.ViewModel;
|
||||||
|
using AutomobilePlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace AutomomilePlantFileImplement.Models
|
||||||
|
{
|
||||||
|
public class CarShop : ICarShop
|
||||||
|
|
||||||
|
{
|
||||||
|
public string ShopName {get; set;} = String.Empty;
|
||||||
|
|
||||||
|
public string Adress { get; set; } = String.Empty;
|
||||||
|
|
||||||
|
public DateTime DateOpen { get; set; }
|
||||||
|
|
||||||
|
public int Fullness { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<int, int> ShopCars { get; set; } = new();
|
||||||
|
private Dictionary<int, (ICarModel, int)> _cars = null;
|
||||||
|
|
||||||
|
public int Id { get; set; }
|
||||||
|
public Dictionary<int, (ICarModel, int)> Cars
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_cars == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_cars = ShopCars.ToDictionary(x => x.Key, y =>
|
||||||
|
((source.Cars.FirstOrDefault(z => z.Id == y.Key) as ICarModel)!,
|
||||||
|
y.Value));
|
||||||
|
}
|
||||||
|
return _cars;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static CarShop? Create(CarShopBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new CarShop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
Fullness = model.Fullness,
|
||||||
|
Adress = model.Adress,
|
||||||
|
DateOpen = model.DateOpen,
|
||||||
|
ShopCars = model.Cars.ToDictionary(x => x.Key, x
|
||||||
|
=> x.Value.Item2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static CarShop? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new CarShop()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ShopName = element.Element("ShopName")!.Value,
|
||||||
|
Adress = element.Element("Adress")!.Value,
|
||||||
|
DateOpen = DateTime.Parse(element.Element("DateOpen")!.Value),
|
||||||
|
Fullness = Convert.ToInt32(element.Element("Fullness")!.Value),
|
||||||
|
ShopCars =
|
||||||
|
element.Element("Cars")!.Elements("ShopCar")
|
||||||
|
.ToDictionary(x =>
|
||||||
|
Convert.ToInt32(x.Element("Key")?.Value), x =>
|
||||||
|
Convert.ToInt32(x.Element("Value")?.Value))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(CarShopBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
Adress = model.Adress;
|
||||||
|
ShopCars = model.Cars.ToDictionary(x => x.Key, x =>
|
||||||
|
x.Value.Item2);
|
||||||
|
_cars = null;
|
||||||
|
}
|
||||||
|
public CarShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
Adress = Adress,
|
||||||
|
DateOpen = DateOpen,
|
||||||
|
Fullness = Fullness,
|
||||||
|
Cars = Cars
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new("CarShop",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ShopName", ShopName),
|
||||||
|
new XElement("Adress", Adress),
|
||||||
|
new XElement("DateOpen", DateOpen.ToString()),
|
||||||
|
new XElement("Fullness", Fullness.ToString()),
|
||||||
|
new XElement("Cars", ShopCars.Select(x =>
|
||||||
|
new XElement("ShopCar",
|
||||||
|
|
||||||
|
new XElement("Key", x.Key),
|
||||||
|
|
||||||
|
new XElement("Value", x.Value)))
|
||||||
|
|
||||||
|
.ToArray()));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user