diff --git a/AutomobilePlant/AbstractAutoBusinessLogic/AutomobilePlantBusinessLogic.csproj b/AutomobilePlant/AbstractAutoBusinessLogic/AutomobilePlantBusinessLogic.csproj new file mode 100644 index 0000000..37dc43e --- /dev/null +++ b/AutomobilePlant/AbstractAutoBusinessLogic/AutomobilePlantBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ComponentLogic.cs b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..134b061 --- /dev/null +++ b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,114 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace AutomobilePlantBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage + componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() :_componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента",nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/OrderLogic.cs b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..e0d5a04 --- /dev/null +++ b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,132 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantBusinessLogic.BusinessLogics +{ + + public class OrderLogic : IOrderLogic + { + 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.Неизвестен) + { + _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 DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public bool TakeOrderInWork(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.Id < 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.Id)); + } + + 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}. WorkId: { WorkId}", model.Id, model.Sum, model.Id); + } + } +} diff --git a/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ProductLogic.cs b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ProductLogic.cs new file mode 100644 index 0000000..29fc773 --- /dev/null +++ b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ProductLogic.cs @@ -0,0 +1,113 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModel; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantBusinessLogic.BusinessLogics +{ + public class ProductLogic : IProductLogic + { + private readonly ILogger _logger; + private readonly IProductStorage _productStorage; + public ProductLogic(ILogger logger, IProductStorage productStorage) + { + _logger = logger; + _productStorage = productStorage; + } + public List? ReadList(ProductSearchModel? model) + { + _logger.LogInformation("ReadList. ProductName:{ProductName}.Id:{ Id}", model?.ProductName, model?.Id); + var list = model == null ? _productStorage.GetFullList() : _productStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ProductViewModel? ReadElement(ProductSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ProductName:{ProductName}. Id:{ Id}", model.ProductName, model.Id); + var element = _productStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ProductBindingModel model) + { + CheckModel(model); + if (_productStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ProductBindingModel model) + { + CheckModel(model); + if (_productStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ProductBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_productStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ProductBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ProductName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.ProductName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Product. ProductName:{ProductName}.Cost:{ Cost}. Id: { Id}", model.ProductName, model.Price, model.Id); + var element = _productStorage.GetElement(new ProductSearchModel + { + ProductName = model.ProductName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/AutomobilePlant/AbstractAutoContracts/AbstractAutoContracts.csproj b/AutomobilePlant/AbstractAutoContracts/AutomobilePlantContracts.csproj similarity index 71% rename from AutomobilePlant/AbstractAutoContracts/AbstractAutoContracts.csproj rename to AutomobilePlant/AbstractAutoContracts/AutomobilePlantContracts.csproj index 81d9b57..940430a 100644 --- a/AutomobilePlant/AbstractAutoContracts/AbstractAutoContracts.csproj +++ b/AutomobilePlant/AbstractAutoContracts/AutomobilePlantContracts.csproj @@ -7,7 +7,7 @@ - + diff --git a/AutomobilePlant/AbstractAutoContracts/BindingModels/ComponentBindingModel.cs b/AutomobilePlant/AbstractAutoContracts/BindingModels/ComponentBindingModel.cs index 6026680..3c76c66 100644 --- a/AutomobilePlant/AbstractAutoContracts/BindingModels/ComponentBindingModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/BindingModels/ComponentBindingModel.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using AbstractAutoDataModels.Models; +using AutomobilePlantDataModels.Models; -namespace AbstractAutoContracts.BindingModels +namespace AutomobilePlantContracts.BindingModels { public class ComponentBindingModel : IComponentModel { diff --git a/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs b/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs index 972ddc7..1b7d314 100644 --- a/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/BindingModels/OrderBindingModel.cs @@ -3,15 +3,16 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using AbstractAutoDataModels.Enums; -using AbstractAutoDataModels.Models; +using AutomobilePlantDataModels.Enums; +using AutomobilePlantDataModels.Models; -namespace AbstractAutoContracts.BindingModels +namespace AutomobilePlantContracts.BindingModels { public class OrderBindingModel : IOrderModel { public int Id { get; set; } public int ProductId { get; set; } + public string ProductName { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs b/AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs index b9b8775..b0d0949 100644 --- a/AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/BindingModels/ProductBindingModel.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using AbstractAutoDataModels.Models; +using AutomobilePlantDataModels.Models; -namespace AbstractAutoContracts.BindingModels +namespace AutomobilePlantContracts.BindingModels { public class ProductBindingModel : IProductModel { diff --git a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IComponentLogic.cs b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IComponentLogic.cs index 7889ced..887da15 100644 --- a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IComponentLogic.cs +++ b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -1,13 +1,13 @@ -using AbstractAutoContracts.BindingModels; -using AbstractAutoContracts.SearchModel; -using AbstractAutoContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.BusinessLogicsContracts +namespace AutomobilePlantContracts.BusinessLogicsContracts { public interface IComponentLogic { diff --git a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IOrderLogic.cs b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IOrderLogic.cs index 6d2e59d..60238ac 100644 --- a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -1,13 +1,13 @@ -using AbstractAutoContracts.BindingModels; -using AbstractAutoContracts.SearchModel; -using AbstractAutoContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.BusinessLogicsContracts +namespace AutomobilePlantContracts.BusinessLogicsContracts { public interface IOrderLogic { diff --git a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs index d420044..8e3cfd8 100644 --- a/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs +++ b/AutomobilePlant/AbstractAutoContracts/BusinessLogicsContracts/IProductLogic.cs @@ -1,13 +1,13 @@ -using AbstractAutoContracts.BindingModels; -using AbstractAutoContracts.SearchModel; -using AbstractAutoContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.BusinessLogicsContracts +namespace AutomobilePlantContracts.BusinessLogicsContracts { public interface IProductLogic { diff --git a/AutomobilePlant/AbstractAutoContracts/SearchModel/ComponentSearchModel.cs b/AutomobilePlant/AbstractAutoContracts/SearchModel/ComponentSearchModel.cs index 9ffed3e..203914a 100644 --- a/AutomobilePlant/AbstractAutoContracts/SearchModel/ComponentSearchModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/SearchModel/ComponentSearchModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.SearchModel +namespace AutomobilePlantContracts.SearchModel { public class ComponentSearchModel { diff --git a/AutomobilePlant/AbstractAutoContracts/SearchModel/OrderSearchModel.cs b/AutomobilePlant/AbstractAutoContracts/SearchModel/OrderSearchModel.cs index 187982f..de416ba 100644 --- a/AutomobilePlant/AbstractAutoContracts/SearchModel/OrderSearchModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/SearchModel/OrderSearchModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.SearchModel +namespace AutomobilePlantContracts.SearchModel { public class OrderSearchModel { diff --git a/AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs b/AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs index 7470ad4..5ca3dbe 100644 --- a/AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/SearchModel/ProductSearchModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.SearchModel +namespace AutomobilePlantContracts.SearchModel { public class ProductSearchModel { diff --git a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IComponentStorage.cs b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IComponentStorage.cs index 9cdbd2a..24f1fec 100644 --- a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IComponentStorage.cs +++ b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IComponentStorage.cs @@ -1,13 +1,13 @@ -using AbstractAutoContracts.BindingModels; -using AbstractAutoContracts.SearchModel; -using AbstractAutoContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.StoragesContracts +namespace AutomobilePlantContracts.StoragesContracts { public interface IComponentStorage { diff --git a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IOrderStorage.cs b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IOrderStorage.cs index 509c8a0..344332f 100644 --- a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IOrderStorage.cs +++ b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IOrderStorage.cs @@ -1,13 +1,13 @@ -using AbstractAutoContracts.BindingModels; -using AbstractAutoContracts.SearchModel; -using AbstractAutoContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.StoragesContracts +namespace AutomobilePlantContracts.StoragesContracts { public interface IOrderStorage { diff --git a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs index fc380f5..08c58e0 100644 --- a/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs +++ b/AutomobilePlant/AbstractAutoContracts/StoragesContracts/IProductStorage.cs @@ -1,13 +1,13 @@ -using AbstractAutoContracts.BindingModels; -using AbstractAutoContracts.SearchModel; -using AbstractAutoContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoContracts.StoragesContracts +namespace AutomobilePlantContracts.StoragesContracts { public interface IProductStorage { diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs index 2f1db18..efaeb1b 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/ComponentViewModel.cs @@ -1,11 +1,11 @@ -using AbstractAutoDataModels.Models; +using AutomobilePlantDataModels.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; -namespace AbstractAutoContracts.ViewModel +namespace AutomobilePlantContracts.ViewModel { public class ComponentViewModel : IComponentModel { diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs index 8d8fdfb..98cd8cc 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/OrderViewModel.cs @@ -1,13 +1,13 @@ -using AbstractAutoDataModels.Models; +using AutomobilePlantDataModels.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; -using AbstractAutoDataModels.Enums; +using AutomobilePlantDataModels.Enums; -namespace AbstractAutoContracts.ViewModel +namespace AutomobilePlantContracts.ViewModel { public class OrderViewModel : IOrderModel { diff --git a/AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs b/AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs index 74f846e..642b457 100644 --- a/AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs +++ b/AutomobilePlant/AbstractAutoContracts/ViewModel/ProductViewModel.cs @@ -1,11 +1,11 @@ -using AbstractAutoDataModels.Models; +using AutomobilePlantDataModels.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; -namespace AbstractAutoContracts.ViewModel +namespace AutomobilePlantContracts.ViewModel { public class ProductViewModel : IProductModel { diff --git a/AutomobilePlant/AbstractAutoDataModels/AbstractAutoDataModels.csproj b/AutomobilePlant/AbstractAutoDataModels/AutomobilePlantDataModels.csproj similarity index 100% rename from AutomobilePlant/AbstractAutoDataModels/AbstractAutoDataModels.csproj rename to AutomobilePlant/AbstractAutoDataModels/AutomobilePlantDataModels.csproj diff --git a/AutomobilePlant/AbstractAutoDataModels/Enums/OrderStatus.cs b/AutomobilePlant/AbstractAutoDataModels/Enums/OrderStatus.cs index 7a041e7..f560e42 100644 --- a/AutomobilePlant/AbstractAutoDataModels/Enums/OrderStatus.cs +++ b/AutomobilePlant/AbstractAutoDataModels/Enums/OrderStatus.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoDataModels.Enums +namespace AutomobilePlantDataModels.Enums { public enum OrderStatus { diff --git a/AutomobilePlant/AbstractAutoDataModels/IId.cs b/AutomobilePlant/AbstractAutoDataModels/IId.cs index d871603..1dd266c 100644 --- a/AutomobilePlant/AbstractAutoDataModels/IId.cs +++ b/AutomobilePlant/AbstractAutoDataModels/IId.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoDataModels +namespace AutomobilePlantDataModels { public interface IId { diff --git a/AutomobilePlant/AbstractAutoDataModels/Models/IComponentModel.cs b/AutomobilePlant/AbstractAutoDataModels/Models/IComponentModel.cs index 50c14e0..65039ce 100644 --- a/AutomobilePlant/AbstractAutoDataModels/Models/IComponentModel.cs +++ b/AutomobilePlant/AbstractAutoDataModels/Models/IComponentModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoDataModels.Models +namespace AutomobilePlantDataModels.Models { public interface IComponentModel : IId { diff --git a/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs b/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs index 8902035..b60da02 100644 --- a/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs +++ b/AutomobilePlant/AbstractAutoDataModels/Models/IOrderModel.cs @@ -1,15 +1,16 @@ -using AbstractAutoDataModels.Enums; +using AutomobilePlantDataModels.Enums; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoDataModels.Models +namespace AutomobilePlantDataModels.Models { public interface IOrderModel : IId { int ProductId { get; } + string ProductName { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs b/AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs index 2875b48..a061105 100644 --- a/AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs +++ b/AutomobilePlant/AbstractAutoDataModels/Models/IProductModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractAutoDataModels.Models +namespace AutomobilePlantDataModels.Models { public interface IProductModel : IId { diff --git a/AutomobilePlant/AbstractAutoListImplement/AutomobilePlantListImplement.csproj b/AutomobilePlant/AbstractAutoListImplement/AutomobilePlantListImplement.csproj new file mode 100644 index 0000000..43870e5 --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/AutomobilePlantListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/AutomobilePlant/AbstractAutoListImplement/DataListSingleton.cs b/AutomobilePlant/AbstractAutoListImplement/DataListSingleton.cs new file mode 100644 index 0000000..1b50c69 --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using AutomobilePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Products { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Products = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/AutomobilePlant/AbstractAutoListImplement/Implements/ComponentStorage.cs b/AutomobilePlant/AbstractAutoListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..e895b67 --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,108 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/AutomobilePlant/AbstractAutoListImplement/Implements/OrderStorage.cs b/AutomobilePlant/AbstractAutoListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..d285c75 --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/Implements/OrderStorage.cs @@ -0,0 +1,124 @@ +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + + if (!model.Id.HasValue) + { + return result; + } + + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + + return result; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + } + + return null; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + + _source.Orders.Add(newOrder); + + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/AutomobilePlant/AbstractAutoListImplement/Implements/ProductStorage.cs b/AutomobilePlant/AbstractAutoListImplement/Implements/ProductStorage.cs new file mode 100644 index 0000000..b748f67 --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/Implements/ProductStorage.cs @@ -0,0 +1,126 @@ +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Implements +{ + public class ProductStorage : IProductStorage + { + private readonly DataListSingleton _source; + + public ProductStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + + foreach (var product in _source.Products) + { + result.Add(product.GetViewModel); + } + + return result; + } + + public List GetFilteredList(ProductSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.ProductName)) + { + return result; + } + + foreach (var product in _source.Products) + { + if (product.ProductName.Contains(model.ProductName)) + { + result.Add(product.GetViewModel); + } + } + + return result; + } + + public ProductViewModel? GetElement(ProductSearchModel model) + { + if (string.IsNullOrEmpty(model.ProductName) && !model.Id.HasValue) + { + return null; + } + + foreach (var product in _source.Products) + { + if ((!string.IsNullOrEmpty(model.ProductName) && product.ProductName == model.ProductName) || (model.Id.HasValue && product.Id == model.Id)) + { + return product.GetViewModel; + } + } + + return null; + } + + public ProductViewModel? Insert(ProductBindingModel model) + { + model.Id = 1; + + foreach (var product in _source.Products) + { + if (model.Id <= product.Id) + { + model.Id = product.Id + 1; + } + } + + var newProduct = Product.Create(model); + + if (newProduct == null) + { + return null; + } + + _source.Products.Add(newProduct); + + return newProduct.GetViewModel; + } + + public ProductViewModel? Update(ProductBindingModel model) + { + foreach (var product in _source.Products) + { + if (product.Id == model.Id) + { + product.Update(model); + return product.GetViewModel; + } + } + + return null; + } + + public ProductViewModel? Delete(ProductBindingModel model) + { + for (int i = 0; i < _source.Products.Count; ++i) + { + if (_source.Products[i].Id == model.Id) + { + var element = _source.Products[i]; + _source.Products.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/AutomobilePlant/AbstractAutoListImplement/Models/Component.cs b/AutomobilePlant/AbstractAutoListImplement/Models/Component.cs new file mode 100644 index 0000000..c194758 --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/Models/Component.cs @@ -0,0 +1,46 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/AutomobilePlant/AbstractAutoListImplement/Models/Order.cs b/AutomobilePlant/AbstractAutoListImplement/Models/Order.cs new file mode 100644 index 0000000..d4649ed --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/Models/Order.cs @@ -0,0 +1,70 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantDataModels.Enums; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int ProductId { get; private set; } + public string ProductName { 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) + { + return null; + } + return new Order() + { + Id = model.Id, + ProductId = model.ProductId, + ProductName = model.ProductName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + ProductId = model.ProductId; + ProductName = model.ProductName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + ProductId = ProductId, + ProductName = ProductName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} diff --git a/AutomobilePlant/AbstractAutoListImplement/Models/Product.cs b/AutomobilePlant/AbstractAutoListImplement/Models/Product.cs new file mode 100644 index 0000000..06c9cde --- /dev/null +++ b/AutomobilePlant/AbstractAutoListImplement/Models/Product.cs @@ -0,0 +1,55 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.ViewModel; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Models +{ + public class Product : IProductModel + { + public int Id { get; private set; } + public string ProductName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary ProductComponents + { + get; + private set; + } = new Dictionary(); + public static Product? Create(ProductBindingModel? model) + { + if (model == null) + { + return null; + } + return new Product() + { + Id = model.Id, + ProductName = model.ProductName, + Price = model.Price, + ProductComponents = model.ProductComponents + }; + } + public void Update(ProductBindingModel? model) + { + if (model == null) + { + return; + } + ProductName = model.ProductName; + Price = model.Price; + ProductComponents = model.ProductComponents; + } + public ProductViewModel GetViewModel => new() + { + Id = Id, + ProductName = ProductName, + Price = Price, + ProductComponents = ProductComponents + }; + + } +} diff --git a/AutomobilePlant/AutomobilePlant.sln b/AutomobilePlant/AutomobilePlant.sln index f7bdc84..1642a09 100644 --- a/AutomobilePlant/AutomobilePlant.sln +++ b/AutomobilePlant/AutomobilePlant.sln @@ -5,9 +5,13 @@ VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlant", "AutomobilePlant\AutomobilePlant.csproj", "{2A499DE6-B7DE-4A28-9906-12FC100451F0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractAutoDataModels", "AbstractAutoDataModels\AbstractAutoDataModels.csproj", "{DD7B0E1A-2EE9-441A-87C3-03AC0421746E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantDataModels", "AbstractAutoDataModels\AutomobilePlantDataModels.csproj", "{DD7B0E1A-2EE9-441A-87C3-03AC0421746E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractAutoContracts", "AbstractAutoContracts\AbstractAutoContracts.csproj", "{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomobilePlantContracts", "AbstractAutoContracts\AutomobilePlantContracts.csproj", "{4B515980-8AD9-48F3-886E-3C2A6B1E9D90}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantBusinessLogic", "AbstractAutoBusinessLogic\AutomobilePlantBusinessLogic.csproj", "{D57C726F-E5B4-4CB3-A754-D5F93295CE1E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantListImplement", "AbstractAutoListImplement\AutomobilePlantListImplement.csproj", "{305978E5-BFB5-47B0-94C9-2C5D06748BD6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,6 +31,14 @@ Global {4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Debug|Any CPU.Build.0 = Debug|Any CPU {4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Release|Any CPU.ActiveCfg = Release|Any CPU {4B515980-8AD9-48F3-886E-3C2A6B1E9D90}.Release|Any CPU.Build.0 = Release|Any CPU + {D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D57C726F-E5B4-4CB3-A754-D5F93295CE1E}.Release|Any CPU.Build.0 = Release|Any CPU + {305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {305978E5-BFB5-47B0-94C9-2C5D06748BD6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE