Доделала

This commit is contained in:
malimova 2024-03-15 10:52:30 +04:00
parent c383eac7a5
commit a798cf5d69
3 changed files with 9 additions and 16 deletions

View File

@ -37,8 +37,7 @@ namespace ConfectioneryFileImplement
Pastrys = LoadData(PastryFileName, "Pastry", x => Pastry.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
Func<XElement, T> selectFunction)
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{
if (File.Exists(filename))
{
@ -47,13 +46,11 @@ namespace ConfectioneryFileImplement
}
return new List<T>();
}
private static void SaveData<T>(List<T> data, string filename, string
xmlNodeName, Func<T, XElement> selectFunction)
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
{
if (data != null)
{
new XDocument(new XElement(xmlNodeName,
data.Select(selectFunction).ToArray())).Save(filename);
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
}
}
}

View File

@ -83,10 +83,10 @@ namespace ConfectioneryFileImplement.Implements
{
return null;
}
var pizza = source.Pastrys.FirstOrDefault(x => x.Id == model.PastryId);
if (pizza != null)
var pastry = source.Pastrys.FirstOrDefault(x => x.Id == model.PastryId);
if (pastry != null)
{
model.PastryName = pizza.PastryName;
model.PastryName = pastry.PastryName;
}
return model;
}

View File

@ -58,11 +58,8 @@ namespace ConfectioneryFileImplement.Models
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
PastryName = element.Element("PastryName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
Components =
element.Element("PastryComponents")!.Elements("PastryComponent")
.ToDictionary(x =>
Convert.ToInt32(x.Element("Key")?.Value), x =>
Convert.ToInt32(x.Element("Value")?.Value))
Components = element.Element("PastryComponents")!.Elements("PastryComponent").ToDictionary
(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(PastryBindingModel model)
@ -73,8 +70,7 @@ Convert.ToInt32(x.Element("Value")?.Value))
}
PastryName = model.PastryName;
Price = model.Price;
Components = model.PastryComponents.ToDictionary(x => x.Key, x =>
x.Value.Item2);
Components = model.PastryComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
_pastryComponents = null;
}
public PastryViewModel GetViewModel => new()