diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj index b363b98..8844615 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj @@ -8,6 +8,12 @@ enable + + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs index 4295273..c988e63 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs @@ -46,7 +46,7 @@ namespace BlacksmithWorkshop { int id = Convert.ToInt32(comboBoxManufacture.SelectedValue); - var manufacture = _logicA.ReadManufacture(new ManufactureSearchModel + var manufacture = _logicA.ReadElement(new ManufactureSearchModel { Id = id }); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs index af32e51..70119b1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs @@ -44,7 +44,7 @@ namespace BlacksmithWorkshop try { - var view = _logic.ReadManufacture(new ManufactureSearchModel { Id = _id.Value }); + var view = _logic.ReadElement(new ManufactureSearchModel { Id = _id.Value }); if(view != null) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 8f7a4c9..f0537ce 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -49,6 +49,7 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ManufactureLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ManufactureLogic.cs index 84a3287..78b61a1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ManufactureLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ManufactureLogic.cs @@ -19,10 +19,10 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic private readonly IManufactureStorage _manufactureStorage; //конструктор - public ManufactureLogic(ILogger logger, IManufactureStorage productStorage) + public ManufactureLogic(ILogger logger, IManufactureStorage manufactureStorage) { _logger = logger; - _manufactureStorage = productStorage; + _manufactureStorage = manufactureStorage; } //вывод отфильтрованного списка @@ -36,6 +36,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic if(list == null) { _logger.LogWarning("ReadList return null list"); + return null; } @@ -45,24 +46,25 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic } //вывод конкретного изделия - public ManufactureViewModel? ReadManufacture(ManufactureSearchModel model) + public ManufactureViewModel? ReadElement(ManufactureSearchModel model) { if(model == null) { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadManufacture. ManufactureName:{ManufactureName}. Id:{Id}", model.ManufactureName, model.Id); + _logger.LogInformation("ReadElement. ManufactureName:{ManufactureName}. Id:{Id}", model.ManufactureName, model.Id); var element = _manufactureStorage.GetElement(model); if(element == null) { - _logger.LogWarning("ReadManufacture element not found"); + _logger.LogWarning("ReadElement element not found"); + return null; } - _logger.LogInformation("ReadManufacture find. Id:{Id}", model.Id); + _logger.LogInformation("ReadElement find. Id:{Id}", model.Id); return element; } @@ -75,6 +77,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic if(_manufactureStorage.Insert(model) == null) { _logger.LogWarning("Create operation failed"); + return false; } @@ -98,11 +101,14 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic //удаление изделия public bool Delete(ManufactureBindingModel model) { - CheckModel(model); + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); if(_manufactureStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); + return false; } @@ -117,7 +123,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(model)); } - //если без параметров? + //так как при удалении параметром withParams передаём false if (!withParams) { return; @@ -144,6 +150,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic ManufactureName = model.ManufactureName, }); + //если элемент найден и его Id не совпадает с Id объекта, переданного на вход if(element != null && element.Id != model.Id) { throw new InvalidOperationException("Изделие с таким названием уже есть"); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs index 3bf131f..d1b08bb 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -37,6 +37,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic if(list == null) { _logger.LogWarning("ReadList return null list"); + return null; } @@ -91,8 +92,8 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(model)); } - //если без параметров? - if(!withParams) + //так как при удалении параметром withParams передаём false + if (!withParams) { return; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs index 30bcbaf..d9dd9b8 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopBusinessLogic.BusinessLogic { - //класс, реализующий логику для компонентов + //класс, реализующий логику для заготовок public class WorkPieceLogic : IWorkPieceLogic { private readonly ILogger _logger; @@ -60,6 +60,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic if(element == null) { _logger.LogWarning("ReadElement element not found"); + return null; } @@ -76,6 +77,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic if(_workPieceStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); + return false; } @@ -90,6 +92,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic if(_workPieceStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); + return false; } @@ -99,11 +102,14 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic //удаление заготовки public bool Delete(WorkPieceBindingModel model) { - CheckModel(model); + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); if (_workPieceStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); + return false; } @@ -118,7 +124,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(model)); } - //если без параметров? + //так как при удалении передаём как параметр false if (!withParams) { return; @@ -144,6 +150,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic WorkPieceName = model.WorkPieceName, }); + //если элемент найден и его Id не совпадает с Id переданного объекта if(element != null && element.Id != model.Id) { throw new InvalidOperationException("Заготовка с таким названием уже есть"); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs index 84ed77d..73ad4bd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopContracts.BindingModels { - //реализация сущности "Продукт" + //реализация сущности "Изделие" public class ManufactureBindingModel : IManufactureModel { public int Id { get; set; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/WorkPieceBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/WorkPieceBindingModel.cs index 68b53da..bbb7056 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/WorkPieceBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/WorkPieceBindingModel.cs @@ -12,8 +12,8 @@ namespace BlacksmithWorkshopContracts.BindingModels { public int Id { get; set; } - public double Cost { get; set; } - public string WorkPieceName { get; set; } = string.Empty; + + public double Cost { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs index 43b6b6e..b607c8d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs @@ -14,7 +14,7 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts { List? ReadList(ManufactureSearchModel? model); - ManufactureViewModel? ReadManufacture(ManufactureSearchModel model); + ManufactureViewModel? ReadElement(ManufactureSearchModel model); bool Create(ManufactureBindingModel model); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index 2101bed..c7a3f78 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -27,10 +27,10 @@ namespace BlacksmithWorkshopContracts.ViewModels public double Sum { get; set; } [DisplayName("Статус")] - public OrderStatus Status { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } + public DateTime DateCreate { get; set; } = DateTime.Now; [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; }