From 79bb7173152b12489b11996cee4a8f541752eeaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=B0=D1=82=20=D0=97=D0=B0=D1=80=D0=B3?= =?UTF-8?q?=D0=B0=D1=80=D0=BE=D0=B2?= Date: Sun, 5 Mar 2023 22:35:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D0=B5=D1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pizzeria/Pizzeria.sln | 4 +- Pizzeria/PizzeriaBusinessLogic/OrderLogic.cs | 147 +++++++++++------- Pizzeria/PizzeriaBusinessLogic/PizzaLogic.cs | 16 +- .../BindingModels/OrderBindingModel.cs | 2 +- .../BindingModels/PizzaBindingModel.cs | 4 +- .../SearchModels/PizzaSearchModel.cs | 2 +- .../ViewModels/OrderViewModel.cs | 4 +- .../ViewModels/PizzaViewModel.cs | 4 +- .../PizzeriaDataModels/Models/IOrderModel.cs | 2 +- .../PizzeriaDataModels/Models/IPizzaModel.cs | 4 +- .../DataListSingleton.cs | 4 +- .../Implements/OrderStorage.cs | 6 +- .../Implements/PizzaStorage.cs | 28 ++-- .../PizzeriaListImplement/Models/Order.cs | 7 +- .../PizzeriaListImplement/Models/Pizza.cs | 16 +- Pizzeria/PizzeriaView/FormPizza.cs | 32 ++-- Pizzeria/PizzeriaView/FormPizzaComponent.cs | 3 +- Pizzeria/PizzeriaView/PizzeriaView.csproj | 1 + Pizzeria/PizzeriaView/Program.cs | 1 + Pizzeria/PizzeriaView/nlog.config | 2 +- 20 files changed, 160 insertions(+), 129 deletions(-) diff --git a/Pizzeria/Pizzeria.sln b/Pizzeria/Pizzeria.sln index 58f0b2d..0cdc8a9 100644 --- a/Pizzeria/Pizzeria.sln +++ b/Pizzeria/Pizzeria.sln @@ -9,9 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaContracts", "Pizzer EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaBusinessLogic", "PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj", "{D8EAAB67-47C6-443D-83FC-E1337F105F67}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{922551CE-15B0-42C8-AA1A-368C8399CAD6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{922551CE-15B0-42C8-AA1A-368C8399CAD6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaView", "PizzeriaView\PizzeriaView.csproj", "{25FCC09C-88AE-4515-9235-FB9C17972034}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaView", "PizzeriaView\PizzeriaView.csproj", "{25FCC09C-88AE-4515-9235-FB9C17972034}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Pizzeria/PizzeriaBusinessLogic/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/OrderLogic.cs index 2af3a9a..f9a47a8 100644 --- a/Pizzeria/PizzeriaBusinessLogic/OrderLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/OrderLogic.cs @@ -17,14 +17,74 @@ namespace PizzeriaBusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; _orderStorage = orderStorage; } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != OrderStatus.Готов) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус готовности перед выдачей!"); + } + model.Status = OrderStatus.Выдан; + model.DateImplement = DateTime.Now; + _orderStorage.Update(model); + return true; + } + + public bool FinishOrder(OrderBindingModel model) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != OrderStatus.Выполняется) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус выполнения перед готовностью!"); + } + model.Status = OrderStatus.Готов; + _orderStorage.Update(model); + return true; + } + public List? ReadList(OrderSearchModel? model) { - _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); if (list == null) { @@ -34,31 +94,29 @@ namespace PizzeriaBusinessLogic _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - public bool CreateOrder(OrderBindingModel model) - { - CheckModel(model); - if (model.Status != OrderStatus.Неизвестен) - return false; - model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } + public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); - } - public bool FinishOrder(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Готов); - } - public bool DeliveryOrder(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Выдан); + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != OrderStatus.Принят) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!"); + } + model.Status = OrderStatus.Выполняется; + _orderStorage.Update(model); + return true; } + private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) @@ -69,52 +127,23 @@ namespace PizzeriaBusinessLogic { return; } - if (model.Count <= 0) - { - throw new ArgumentException("Количество пиццы в заказе не может быть меньше 1", nameof(model.Count)); - } if (model.Sum <= 0) { - throw new ArgumentException("Стоимость заказа на может быть меньше 1", nameof(model.Sum)); + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); } - if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) + if (model.Count <= 0) { - throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}"); + throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); } - _logger.LogInformation("Pizza. PizzaId:{PizzaId}.Count:{Count}.Sum:{Sum}Id:{Id}", - model.ProductId, model.Count, model.Sum, model.Id); - } - private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus) - { - CheckModel(model, false); - var element = _orderStorage.GetElement(new OrderSearchModel() + _logger.LogInformation("Order. Sum:{Sum}. Id:{Id}", model.Sum, model.Id); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); - if (element == null) + if (element != null && element.Id != model.Id) { - throw new ArgumentNullException(nameof(element)); + throw new InvalidOperationException("Заказ с таким ID уже существует"); } - model.DateCreate = element.DateCreate; - model.ProductId = element.ProductId; - model.DateImplement = element.DateImplement; - model.Status = element.Status; - model.Count = element.Count; - model.Sum = element.Sum; - if (requiredStatus - model.Status == 1) - { - model.Status = requiredStatus; - if (model.Status == OrderStatus.Выдан) - model.DateImplement = DateTime.Now; - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - _logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus); - throw new ArgumentException($"Невозможно присвоить статус {requiredStatus} заказу с текущим статусом {model.Status}"); } } } diff --git a/Pizzeria/PizzeriaBusinessLogic/PizzaLogic.cs b/Pizzeria/PizzeriaBusinessLogic/PizzaLogic.cs index 1eba832..f21fc35 100644 --- a/Pizzeria/PizzeriaBusinessLogic/PizzaLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/PizzaLogic.cs @@ -23,7 +23,7 @@ namespace PizzeriaBusinessLogic } public List? ReadList(PizzaSearchModel? model) { - _logger.LogInformation("ReadList. PizzaName:{PizzaName}.Id:{ Id}", model?.ProductName, model?.Id); + _logger.LogInformation("ReadList. PizzaName:{PizzaName}.Id:{ Id}", model?.PizzaName, model?.Id); var list = model == null ? _PizzaStorage.GetFullList() : _PizzaStorage.GetFilteredList(model); if (list == null) { @@ -39,7 +39,7 @@ namespace PizzeriaBusinessLogic { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. PizzaName:{PizzaName}.Id:{ Id}", model.ProductName, model.Id); + _logger.LogInformation("ReadElement. PizzaName:{PizzaName}.Id:{ Id}", model.PizzaName, model.Id); var element = _PizzaStorage.GetElement(model); if (element == null) { @@ -90,22 +90,22 @@ namespace PizzeriaBusinessLogic { return; } - if (string.IsNullOrEmpty(model.ProductName)) + if (string.IsNullOrEmpty(model.PizzaName)) { - throw new ArgumentNullException("Нет названия пиццы", nameof(model.ProductName)); + throw new ArgumentNullException("Нет названия пиццы", nameof(model.PizzaName)); } if (model.Price <= 0) { throw new ArgumentNullException("Цена пиццы должна быть больше 0", nameof(model.Price)); } - if (model.ProductComponents == null || model.ProductComponents.Count == 0) + if (model.PizzaComponents == null || model.PizzaComponents.Count == 0) { - throw new ArgumentNullException("Перечень ингредиентов не может быть пустым", nameof(model.ProductComponents)); + throw new ArgumentNullException("Перечень ингредиентов не может быть пустым", nameof(model.PizzaComponents)); } - _logger.LogInformation("Pizza. PizzaName:{PizzaName}.Price:{Price}.Id: { Id}", model.ProductName, model.Price, model.Id); + _logger.LogInformation("Pizza. PizzaName:{PizzaName}.Price:{Price}.Id: { Id}", model.PizzaName, model.Price, model.Id); var element = _PizzaStorage.GetElement(new PizzaSearchModel { - ProductName = model.ProductName + PizzaName = model.PizzaName }); if (element != null && element.Id != model.Id) { diff --git a/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs index 42eef98..ecf2e34 100644 --- a/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs +++ b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs @@ -10,7 +10,7 @@ namespace PizzeriaContracts.BindingModels public class OrderBindingModel : IOrderModel { public int Id { get; set; } - public int ProductId { get; set; } + public int PizzaId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs index 919f93e..53291c9 100644 --- a/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs +++ b/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs @@ -10,9 +10,9 @@ namespace PizzeriaContracts.BindingModels public class PizzaBindingModel : IPizzaModel { public int Id { get; set; } - public string ProductName { get; set; } = string.Empty; + public string PizzaName { get; set; } = string.Empty; public double Price { get; set; } - public Dictionary ProductComponents + public Dictionary PizzaComponents { get; set; diff --git a/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs index 5561e40..9f01679 100644 --- a/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs +++ b/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs @@ -9,7 +9,7 @@ namespace PizzeriaContracts.SearchModels public class PizzaSearchModel { public int? Id { get; set; } - public string? ProductName { get; set; } + public string? PizzaName { get; set; } } } diff --git a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs index 8ddf93e..19f695c 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs @@ -12,9 +12,9 @@ namespace PizzeriaContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } - public int ProductId { get; set; } + public int PizzaId { get; set; } [DisplayName("Изделие")] - public string ProductName { get; set; } = string.Empty; + public string PizzaName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] diff --git a/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs index b0d9724..9bde662 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs @@ -12,10 +12,10 @@ namespace PizzeriaContracts.ViewModels { public int Id { get; set; } [DisplayName("Название изделия")] - public string ProductName { get; set; } = string.Empty; + public string PizzaName { get; set; } = string.Empty; [DisplayName("Цена")] public double Price { get; set; } - public Dictionary ProductComponents + public Dictionary PizzaComponents { get; set; diff --git a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs index 189bedb..6c88ac2 100644 --- a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs +++ b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs @@ -8,7 +8,7 @@ namespace PizzeriaDataModels { public interface IOrderModel : IId { - int ProductId { get; } + int PizzaId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs b/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs index 724b9da..1837d3b 100644 --- a/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs +++ b/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs @@ -8,8 +8,8 @@ namespace PizzeriaDataModels { public interface IPizzaModel : IId { - string ProductName { get; } + string PizzaName { get; } double Price { get; } - Dictionary ProductComponents { get; } + Dictionary PizzaComponents { get; } } } diff --git a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs index 29bd0a8..c9909f5 100644 --- a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs +++ b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs @@ -12,12 +12,12 @@ namespace PizzeriaListImplement private static DataListSingleton? _instance; public List Components { get; set; } public List Orders { get; set; } - public List Products { get; set; } + public List Pizzas { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); - Products = new List(); + Pizzas = new List(); } public static DataListSingleton GetInstance() { diff --git a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs index 83351f7..b594b9b 100644 --- a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs +++ b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs @@ -105,11 +105,11 @@ namespace PizzeriaListImplement.Implements } private OrderViewModel AttachPizzaName(OrderViewModel model) { - foreach (var pizza in _source.Products) + foreach (var pizza in _source.Pizzas) { - if (pizza.Id == model.ProductId) + if (pizza.Id == model.PizzaId) { - model.ProductName = pizza.ProductName; + model.PizzaName = pizza.PizzaName; return model; } } diff --git a/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs index ca04083..d799b14 100644 --- a/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs +++ b/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs @@ -21,7 +21,7 @@ namespace PizzeriaListImplement.Implements public List GetFullList() { var result = new List(); - foreach (var pizzas in _source.Products) + foreach (var pizzas in _source.Pizzas) { result.Add(pizzas.GetViewModel); } @@ -30,13 +30,13 @@ namespace PizzeriaListImplement.Implements public List GetFilteredList(PizzaSearchModel model) { var result = new List(); - if (string.IsNullOrEmpty(model.ProductName)) + if (string.IsNullOrEmpty(model.PizzaName)) { return result; } - foreach (var pizzas in _source.Products) + foreach (var pizzas in _source.Pizzas) { - if (pizzas.ProductName.Contains(model.ProductName)) + if (pizzas.PizzaName.Contains(model.PizzaName)) { result.Add(pizzas.GetViewModel); } @@ -45,13 +45,13 @@ namespace PizzeriaListImplement.Implements } public PizzaViewModel? GetElement(PizzaSearchModel model) { - if (string.IsNullOrEmpty(model.ProductName) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.PizzaName) && !model.Id.HasValue) { return null; } - foreach (var pizzas in _source.Products) + foreach (var pizzas in _source.Pizzas) { - if ((!string.IsNullOrEmpty(model.ProductName) && pizzas.ProductName == model.ProductName) || + if ((!string.IsNullOrEmpty(model.PizzaName) && pizzas.PizzaName == model.PizzaName) || (model.Id.HasValue && pizzas.Id == model.Id)) { return pizzas.GetViewModel; @@ -62,7 +62,7 @@ namespace PizzeriaListImplement.Implements public PizzaViewModel? Insert(PizzaBindingModel model) { model.Id = 1; - foreach (var pizzas in _source.Products) + foreach (var pizzas in _source.Pizzas) { if (model.Id <= pizzas.Id) { @@ -74,12 +74,12 @@ namespace PizzeriaListImplement.Implements { return null; } - _source.Products.Add(newPizzas); + _source.Pizzas.Add(newPizzas); return newPizzas.GetViewModel; } public PizzaViewModel? Update(PizzaBindingModel model) { - foreach (var pizzas in _source.Products) + foreach (var pizzas in _source.Pizzas) { if (pizzas.Id == model.Id) { @@ -91,12 +91,12 @@ namespace PizzeriaListImplement.Implements } public PizzaViewModel? Delete(PizzaBindingModel model) { - for (int i = 0; i < _source.Products.Count; ++i) + for (int i = 0; i < _source.Pizzas.Count; ++i) { - if (_source.Products[i].Id == model.Id) + if (_source.Pizzas[i].Id == model.Id) { - var element = _source.Products[i]; - _source.Products.RemoveAt(i); + var element = _source.Pizzas[i]; + _source.Pizzas.RemoveAt(i); return element.GetViewModel; } } diff --git a/Pizzeria/PizzeriaListImplement/Models/Order.cs b/Pizzeria/PizzeriaListImplement/Models/Order.cs index 2e50249..ae0951e 100644 --- a/Pizzeria/PizzeriaListImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaListImplement/Models/Order.cs @@ -12,7 +12,7 @@ namespace PizzeriaListImplement.Models public class Order : IOrderModel { public int Id { get; private set; } - public int ProductId { get; private set; } + public int PizzaId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -27,7 +27,7 @@ namespace PizzeriaListImplement.Models return new Order() { Id = model.Id, - ProductId = model.ProductId, + PizzaId = model.PizzaId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -42,11 +42,12 @@ namespace PizzeriaListImplement.Models return; } Status = model.Status; + if (model.DateImplement.HasValue) DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { Id = Id, - ProductId = ProductId, + PizzaId = PizzaId, Count = Count, Sum = Sum, Status = Status, diff --git a/Pizzeria/PizzeriaListImplement/Models/Pizza.cs b/Pizzeria/PizzeriaListImplement/Models/Pizza.cs index cfd5155..c233c87 100644 --- a/Pizzeria/PizzeriaListImplement/Models/Pizza.cs +++ b/Pizzeria/PizzeriaListImplement/Models/Pizza.cs @@ -12,9 +12,9 @@ namespace PizzeriaListImplement.Models public class Pizza : IPizzaModel { public int Id { get; private set; } - public string ProductName { get; private set; } = string.Empty; + public string PizzaName { get; private set; } = string.Empty; public double Price { get; private set; } - public Dictionary ProductComponents + public Dictionary PizzaComponents { get; private set; @@ -28,9 +28,9 @@ namespace PizzeriaListImplement.Models return new Pizza() { Id = model.Id, - ProductName = model.ProductName, + PizzaName = model.PizzaName, Price = model.Price, - ProductComponents = model.ProductComponents + PizzaComponents = model.PizzaComponents }; } public void Update(PizzaBindingModel? model) @@ -39,16 +39,16 @@ namespace PizzeriaListImplement.Models { return; } - ProductName = model.ProductName; + PizzaName = model.PizzaName; Price = model.Price; - ProductComponents = model.ProductComponents; + PizzaComponents = model.PizzaComponents; } public PizzaViewModel GetViewModel => new() { Id = Id, - ProductName = ProductName, + PizzaName = PizzaName, Price = Price, - ProductComponents = ProductComponents + PizzaComponents = PizzaComponents }; } diff --git a/Pizzeria/PizzeriaView/FormPizza.cs b/Pizzeria/PizzeriaView/FormPizza.cs index 15ff1d9..c1bab59 100644 --- a/Pizzeria/PizzeriaView/FormPizza.cs +++ b/Pizzeria/PizzeriaView/FormPizza.cs @@ -21,14 +21,14 @@ namespace PizzeriaView private readonly ILogger _logger; private readonly IPizzaLogic _logic; private int? _id; - private Dictionary _ProductComponents; + private Dictionary _PizzaComponents; public int Id { set { _id = value; } } public FormPizza(ILogger logger, IPizzaLogic logic) { InitializeComponent(); _logger = logger; _logic = logic; - _ProductComponents = new Dictionary(); + _PizzaComponents = new Dictionary(); } private void FormPizza_Load(object sender, EventArgs e) { @@ -43,9 +43,9 @@ namespace PizzeriaView }); if (view != null) { - textBoxName.Text = view.ProductName; + textBoxName.Text = view.PizzaName; textBoxPrice.Text = view.Price.ToString(); - _ProductComponents = view.ProductComponents ?? new + _PizzaComponents = view.PizzaComponents ?? new Dictionary(); LoadData(); } @@ -63,10 +63,10 @@ namespace PizzeriaView _logger.LogInformation("Загрузка ингредиент пиццы"); try { - if (_ProductComponents != null) + if (_PizzaComponents != null) { dataGridView.Rows.Clear(); - foreach (var pc in _ProductComponents) + foreach (var pc in _PizzaComponents) { dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); } @@ -92,13 +92,13 @@ namespace PizzeriaView return; } _logger.LogInformation("Добавление нового ингредиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); - if (_ProductComponents.ContainsKey(form.Id)) + if (_PizzaComponents.ContainsKey(form.Id)) { - _ProductComponents[form.Id] = (form.ComponentModel,form.Count); + _PizzaComponents[form.Id] = (form.ComponentModel,form.Count); } else { - _ProductComponents.Add(form.Id, (form.ComponentModel,form.Count)); + _PizzaComponents.Add(form.Id, (form.ComponentModel,form.Count)); } LoadData(); } @@ -113,7 +113,7 @@ namespace PizzeriaView { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); form.Id = id; - form.Count = _ProductComponents[id].Item2; + form.Count = _PizzaComponents[id].Item2; if (form.ShowDialog() == DialogResult.OK) { if (form.ComponentModel == null) @@ -121,7 +121,7 @@ namespace PizzeriaView return; } _logger.LogInformation("Изменение ингредиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); - _ProductComponents[form.Id] = (form.ComponentModel, form.Count); + _PizzaComponents[form.Id] = (form.ComponentModel, form.Count); LoadData(); } } @@ -136,7 +136,7 @@ namespace PizzeriaView try { _logger.LogInformation("Удаление ингредиента:{ ComponentName}-{ Count}", dataGridView.SelectedRows[0].Cells[1].Value); - _ProductComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + _PizzaComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); } catch (Exception ex) { @@ -163,7 +163,7 @@ namespace PizzeriaView MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (_ProductComponents == null || _ProductComponents.Count == 0) + if (_PizzaComponents == null || _PizzaComponents.Count == 0) { MessageBox.Show("Заполните ингредиенты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -174,9 +174,9 @@ namespace PizzeriaView var model = new PizzaBindingModel { Id = _id ?? 0, - ProductName = textBoxName.Text, + PizzaName = textBoxName.Text, Price = Convert.ToDouble(textBoxPrice.Text), - ProductComponents = _ProductComponents + PizzaComponents = _PizzaComponents }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); @@ -202,7 +202,7 @@ namespace PizzeriaView private double CalcPrice() { double price = 0; - foreach (var elem in _ProductComponents) + foreach (var elem in _PizzaComponents) { price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); } diff --git a/Pizzeria/PizzeriaView/FormPizzaComponent.cs b/Pizzeria/PizzeriaView/FormPizzaComponent.cs index 8c7b816..9fc1534 100644 --- a/Pizzeria/PizzeriaView/FormPizzaComponent.cs +++ b/Pizzeria/PizzeriaView/FormPizzaComponent.cs @@ -1,5 +1,4 @@ -using PizzeriaDataModels.Models; -using Microsoft.VisualBasic.Logging; +using Microsoft.VisualBasic.Logging; using PizzeriaContracts.BusinessLogicsContracts; using PizzeriaContracts.ViewModels; using System; diff --git a/Pizzeria/PizzeriaView/PizzeriaView.csproj b/Pizzeria/PizzeriaView/PizzeriaView.csproj index 4a33b51..545e71a 100644 --- a/Pizzeria/PizzeriaView/PizzeriaView.csproj +++ b/Pizzeria/PizzeriaView/PizzeriaView.csproj @@ -11,6 +11,7 @@ + diff --git a/Pizzeria/PizzeriaView/Program.cs b/Pizzeria/PizzeriaView/Program.cs index 0868b0e..37fa82c 100644 --- a/Pizzeria/PizzeriaView/Program.cs +++ b/Pizzeria/PizzeriaView/Program.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; using PizzeriaBusinessLogic; using PizzeriaContracts.BusinessLogicsContracts; using PizzeriaContracts.StorageContracts; diff --git a/Pizzeria/PizzeriaView/nlog.config b/Pizzeria/PizzeriaView/nlog.config index dcd37c8..b94cde0 100644 --- a/Pizzeria/PizzeriaView/nlog.config +++ b/Pizzeria/PizzeriaView/nlog.config @@ -5,7 +5,7 @@ autoReload="true" internalLogLevel="Info"> - +