Revert "немного"

This reverts commit 5a9a99b1b6.
This commit is contained in:
dex_moth 2024-03-02 09:14:37 +04:00
parent 68b38e4fd3
commit 08a8c499b1
3 changed files with 6 additions and 76 deletions

View File

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FishFactoryListImplement
{
internal class DataFileSingleton1
{
}
}

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace FishFactoryListImplement.Models
{
@ -15,21 +14,11 @@ namespace FishFactoryListImplement.Models
public int Id { get; private set; }
public string CannedName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _cannedComponents = null;
public Dictionary<int, (IComponentModel, int)> CannedComponents
{
get
{
if (_cannedComponents == null)
{
var source = DataFileSingleton.GetInstance();
_cannedComponents = Components.ToDictionary(x => x.Key, y =>
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
}
return _cannedComponents;
}
}
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
public static Canned? Create(CannedBindingModel? model)
{
if (model == null)
@ -41,26 +30,9 @@ namespace FishFactoryListImplement.Models
Id = model.Id,
CannedName = model.CannedName,
Price = model.Price,
Components = model.CannedComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
CannedComponents = model.CannedComponents
};
}
public static Canned? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Canned()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
CannedName = element.Element("CannedName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
Components = element.Element("CannedComponents")!.Elements("CannedComponent").ToDictionary
(x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value))};
}
public void Update(CannedBindingModel? model)
{
if (model == null)
@ -69,9 +41,7 @@ namespace FishFactoryListImplement.Models
}
CannedName = model.CannedName;
Price = model.Price;
Components = model.CannedComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
_cannedComponents = null;
CannedComponents = model.CannedComponents;
}
public CannedViewModel GetViewModel => new()
{
@ -80,13 +50,6 @@ namespace FishFactoryListImplement.Models
Price = Price,
CannedComponents = CannedComponents
};
public XElement GetXElement => new("Canned",
new XAttribute("Id", Id),
new XElement("CannedName", CannedName),
new XElement("Price", Price.ToString()),
new XElement("CannedComponents", Components.Select(x =>
new XElement("CannedComponent",
new XElement("Key", x.Key),
new XElement("Value", x.Value))).ToArray()));
}
}

View File

@ -1,7 +1,6 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModel.Models;
using System.Xml.Linq;
namespace FishFactoryListImplement.Models
{
@ -23,21 +22,6 @@ namespace FishFactoryListImplement.Models
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)
@ -53,10 +37,5 @@ namespace FishFactoryListImplement.Models
ComponentName = ComponentName,
Cost = Cost
};
public XElement GetXElement => new("Component",
new XAttribute("Id", Id),
new XElement("ComponentName", ComponentName),
new XElement("Cost", Cost.ToString()));
}
}