немного
This commit is contained in:
parent
30f244c552
commit
5a9a99b1b6
12
FishFactoryListImplement/DataFileSingleton1.cs
Normal file
12
FishFactoryListImplement/DataFileSingleton1.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FishFactoryListImplement
|
||||||
|
{
|
||||||
|
internal class DataFileSingleton1
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace FishFactoryListImplement.Models
|
namespace FishFactoryListImplement.Models
|
||||||
{
|
{
|
||||||
@ -14,11 +15,21 @@ namespace FishFactoryListImplement.Models
|
|||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public string CannedName { get; private set; } = string.Empty;
|
public string CannedName { get; private set; } = string.Empty;
|
||||||
public double Price { get; private set; }
|
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
|
public Dictionary<int, (IComponentModel, int)> CannedComponents
|
||||||
{
|
{
|
||||||
get;
|
get
|
||||||
private set;
|
{
|
||||||
} = new Dictionary<int, (IComponentModel, int)>();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
public static Canned? Create(CannedBindingModel? model)
|
public static Canned? Create(CannedBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -30,9 +41,26 @@ namespace FishFactoryListImplement.Models
|
|||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
CannedName = model.CannedName,
|
CannedName = model.CannedName,
|
||||||
Price = model.Price,
|
Price = model.Price,
|
||||||
CannedComponents = model.CannedComponents
|
Components = model.CannedComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
public void Update(CannedBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -41,7 +69,9 @@ namespace FishFactoryListImplement.Models
|
|||||||
}
|
}
|
||||||
CannedName = model.CannedName;
|
CannedName = model.CannedName;
|
||||||
Price = model.Price;
|
Price = model.Price;
|
||||||
CannedComponents = model.CannedComponents;
|
Components = model.CannedComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_cannedComponents = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
public CannedViewModel GetViewModel => new()
|
public CannedViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
@ -50,6 +80,13 @@ namespace FishFactoryListImplement.Models
|
|||||||
Price = Price,
|
Price = Price,
|
||||||
CannedComponents = CannedComponents
|
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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using FishFactoryContracts.BindingModels;
|
using FishFactoryContracts.BindingModels;
|
||||||
using FishFactoryContracts.ViewModels;
|
using FishFactoryContracts.ViewModels;
|
||||||
using FishFactoryDataModel.Models;
|
using FishFactoryDataModel.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace FishFactoryListImplement.Models
|
namespace FishFactoryListImplement.Models
|
||||||
{
|
{
|
||||||
@ -22,6 +23,21 @@ namespace FishFactoryListImplement.Models
|
|||||||
Cost = model.Cost
|
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)
|
public void Update(ComponentBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -37,5 +53,10 @@ namespace FishFactoryListImplement.Models
|
|||||||
ComponentName = ComponentName,
|
ComponentName = ComponentName,
|
||||||
Cost = Cost
|
Cost = Cost
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new("Component",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ComponentName", ComponentName),
|
||||||
|
new XElement("Cost", Cost.ToString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user