2024-03-23 12:04:42 +04:00
|
|
|
|
using PrecastConcretePlantContracts.BindingModels;
|
|
|
|
|
using PrecastConcretePlantContracts.ViewModels;
|
|
|
|
|
using PrecastConcretePlantDataModels.Models;
|
2024-05-16 20:23:36 +04:00
|
|
|
|
using System.Runtime.Serialization;
|
2024-03-23 12:04:42 +04:00
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
namespace PrecastConcretePlantFileImplement.Models
|
|
|
|
|
{
|
2024-05-16 20:23:36 +04:00
|
|
|
|
[DataContract]
|
2024-03-23 12:04:42 +04:00
|
|
|
|
public class Reinforced : IReinforcedModel
|
|
|
|
|
{
|
2024-05-16 20:23:36 +04:00
|
|
|
|
[DataMember]
|
2024-03-23 12:04:42 +04:00
|
|
|
|
public int Id { get; private set; }
|
2024-05-16 20:23:36 +04:00
|
|
|
|
|
|
|
|
|
[DataMember]
|
2024-03-23 12:04:42 +04:00
|
|
|
|
public string ReinforcedName { get; private set; } = string.Empty;
|
2024-05-16 20:23:36 +04:00
|
|
|
|
|
|
|
|
|
[DataMember]
|
2024-03-23 12:04:42 +04:00
|
|
|
|
public double Price { get; private set; }
|
2024-05-16 20:23:36 +04:00
|
|
|
|
|
2024-03-23 12:04:42 +04:00
|
|
|
|
public Dictionary<int, int> Components { get; private set; } = new();
|
|
|
|
|
|
|
|
|
|
private Dictionary<int, (IComponentModel, int)>? _reinforcedComponents = null;
|
2024-05-16 20:23:36 +04:00
|
|
|
|
|
|
|
|
|
[DataMember]
|
2024-03-23 12:04:42 +04:00
|
|
|
|
public Dictionary<int, (IComponentModel, int)> ReinforcedComponents
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_reinforcedComponents == null)
|
|
|
|
|
{
|
|
|
|
|
var source = DataFileSingleton.GetInstance();
|
|
|
|
|
_reinforcedComponents = Components.ToDictionary(x => x.Key, y =>
|
|
|
|
|
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
|
|
|
|
|
y.Value));
|
|
|
|
|
}
|
|
|
|
|
return _reinforcedComponents;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static Reinforced? Create(ReinforcedBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Reinforced()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
ReinforcedName = model.ReinforcedName,
|
|
|
|
|
Price = model.Price,
|
|
|
|
|
Components = model.ReinforcedComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public static Reinforced? Create(XElement element)
|
|
|
|
|
{
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Reinforced()
|
|
|
|
|
{
|
|
|
|
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
|
|
|
|
ReinforcedName = element.Element("ReinforcedName")!.Value,
|
|
|
|
|
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
|
|
|
|
Components =
|
|
|
|
|
element.Element("ReinforcedComponents")!.Elements("ReinforcedComponent")
|
|
|
|
|
.ToDictionary(x =>
|
|
|
|
|
Convert.ToInt32(x.Element("Key")?.Value), x =>
|
|
|
|
|
Convert.ToInt32(x.Element("Value")?.Value))
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(ReinforcedBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ReinforcedName = model.ReinforcedName;
|
|
|
|
|
Price = model.Price;
|
|
|
|
|
Components = model.ReinforcedComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
|
|
|
|
|
_reinforcedComponents = null;
|
|
|
|
|
}
|
|
|
|
|
public ReinforcedViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
ReinforcedName = ReinforcedName,
|
|
|
|
|
Price = Price,
|
|
|
|
|
ReinforcedComponents = ReinforcedComponents
|
|
|
|
|
};
|
|
|
|
|
public XElement GetXElement => new("Reinforced",
|
|
|
|
|
new XAttribute("Id", Id),
|
|
|
|
|
new XElement("ReinforcedName", ReinforcedName),
|
|
|
|
|
new XElement("Price", Price.ToString()),
|
|
|
|
|
new XElement("ReinforcedComponents", Components.Select(x =>
|
|
|
|
|
new XElement("ReinforcedComponent",
|
|
|
|
|
new XElement("Key", x.Key),
|
|
|
|
|
new XElement("Value", x.Value)))
|
|
|
|
|
.ToArray()));
|
|
|
|
|
}
|
|
|
|
|
}
|