From 3923eacebdcd121a8d0683fee27f5507be7bf46c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Mon, 1 May 2023 14:18:15 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=B0=D1=8F=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8=D1=89=D0=B0=20=D0=BC=D0=B0=D0=B3?= =?UTF-8?q?=D0=B0=D0=B7=D0=B8=D0=BD=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/CarShopBindingModel.cs | 1 + .../StoragesContracts/ICarShopStorage.cs | 3 + .../ViewModel/CarShopViewModel.cs | 2 + .../AbstractAutoDataModels/Models/ICarShop.cs | 1 + .../Implements/CarShopStorege.cs | 11 ++ .../Models/CarShop.cs | 1 + .../AutomobilePlant/FormShopCar.Designer.cs | 80 +++++++----- .../AutomobilePlant/FormShopCar.cs | 1 + AutomobilePlant/AutomobilePlant/Program.cs | 2 +- .../DataFileSingleton.cs | 5 + .../Implements/CarShopStorage.cs | 96 +++++++++++++++ .../Models/CarShop.cs | 116 ++++++++++++++++++ 12 files changed, 290 insertions(+), 29 deletions(-) create mode 100644 AutomobilePlant/AutomomilePlantFileImplement/Implements/CarShopStorage.cs create mode 100644 AutomobilePlant/AutomomilePlantFileImplement/Models/CarShop.cs diff --git a/AutomobilePlant/AbstractAutoContracts/BindingModels/CarShopBindingModel.cs b/AutomobilePlant/AbstractAutoContracts/BindingModels/CarShopBindingModel.cs index 1e0026b..f803cb3 100644 --- a/AutomobilePlant/AbstractAutoContracts/BindingModels/CarShopBindingModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/BindingModels/CarShopBindingModel.cs @@ -14,6 +14,7 @@ namespace AutomobilePlantContracts.BindingModels public string Adress { get; set; } = String.Empty ; public DateTime DateOpen { get; set; } = new(); + public int Fullness { get; set; } public Dictionary Cars { get; set; } = new(); diff --git a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/ICarShopStorage.cs b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/ICarShopStorage.cs index 51504b2..1cc791c 100644 --- a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/ICarShopStorage.cs +++ b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/ICarShopStorage.cs @@ -1,6 +1,7 @@ using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.SearchModel; using AutomobilePlantContracts.ViewModel; +using AutomobilePlantDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -13,6 +14,8 @@ namespace AutomobilePlantContracts.StoragesContracts { List GetFullList(); List GetFilteredList(CarShopSearchModel model); + bool CheckShop (CarShopSearchModel model); + bool TrySell (CarShopSearchModel model, ICarModel car); CarShopViewModel? GetElement(CarShopSearchModel model); CarShopViewModel? Insert(CarShopBindingModel model); CarShopViewModel? Update(CarShopBindingModel model); diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/CarShopViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/CarShopViewModel.cs index fc409af..d0dba5f 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/CarShopViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/CarShopViewModel.cs @@ -16,6 +16,8 @@ namespace AutomobilePlantContracts.ViewModel public string Adress { get; set; } = String.Empty; [DisplayName("Дата открытия")] public DateTime DateOpen { get; set; } = new(); + [DisplayName("Наполненность")] + public int Fullness { get; set; } public Dictionary Cars { get; set; } = new(); diff --git a/AutomobilePlant/AbstractAutoDataModels/Models/ICarShop.cs b/AutomobilePlant/AbstractAutoDataModels/Models/ICarShop.cs index 38d80ea..f75a89f 100644 --- a/AutomobilePlant/AbstractAutoDataModels/Models/ICarShop.cs +++ b/AutomobilePlant/AbstractAutoDataModels/Models/ICarShop.cs @@ -11,6 +11,7 @@ namespace AutomobilePlantDataModels.Models string ShopName { get; } string Adress { get; } DateTime DateOpen { get; } + int Fullness { get; } Dictionary Cars { get; } } } diff --git a/AutomobilePlant/AbstractAutoListImplement/Implements/CarShopStorege.cs b/AutomobilePlant/AbstractAutoListImplement/Implements/CarShopStorege.cs index 7f54820..8077855 100644 --- a/AutomobilePlant/AbstractAutoListImplement/Implements/CarShopStorege.cs +++ b/AutomobilePlant/AbstractAutoListImplement/Implements/CarShopStorege.cs @@ -2,6 +2,7 @@ using AutomobilePlantContracts.SearchModel; using AutomobilePlantContracts.StoragesContracts; using AutomobilePlantContracts.ViewModel; +using AutomobilePlantDataModels.Models; using AutomobilePlantListImplement.Models; using System; using System.Collections.Generic; @@ -117,5 +118,15 @@ namespace AutomobilePlantListImplement.Implements return null; } + + public bool CheckShop(CarShopSearchModel model) + { + throw new NotImplementedException(); + } + + public bool TrySell(CarShopSearchModel model, ICarModel car) + { + throw new NotImplementedException(); + } } } diff --git a/AutomobilePlant/AbstractAutoListImplement/Models/CarShop.cs b/AutomobilePlant/AbstractAutoListImplement/Models/CarShop.cs index 31cf0cc..005394b 100644 --- a/AutomobilePlant/AbstractAutoListImplement/Models/CarShop.cs +++ b/AutomobilePlant/AbstractAutoListImplement/Models/CarShop.cs @@ -18,6 +18,7 @@ namespace AutomobilePlantListImplement.Models public string Adress { get; private set; } = String.Empty; public DateTime DateOpen { get; private set; } + public int Fullness { get; set; } public Dictionary Cars { get; private set; } = new (); diff --git a/AutomobilePlant/AutomobilePlant/FormShopCar.Designer.cs b/AutomobilePlant/AutomobilePlant/FormShopCar.Designer.cs index 38ae461..ae029dc 100644 --- a/AutomobilePlant/AutomobilePlant/FormShopCar.Designer.cs +++ b/AutomobilePlant/AutomobilePlant/FormShopCar.Designer.cs @@ -28,9 +28,9 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle(); this.ShopNameLabel = new System.Windows.Forms.Label(); this.AdressLabel = new System.Windows.Forms.Label(); this.ShopNameTextBox = new System.Windows.Forms.TextBox(); @@ -44,8 +44,11 @@ this.ComponentNameField = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.CountField = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.DateOpenPicker = new System.Windows.Forms.DateTimePicker(); + this.FullnessnumericUpDown = new System.Windows.Forms.NumericUpDown(); + this.Fullness = new System.Windows.Forms.Label(); this.ComponentsGroupBox.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.FullnessnumericUpDown)).BeginInit(); this.SuspendLayout(); // // ShopNameLabel @@ -132,38 +135,38 @@ // // DataGridView // - dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; - dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.DataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; + dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle4.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.DataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle4; this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.ID, this.ComponentNameField, this.CountField}); - dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText; - dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this.DataGridView.DefaultCellStyle = dataGridViewCellStyle2; + dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle5.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle5.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + dataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle5.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle5.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.DataGridView.DefaultCellStyle = dataGridViewCellStyle5; this.DataGridView.Location = new System.Drawing.Point(7, 29); this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.DataGridView.Name = "DataGridView"; - dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control; - dataGridViewCellStyle3.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.DataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle3; + dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle6.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + dataGridViewCellStyle6.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle6.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle6.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle6.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.DataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle6; this.DataGridView.RowHeadersWidth = 51; this.DataGridView.RowTemplate.Height = 25; this.DataGridView.Size = new System.Drawing.Size(641, 429); @@ -193,16 +196,34 @@ // // 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.Size = new System.Drawing.Size(250, 27); 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 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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.ComponentsGroupBox); this.Controls.Add(this.AdressTextBox); @@ -215,6 +236,7 @@ this.Load += new System.EventHandler(this.FormCar_Load); this.ComponentsGroupBox.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.FullnessnumericUpDown)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -235,5 +257,7 @@ private DataGridViewTextBoxColumn ComponentNameField; private DataGridViewTextBoxColumn CountField; private DateTimePicker DateOpenPicker; + private NumericUpDown FullnessnumericUpDown; + private Label Fullness; } } \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormShopCar.cs b/AutomobilePlant/AutomobilePlant/FormShopCar.cs index ba18cef..1b24873 100644 --- a/AutomobilePlant/AutomobilePlant/FormShopCar.cs +++ b/AutomobilePlant/AutomobilePlant/FormShopCar.cs @@ -110,6 +110,7 @@ namespace AutomobilePlant ShopName = ShopNameTextBox.Text, DateOpen = DateOpenPicker.Value, Adress = AdressTextBox.Text, + Fullness = (int)FullnessnumericUpDown.Value, Cars = _cars }; var operationResult = _id.HasValue ? _logic.Update(model) : diff --git a/AutomobilePlant/AutomobilePlant/Program.cs b/AutomobilePlant/AutomobilePlant/Program.cs index 187e842..20f4ab1 100644 --- a/AutomobilePlant/AutomobilePlant/Program.cs +++ b/AutomobilePlant/AutomobilePlant/Program.cs @@ -37,7 +37,7 @@ namespace AutomobilePlant services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/AutomobilePlant/AutomomilePlantFileImplement/DataFileSingleton.cs b/AutomobilePlant/AutomomilePlantFileImplement/DataFileSingleton.cs index 65f994f..217b935 100644 --- a/AutomobilePlant/AutomomilePlantFileImplement/DataFileSingleton.cs +++ b/AutomobilePlant/AutomomilePlantFileImplement/DataFileSingleton.cs @@ -14,9 +14,11 @@ namespace AutomomilePlantFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string CarFileName = "Car.xml"; + private readonly string CarShopFileName = "CarShop.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Cars { get; private set; } + public List CarShops { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -29,6 +31,8 @@ namespace AutomomilePlantFileImplement "Components", x => x.GetXElement); public void SaveCars() => SaveData(Cars, CarFileName, "Cars", x => x.GetXElement); + public void SaveCarShops() => SaveData(CarShops, CarShopFileName, + "CarShops", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); private DataFileSingleton() @@ -38,6 +42,7 @@ namespace AutomomilePlantFileImplement Cars = LoadData(CarFileName, "Car", x => Car.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + CarShops = LoadData(CarShopFileName, "CarShop", x => CarShop.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/AutomobilePlant/AutomomilePlantFileImplement/Implements/CarShopStorage.cs b/AutomobilePlant/AutomomilePlantFileImplement/Implements/CarShopStorage.cs new file mode 100644 index 0000000..d86068b --- /dev/null +++ b/AutomobilePlant/AutomomilePlantFileImplement/Implements/CarShopStorage.cs @@ -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 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 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; + } + } +} diff --git a/AutomobilePlant/AutomomilePlantFileImplement/Models/CarShop.cs b/AutomobilePlant/AutomomilePlantFileImplement/Models/CarShop.cs new file mode 100644 index 0000000..437e5b9 --- /dev/null +++ b/AutomobilePlant/AutomomilePlantFileImplement/Models/CarShop.cs @@ -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 ShopCars { get; set; } = new(); + private Dictionary _cars = null; + + public int Id { get; set; } + public Dictionary 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())); + } +}