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