This commit is contained in:
Viltskaa 2023-02-13 19:08:26 +04:00
parent 8edde4a4fc
commit 16d53bc9ec
6 changed files with 14 additions and 13 deletions

View File

@ -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
{

View File

@ -15,6 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\SushiBarBusinessLogic\SushiBarBusinessLogic.csproj" />
<ProjectReference Include="..\SushiBarFileImplement\SushiBarFileImplement.csproj" />
<ProjectReference Include="..\SushibarListImplement\SushibarListImplement.csproj" />
</ItemGroup>

View File

@ -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,12 +18,12 @@ 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)!)!;
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)

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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()),