ISEbd-22 Alimova M.S. Lab Work 02 base #2
@ -29,14 +29,13 @@ namespace ConfectioneryFileImplement
|
||||
"Components", x => x.GetXElement);
|
||||
public void SavePastrys() => SaveData(Pastrys, PastryFileName,
|
||||
"Pastrys", x => x.GetXElement);
|
||||
public void SaveOrders() { }
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName,
|
||||
"Orders", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x =>
|
||||
Component.Create(x)!)!;
|
||||
Pastrys = LoadData(PastryFileName, "Pastry", x =>
|
||||
Pastry.Create(x)!)!;
|
||||
Orders = new List<Order>();
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
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)
|
||||
|
@ -4,9 +4,9 @@ using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
public class Order
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int PastryId { get; private set; }
|
||||
|
@ -2,6 +2,7 @@
|
||||
using ConfectioneryContracts.SearchModels;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -82,10 +83,10 @@ namespace ConfectioneryFileImplement.Implements
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var pastry = source.Pastrys.FirstOrDefault(x => x.Id == model.PastryId);
|
||||
if (pastry != null)
|
||||
var pizza = source.Pastrys.FirstOrDefault(x => x.Id == model.PastryId);
|
||||
if (pizza != null)
|
||||
|
||||
{
|
||||
model.PastryName = pastry.PastryName;
|
||||
model.PastryName = pizza.PastryName;
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
@ -17,19 +17,19 @@ namespace ConfectioneryFileImplement.Models
|
||||
public double Price { get; private set; }
|
||||
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
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_productComponents == null)
|
||||
if (_pastryComponents == null)
|
||||
{
|
||||
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)!,
|
||||
y.Value));
|
||||
}
|
||||
return _productComponents;
|
||||
return _pastryComponents;
|
||||
}
|
||||
}
|
||||
public static Pastry? Create(PastryBindingModel model)
|
||||
@ -75,7 +75,7 @@ Convert.ToInt32(x.Element("Value")?.Value))
|
||||
Price = model.Price;
|
||||
Components = model.PastryComponents.ToDictionary(x => x.Key, x =>
|
||||
x.Value.Item2);
|
||||
_productComponents = null;
|
||||
_pastryComponents = null;
|
||||
}
|
||||
public PastryViewModel GetViewModel => new()
|
||||
{
|
||||
|
@ -92,9 +92,9 @@ namespace ConfectioneryView
|
||||
try
|
||||
{
|
||||
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);
|
||||
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
|
||||
textBoxSum.Text = Math.Round(count * (pastry?.Price ?? 0), 2).ToString();
|
||||
_logger.LogInformation("Расчет суммы заказа");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Loading…
Reference in New Issue
Block a user
Можно без if: viewModel.<Название продукта> = <элемент>?.<Название продукта>;