Фикс ошибочек
This commit is contained in:
parent
d1ef782fa6
commit
c383eac7a5
@ -29,14 +29,13 @@ namespace ConfectioneryFileImplement
|
|||||||
"Components", x => x.GetXElement);
|
"Components", x => x.GetXElement);
|
||||||
public void SavePastrys() => SaveData(Pastrys, PastryFileName,
|
public void SavePastrys() => SaveData(Pastrys, PastryFileName,
|
||||||
"Pastrys", x => x.GetXElement);
|
"Pastrys", x => x.GetXElement);
|
||||||
public void SaveOrders() { }
|
public void SaveOrders() => SaveData(Orders, OrderFileName,
|
||||||
|
"Orders", x => x.GetXElement);
|
||||||
private DataFileSingleton()
|
private DataFileSingleton()
|
||||||
{
|
{
|
||||||
Components = LoadData(ComponentFileName, "Component", x =>
|
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||||
Component.Create(x)!)!;
|
Pastrys = LoadData(PastryFileName, "Pastry", x => Pastry.Create(x)!)!;
|
||||||
Pastrys = LoadData(PastryFileName, "Pastry", x =>
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
Pastry.Create(x)!)!;
|
|
||||||
Orders = new List<Order>();
|
|
||||||
}
|
}
|
||||||
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)
|
||||||
|
@ -4,9 +4,9 @@ using ConfectioneryContracts.BindingModels;
|
|||||||
using ConfectioneryContracts.ViewModels;
|
using ConfectioneryContracts.ViewModels;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace ConfectioneryFileImplement
|
namespace ConfectioneryFileImplement.Models
|
||||||
{
|
{
|
||||||
public class Order
|
public class Order : IOrderModel
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public int PastryId { get; private set; }
|
public int PastryId { get; private set; }
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using ConfectioneryContracts.SearchModels;
|
using ConfectioneryContracts.SearchModels;
|
||||||
using ConfectioneryContracts.StoragesContracts;
|
using ConfectioneryContracts.StoragesContracts;
|
||||||
using ConfectioneryContracts.ViewModels;
|
using ConfectioneryContracts.ViewModels;
|
||||||
|
using ConfectioneryFileImplement.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -82,10 +83,10 @@ namespace ConfectioneryFileImplement.Implements
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var pastry = source.Pastrys.FirstOrDefault(x => x.Id == model.PastryId);
|
var pizza = source.Pastrys.FirstOrDefault(x => x.Id == model.PastryId);
|
||||||
if (pastry != null)
|
if (pizza != null)
|
||||||
{
|
{
|
||||||
model.PastryName = pastry.PastryName;
|
model.PastryName = pizza.PastryName;
|
||||||
}
|
}
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
@ -17,19 +17,19 @@ namespace ConfectioneryFileImplement.Models
|
|||||||
public double Price { get; private set; }
|
public double Price { get; private set; }
|
||||||
public Dictionary<int, int> Components { get; private set; } = new();
|
public Dictionary<int, int> Components { get; private set; } = new();
|
||||||
|
|
||||||
private Dictionary<int, (IComponentModel, int)>? _productComponents = null;
|
private Dictionary<int, (IComponentModel, int)>? _pastryComponents = null;
|
||||||
public Dictionary<int, (IComponentModel, int)> PastryComponents
|
public Dictionary<int, (IComponentModel, int)> PastryComponents
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_productComponents == null)
|
if (_pastryComponents == null)
|
||||||
{
|
{
|
||||||
var source = DataFileSingleton.GetInstance();
|
var source = DataFileSingleton.GetInstance();
|
||||||
_productComponents = Components.ToDictionary(x => x.Key, y =>
|
_pastryComponents = Components.ToDictionary(x => x.Key, y =>
|
||||||
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
|
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
|
||||||
y.Value));
|
y.Value));
|
||||||
}
|
}
|
||||||
return _productComponents;
|
return _pastryComponents;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static Pastry? Create(PastryBindingModel model)
|
public static Pastry? Create(PastryBindingModel model)
|
||||||
@ -75,7 +75,7 @@ Convert.ToInt32(x.Element("Value")?.Value))
|
|||||||
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);
|
||||||
_productComponents = null;
|
_pastryComponents = null;
|
||||||
}
|
}
|
||||||
public PastryViewModel GetViewModel => new()
|
public PastryViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
|
@ -92,9 +92,9 @@ namespace ConfectioneryView
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
int id = Convert.ToInt32(comboBoxPastry.SelectedValue);
|
int id = Convert.ToInt32(comboBoxPastry.SelectedValue);
|
||||||
var product = _logicP.ReadElement(new PastrySearchModel { Id = id });
|
var pastry = _logicP.ReadElement(new PastrySearchModel { Id = id });
|
||||||
int count = Convert.ToInt32(textBoxCount.Text);
|
int count = Convert.ToInt32(textBoxCount.Text);
|
||||||
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
|
textBoxSum.Text = Math.Round(count * (pastry?.Price ?? 0), 2).ToString();
|
||||||
_logger.LogInformation("Расчет суммы заказа");
|
_logger.LogInformation("Расчет суммы заказа");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
Loading…
Reference in New Issue
Block a user