Complete
This commit is contained in:
parent
8edde4a4fc
commit
16d53bc9ec
@ -4,7 +4,7 @@ using NLog.Extensions.Logging;
|
||||
using SushiBarBusinessLogic.BusinessLogics;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushibarListImplement.Implements;
|
||||
using SushiBarFileImplement.Implements;
|
||||
|
||||
namespace SushiBar
|
||||
{
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SushiBarBusinessLogic\SushiBarBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\SushiBarFileImplement\SushiBarFileImplement.csproj" />
|
||||
<ProjectReference Include="..\SushibarListImplement\SushibarListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -8,7 +8,7 @@ namespace SushiBarFileImplement
|
||||
private static DataFileSingleton? instance;
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string ProductFileName = "Sushi.xml";
|
||||
private readonly string SushiFileName = "Sushi.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Sushi> Sushis { get; private set; }
|
||||
@ -18,13 +18,13 @@ namespace SushiBarFileImplement
|
||||
return instance;
|
||||
}
|
||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||
public void SaveProducts() => SaveData(Sushis, ProductFileName, "Sushis", x => x.GetXElement);
|
||||
public void SaveSushis() => SaveData(Sushis, SushiFileName, "Sushis", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Sushis = LoadData(ProductFileName, "Sushi", x => Sushi.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Sushis = LoadData(SushiFileName, "Sushi", x => Sushi.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
}
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ namespace SushiBarFileImplement.Implements
|
||||
if (element != null)
|
||||
{
|
||||
source.Orders.Remove(element);
|
||||
source.SaveComponents();
|
||||
source.SaveOrders();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
@ -67,7 +67,7 @@ namespace SushiBarFileImplement.Implements
|
||||
return null;
|
||||
}
|
||||
source.Orders.Add(newOrder);
|
||||
source.SaveComponents();
|
||||
source.SaveOrders();
|
||||
return newOrder.GetViewModel;
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ namespace SushiBarFileImplement.Implements
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
source.SaveComponents();
|
||||
source.SaveOrders();
|
||||
return order.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace SushiBarFileImplement.Implements
|
||||
if (element != null)
|
||||
{
|
||||
source.Sushis.Remove(element);
|
||||
source.SaveComponents();
|
||||
source.SaveSushis();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
@ -70,7 +70,7 @@ namespace SushiBarFileImplement.Implements
|
||||
return null;
|
||||
}
|
||||
source.Sushis.Add(newSushi);
|
||||
source.SaveComponents();
|
||||
source.SaveSushis();
|
||||
return newSushi.GetViewModel;
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ namespace SushiBarFileImplement.Implements
|
||||
return null;
|
||||
}
|
||||
sushi.Update(model);
|
||||
source.SaveComponents();
|
||||
source.SaveSushis();
|
||||
return sushi.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ namespace SushiBarFileImplement.Models
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
SushiName = element.Element("SushiName")!.Value,
|
||||
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||
Components = element.Element("ProductComponents")!
|
||||
Components = element.Element("SushiComponents")!
|
||||
.Elements("ProductComponent")
|
||||
.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||
@ -74,7 +74,7 @@ namespace SushiBarFileImplement.Models
|
||||
Price = Price,
|
||||
SushiComponents = SushiComponents
|
||||
};
|
||||
public XElement GetXElement => new("Product",
|
||||
public XElement GetXElement => new("Sushi",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("SushiName", SushiName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
|
Loading…
Reference in New Issue
Block a user