diff --git a/SushiBar/SushiBar/FormCreateOrder.cs b/SushiBar/SushiBar/FormCreateOrder.cs index 613f1b8..26d31f5 100644 --- a/SushiBar/SushiBar/FormCreateOrder.cs +++ b/SushiBar/SushiBar/FormCreateOrder.cs @@ -45,12 +45,12 @@ namespace SushiBarView try { int id = Convert.ToInt32(comboBoxSushi.SelectedValue); - var product = _logicS.ReadElement(new SushiSearchModel + var sushi = _logicS.ReadElement(new SushiSearchModel { Id = id }); int count = Convert.ToInt32(textBoxCount.Text); - textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + textBoxSum.Text = Math.Round(count * (sushi?.Price ?? 0), 2).ToString(); _logger.LogInformation("Расчет суммы заказа"); } catch (Exception ex) diff --git a/SushiBar/SushiBar/FormSushi.cs b/SushiBar/SushiBar/FormSushi.cs index 9d98bd1..67496b1 100644 --- a/SushiBar/SushiBar/FormSushi.cs +++ b/SushiBar/SushiBar/FormSushi.cs @@ -50,7 +50,7 @@ namespace SushiBarView } private void LoadData() { - _logger.LogInformation("Загрузка ингредиент суши"); + _logger.LogInformation("Загрузка ингредиентов суши"); try { if (_sushiIngredients != null) @@ -65,7 +65,7 @@ namespace SushiBarView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки ингредиент суши"); + _logger.LogError(ex, "Ошибка загрузки ингредиентов суши"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -83,13 +83,11 @@ namespace SushiBarView _logger.LogInformation("Добавление нового ингредиента: { IngredientName} - { Count}", form.IngredientModel.IngredientName, form.Count); if (_sushiIngredients.ContainsKey(form.Id)) { - _sushiIngredients[form.Id] = (form.IngredientModel, - form.Count); + _sushiIngredients[form.Id] = (form.IngredientModel, form.Count); } else { - _sushiIngredients.Add(form.Id, (form.IngredientModel, - form.Count)); + _sushiIngredients.Add(form.Id, (form.IngredientModel, form.Count)); } LoadData(); } @@ -102,8 +100,7 @@ namespace SushiBarView var service = Program.ServiceProvider?.GetService(typeof(FormSushiIngredients)); if (service is FormSushiIngredients form) { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); form.Id = id; form.Count = _sushiIngredients[id].Item2; if (form.ShowDialog() == DialogResult.OK) @@ -123,8 +120,7 @@ namespace SushiBarView { if (dataGridView.SelectedRows.Count == 1) { - if (MessageBox.Show("Удалить запись?", "Вопрос", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { @@ -133,8 +129,7 @@ namespace SushiBarView } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(); } @@ -148,20 +143,17 @@ namespace SushiBarView { if (string.IsNullOrEmpty(textBoxName.Text)) { - MessageBox.Show("Заполните название", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(textBoxPrice.Text)) { - MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (_sushiIngredients == null || _sushiIngredients.Count == 0) { - MessageBox.Show("Заполните ингредиенты", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните ингредиенты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _logger.LogInformation("Сохранение суши"); diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs index 5b93cb8..0b3ba93 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs @@ -105,7 +105,7 @@ namespace SushiBarBusinessLogic.BusinessLogics }); if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Компонент с таким названием уже есть"); + throw new InvalidOperationException("Ингридиент с таким названием уже есть"); } } } diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 13b21b6..8b5ad72 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -18,6 +18,18 @@ namespace SushiBarBusinessLogic.BusinessLogics _logger = logger; _orderStorage = orderStorage; } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("Order. OrderID:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } public bool CreateOrder(OrderBindingModel model) { @@ -36,6 +48,30 @@ namespace SushiBarBusinessLogic.BusinessLogics } return true; } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.SushiId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор у суши", nameof(model.SushiId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество суши в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. OrderID:{Id}. Sum:{ Sum}. SushiId: { SushiId}", model.Id, model.Sum, model.SushiId); + } public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) { @@ -70,43 +106,5 @@ namespace SushiBarBusinessLogic.BusinessLogics { return StatusUpdate(model, OrderStatus.Готов); } - - public List? ReadList(OrderSearchModel? model) - { - _logger.LogInformation("Order. OrderID:{Id}", model?.Id); - var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - - private void CheckModel(OrderBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.SushiId < 0) - { - throw new ArgumentNullException("Некорректный идентификатор у суши", nameof(model.SushiId)); - } - if (model.Count <= 0) - { - throw new ArgumentNullException("Количество суши в заказе должно быть больше 0", nameof(model.Count)); - } - if (model.Sum <= 0) - { - throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); - } - _logger.LogInformation("Order. OrderID:{Id}. Sum:{ Sum}. SushiId: { SushiId}", model.Id, model.Sum, model.SushiId); - } } } diff --git a/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs b/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs index 15a0746..92a771b 100644 --- a/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs @@ -16,9 +16,9 @@ namespace SushiBarListImplement.Implements public List GetFullList() { var result = new List(); - foreach (var component in _source.Ingredients) + foreach (var ingredient in _source.Ingredients) { - result.Add(component.GetViewModel); + result.Add(ingredient.GetViewModel); } return result; } @@ -29,11 +29,11 @@ namespace SushiBarListImplement.Implements { return result; } - foreach (var component in _source.Ingredients) + foreach (var ingredient in _source.Ingredients) { - if (component.IngredientName.Contains(model.IngredientName)) + if (ingredient.IngredientName.Contains(model.IngredientName)) { - result.Add(component.GetViewModel); + result.Add(ingredient.GetViewModel); } } return result; @@ -44,13 +44,12 @@ namespace SushiBarListImplement.Implements { return null; } - foreach (var component in _source.Ingredients) + foreach (var ingredient in _source.Ingredients) { - if ((!string.IsNullOrEmpty(model.IngredientName) && - component.IngredientName == model.IngredientName) || - (model.Id.HasValue && component.Id == model.Id)) + if ((!string.IsNullOrEmpty(model.IngredientName) && ingredient.IngredientName == model.IngredientName) || + (model.Id.HasValue && ingredient.Id == model.Id)) { - return component.GetViewModel; + return ingredient.GetViewModel; } } return null; @@ -58,11 +57,11 @@ namespace SushiBarListImplement.Implements public IngredientViewModel? Insert(IngredientBindingModel model) { model.Id = 1; - foreach (var component in _source.Ingredients) + foreach (var ingredient in _source.Ingredients) { - if (model.Id <= component.Id) + if (model.Id <= ingredient.Id) { - model.Id = component.Id + 1; + model.Id = ingredient.Id + 1; } } var newIngredient = Ingredient.Create(model); @@ -75,12 +74,12 @@ namespace SushiBarListImplement.Implements } public IngredientViewModel? Update(IngredientBindingModel model) { - foreach (var component in _source.Ingredients) + foreach (var ingredient in _source.Ingredients) { - if (component.Id == model.Id) + if (ingredient.Id == model.Id) { - component.Update(model); - return component.GetViewModel; + ingredient.Update(model); + return ingredient.GetViewModel; } } return null; diff --git a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs index 7674b86..d2878ca 100644 --- a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs @@ -47,8 +47,7 @@ namespace SushiBarListImplement.Implements } foreach (var sushi in _source.ListSushi) { - if ((!string.IsNullOrEmpty(model.SushiName) && - sushi.SushiName == model.SushiName) || + if ((!string.IsNullOrEmpty(model.SushiName) && sushi.SushiName == model.SushiName) || (model.Id.HasValue && sushi.Id == model.Id)) { return sushi.GetViewModel; diff --git a/SushiBar/SushiBarListImplement/Models/Order.cs b/SushiBar/SushiBarListImplement/Models/Order.cs index 6d2dbba..a3bcd59 100644 --- a/SushiBar/SushiBarListImplement/Models/Order.cs +++ b/SushiBar/SushiBarListImplement/Models/Order.cs @@ -7,6 +7,7 @@ namespace SushiBarListImplement.Models { public class Order : IOrderModel { + public int Id { get; private set; } public int SushiId { get; private set; } public string SushiName { get; private set; } = string.Empty; public int Count { get; private set; } @@ -14,7 +15,6 @@ namespace SushiBarListImplement.Models public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } - public int Id { get; private set; } public static Order? Create(OrderBindingModel? model) { if (model == null)