Доделала
This commit is contained in:
parent
c383eac7a5
commit
a798cf5d69
@ -37,8 +37,7 @@ namespace ConfectioneryFileImplement
|
|||||||
Pastrys = LoadData(PastryFileName, "Pastry", x => Pastry.Create(x)!)!;
|
Pastrys = LoadData(PastryFileName, "Pastry", x => Pastry.Create(x)!)!;
|
||||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
Orders = LoadData(OrderFileName, "Order", x => Order.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)
|
|
||||||
{
|
{
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
@ -47,13 +46,11 @@ namespace ConfectioneryFileImplement
|
|||||||
}
|
}
|
||||||
return new List<T>();
|
return new List<T>();
|
||||||
}
|
}
|
||||||
private static void SaveData<T>(List<T> data, string filename, string
|
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
|
||||||
xmlNodeName, Func<T, XElement> selectFunction)
|
|
||||||
{
|
{
|
||||||
if (data != null)
|
if (data != null)
|
||||||
{
|
{
|
||||||
new XDocument(new XElement(xmlNodeName,
|
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
|
||||||
data.Select(selectFunction).ToArray())).Save(filename);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,10 +83,10 @@ namespace ConfectioneryFileImplement.Implements
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var pizza = source.Pastrys.FirstOrDefault(x => x.Id == model.PastryId);
|
var pastry = source.Pastrys.FirstOrDefault(x => x.Id == model.PastryId);
|
||||||
if (pizza != null)
|
if (pastry != null)
|
||||||
{
|
{
|
||||||
model.PastryName = pizza.PastryName;
|
model.PastryName = pastry.PastryName;
|
||||||
}
|
}
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
@ -58,11 +58,8 @@ namespace ConfectioneryFileImplement.Models
|
|||||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
PastryName = element.Element("PastryName")!.Value,
|
PastryName = element.Element("PastryName")!.Value,
|
||||||
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||||
Components =
|
Components = element.Element("PastryComponents")!.Elements("PastryComponent").ToDictionary
|
||||||
element.Element("PastryComponents")!.Elements("PastryComponent")
|
(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||||
.ToDictionary(x =>
|
|
||||||
Convert.ToInt32(x.Element("Key")?.Value), x =>
|
|
||||||
Convert.ToInt32(x.Element("Value")?.Value))
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void Update(PastryBindingModel model)
|
public void Update(PastryBindingModel model)
|
||||||
@ -73,8 +70,7 @@ Convert.ToInt32(x.Element("Value")?.Value))
|
|||||||
}
|
}
|
||||||
PastryName = model.PastryName;
|
PastryName = model.PastryName;
|
||||||
Price = model.Price;
|
Price = model.Price;
|
||||||
Components = model.PastryComponents.ToDictionary(x => x.Key, x =>
|
Components = model.PastryComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
x.Value.Item2);
|
|
||||||
_pastryComponents = null;
|
_pastryComponents = null;
|
||||||
}
|
}
|
||||||
public PastryViewModel GetViewModel => new()
|
public PastryViewModel GetViewModel => new()
|
||||||
|
Loading…
Reference in New Issue
Block a user