diff --git a/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 07795aa..1b9cfd8 100644 --- a/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -15,127 +15,117 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics { public class OrderLogic : IOrderLogic { - private readonly ILogger _logger; - private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) - { - _logger = logger; - _orderStorage = orderStorage; - } - public List? ReadList(OrderSearchModel? model) - { - _logger.LogInformation("ReadList. Id:{ 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) - { - _orderStorage.Insert(new OrderBindingModel - { - WoodId = model.WoodId, - WoodName = model.WoodName, - Count = model.Count, - Sum = model.Sum, - Status = OrderStatus.Принят, - DateCreate = DateTime.Now - }); ; - return true; - } - public bool TakeOrderInWork(OrderBindingModel model) - { - var order = _orderStorage.GetElement(new OrderSearchModel - { - Id = model.Id - }); - if (order == null) - { - throw new Exception("Элемент не найден"); - } - if (order.Status.ToString() != "Принят") - { - throw new Exception("Заказ не в статусе \"Принят\""); - } - _orderStorage.Update(new OrderBindingModel - { - Id = order.Id, - WoodId = order.WoodId, - WoodName = order.WoodName, - Count = order.Count, - Sum = order.Sum, - DateCreate = order.DateCreate, - - Status = OrderStatus.Выполняется - }); - return true; - } - public bool FinishOrder(OrderBindingModel model) - { - var order = _orderStorage.GetElement(new OrderSearchModel - { - Id = model.Id - }); - if (order == null) - { - throw new Exception("Не найден заказ"); - } - if (order.Status.ToString() != "Выполняется") - { - throw new Exception("Заказ не в статусе \"Выполняется\""); - } - _orderStorage.Update(new OrderBindingModel - { - Id = order.Id, - WoodId = order.WoodId, - WoodName = order.WoodName, - Count = order.Count, - Sum = order.Sum, - DateCreate = order.DateCreate, - DateImplement = DateTime.Now, - Status = OrderStatus.Готов - }); - return true; - } - public bool DeliveryOrder(OrderBindingModel model) - { - var order = _orderStorage.GetElement(new OrderSearchModel - { - Id = model.Id - }); - if (order == null) - { - throw new Exception("Не найден заказ"); - } + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; - if (order.Status.ToString() != "Готов") - { - throw new Exception("Заказ не в статусе \"Готов\""); - } + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } - _orderStorage.Update(new OrderBindingModel - { - Id = order.Id, - WoodId = order.WoodId, - WoodName = order.WoodName, - Count = order.Count, - Sum = order.Sum, - DateCreate = order.DateCreate, - DateImplement = order.DateImplement, - Status = OrderStatus.Выдан - }); - return true; + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); - } + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } - + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model); - } + if (model.Status + 1 != newStatus) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } + + model.Status = newStatus; + + if (model.Status == OrderStatus.Выдан) + model.DateImplement = DateTime.Now; + + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool FinishOrder(OrderBindingModel model) + { + 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.WoodId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.WoodId)); + } + + 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}. WoodId: { WoodId}", model.Id, model.Sum, model.WoodId); + } + } } diff --git a/CarpentryWorkshopBusinessLogic/BusinessLogics/WoodLogic.cs b/CarpentryWorkshopBusinessLogic/BusinessLogics/WoodLogic.cs index dc5b8bd..e78c8ea 100644 --- a/CarpentryWorkshopBusinessLogic/BusinessLogics/WoodLogic.cs +++ b/CarpentryWorkshopBusinessLogic/BusinessLogics/WoodLogic.cs @@ -88,11 +88,11 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics } if (string.IsNullOrEmpty(model.WoodName)) { - throw new ArgumentNullException("Нет названия компонента", nameof(model.WoodName)); + throw new ArgumentNullException("Нет названия изделия", nameof(model.WoodName)); } if (model.Price <= 0) { - throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Price)); + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); } _logger.LogInformation("Wood. WoodName:{WoodName}. Cost:{ Cost}. Id: { Id}", model.WoodName, model.Price, model.Id); var element = _woodStorage.GetElement(new WoodSearchModel @@ -101,7 +101,7 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics }); if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Компонент с таким названием уже есть"); + throw new InvalidOperationException("Изделие с таким названием уже есть"); } } } diff --git a/CarpentryWorkshopBusinessLogic/Class1.cs b/CarpentryWorkshopBusinessLogic/Class1.cs deleted file mode 100644 index 41846ac..0000000 --- a/CarpentryWorkshopBusinessLogic/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace CarpentryWorkshopBusinessLogic -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs b/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs index 99635fc..8ce823b 100644 --- a/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -16,6 +16,5 @@ namespace CarpentryWorkshopContracts.BusinessLogicsContracts bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); bool DeliveryOrder(OrderBindingModel model); - } } diff --git a/CarpentryWorkshopContracts/Class1.cs b/CarpentryWorkshopContracts/Class1.cs deleted file mode 100644 index 26e1951..0000000 --- a/CarpentryWorkshopContracts/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace CarpentryWorkshopContracts -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/CarpentryWorkshopContracts/SearchModels/ComponentSearchModel.cs b/CarpentryWorkshopContracts/SearchModels/ComponentSearchModel.cs index d584872..d9e1fe0 100644 --- a/CarpentryWorkshopContracts/SearchModels/ComponentSearchModel.cs +++ b/CarpentryWorkshopContracts/SearchModels/ComponentSearchModel.cs @@ -11,5 +11,4 @@ namespace CarpentryWorkshopContracts.SearchModels public int? Id { get; set; } public string? ComponentName { get; set; } } - } diff --git a/CarpentryWorkshopContracts/SearchModels/WoodSearchModel.cs b/CarpentryWorkshopContracts/SearchModels/WoodSearchModel.cs index b5ac7bd..e1a1a65 100644 --- a/CarpentryWorkshopContracts/SearchModels/WoodSearchModel.cs +++ b/CarpentryWorkshopContracts/SearchModels/WoodSearchModel.cs @@ -11,5 +11,4 @@ namespace CarpentryWorkshopContracts.SearchModels public int? Id { get; set; } public string? WoodName { get; set; } } - } diff --git a/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs b/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs index 0c17489..31f15c0 100644 --- a/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs +++ b/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs @@ -16,5 +16,4 @@ namespace CarpentryWorkshopContracts.ViewModels [DisplayName("Цена")] public double Cost { get; set; } } - } diff --git a/CarpentryWorkshopDataModels/CarpentryWorkshopDataModels.csproj b/CarpentryWorkshopDataModels/CarpentryWorkshopDataModels.csproj index 132c02c..7fa6a8d 100644 --- a/CarpentryWorkshopDataModels/CarpentryWorkshopDataModels.csproj +++ b/CarpentryWorkshopDataModels/CarpentryWorkshopDataModels.csproj @@ -6,4 +6,7 @@ enable + + + diff --git a/CarpentryWorkshopDataModels/Models/IOrderModel.cs b/CarpentryWorkshopDataModels/Models/IOrderModel.cs index 7276b02..3b691f6 100644 --- a/CarpentryWorkshopDataModels/Models/IOrderModel.cs +++ b/CarpentryWorkshopDataModels/Models/IOrderModel.cs @@ -10,11 +10,7 @@ namespace CarpentryWorkshopDataModels.Models public interface IOrderModel : IId { int WoodId { get; } - string WoodName - { - get; - } - + string WoodName { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/CarpentryWorkshopFileImplement/Models/Order.cs b/CarpentryWorkshopFileImplement/Models/Order.cs index 1d03e65..a3625ba 100644 --- a/CarpentryWorkshopFileImplement/Models/Order.cs +++ b/CarpentryWorkshopFileImplement/Models/Order.cs @@ -14,14 +14,14 @@ namespace CarpentryWorkshopFileImplement.Models { public class Order : IOrderModel { - public int Id { get; set; } - public int WoodId { get; set; } - public string WoodName { get; set; } = string.Empty; - public int Count { get; set; } - public double Sum { get; set; } - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; set; } = DateTime.Now; - public DateTime? DateImplement { get; set; } + public int Id { get; private set; } + public int WoodId { get; private set; } + public string WoodName { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel model) { if (model == null) @@ -65,14 +65,7 @@ namespace CarpentryWorkshopFileImplement.Models { return; } - Id = model.Id; - WoodId = model.WoodId; - WoodName = model.WoodName; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; - DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { diff --git a/CarpentryWorkshopListImplement/Models/Order.cs b/CarpentryWorkshopListImplement/Models/Order.cs index f48279e..df34b1a 100644 --- a/CarpentryWorkshopListImplement/Models/Order.cs +++ b/CarpentryWorkshopListImplement/Models/Order.cs @@ -13,14 +13,14 @@ namespace CarpentryWorkshopListImplement.Models { public class Order : IOrderModel { - public int Id { get; set; } - public int WoodId { get; set; } - public string WoodName { get; set; } = string.Empty; - public int Count { get; set; } - public double Sum { get; set; } - public OrderStatus Status { get; set; } - public DateTime DateCreate { get; set; } - public DateTime? DateImplement { get; set; } + public int Id { get; private set; } + public int WoodId { get; private set; } + public string WoodName { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model) { if (model == null) diff --git a/CarpentryWorkshopView/CarpentryWorkshopView.csproj b/CarpentryWorkshopView/CarpentryWorkshopView.csproj index d0d744a..329c97f 100644 --- a/CarpentryWorkshopView/CarpentryWorkshopView.csproj +++ b/CarpentryWorkshopView/CarpentryWorkshopView.csproj @@ -22,5 +22,4 @@ - \ No newline at end of file diff --git a/CarpentryWorkshopView/FormComponent.Designer.cs b/CarpentryWorkshopView/FormComponent.Designer.cs index df40fe6..97566b9 100644 --- a/CarpentryWorkshopView/FormComponent.Designer.cs +++ b/CarpentryWorkshopView/FormComponent.Designer.cs @@ -100,7 +100,7 @@ this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.ButtonSave); this.Name = "FormComponent"; - this.Text = "FormComponent"; + this.Text = "Форма Компонента"; this.Load += new System.EventHandler(this.FormComponent_Load); this.ResumeLayout(false); this.PerformLayout();