diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/EquipmentReceivingLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/EquipmentReceivingLogic.cs index fffdc81..29b19e8 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/EquipmentReceivingLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/EquipmentReceivingLogic.cs @@ -52,7 +52,7 @@ namespace ComputerShopBusinessLogic.BusinessLogics return true; } - public bool TakeOrderInWork(EquipmentReceivingBindingModel model) + public bool TakeInWork(EquipmentReceivingBindingModel model) { return StatusUpdate(model, EquipmentReceivingStatus.Ожидается); } @@ -92,10 +92,5 @@ namespace ComputerShopBusinessLogic.BusinessLogics return true; } - public bool TakeInWork(EquipmentReceivingBindingModel model) - { - throw new NotImplementedException(); - } - } } diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs index 6b3ede5..a1b4325 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -18,11 +18,13 @@ namespace ComputerShopBusinessLogic.BusinessLogics private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; private readonly IAssemblyStorage _assemblyStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage, IAssemblyStorage assemblyStorage) + private readonly ISupplyStorage _supplyStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IAssemblyStorage assemblyStorage, ISupplyStorage supplyStorage) { _logger = logger; _orderStorage = orderStorage; _assemblyStorage = assemblyStorage; + _supplyStorage = supplyStorage; } public bool CreateOrder(OrderBindingModel model) { @@ -162,5 +164,6 @@ namespace ComputerShopBusinessLogic.BusinessLogics return true; } + } } diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/SupplyLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/SupplyLogic.cs index c5b2bae..6b3f7c8 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/SupplyLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/SupplyLogic.cs @@ -17,10 +17,13 @@ namespace ComputerShopBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly ISupplyStorage _supplyStorage; - public SupplyLogic(ILogger logger, ISupplyStorage supplyStorage) + private readonly IOrderStorage _orderStorage; + + public SupplyLogic(ILogger logger, ISupplyStorage supplyStorage, IOrderStorage orderStorage) { _logger = logger; _supplyStorage = supplyStorage; + _orderStorage = orderStorage; } public bool Create(SupplyBindingModel model) { @@ -112,5 +115,31 @@ namespace ComputerShopBusinessLogic.BusinessLogics } return true; } + + public bool AddOrder(SupplySearchModel supplymodel, OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var order = _orderStorage.GetElement(model); + var supply = _supplyStorage.GetElement(supplymodel); + + if (order == null || supply == null) + { + return false; + } + + order.SupplyOrders[order.Id] = order; + + _supplyStorage.Update(new() + { + Id = supply.Id, + SupplyOrders = supply.SupplyOrders, + }); + + return true; + } } } diff --git a/ComputerShopProvider/ComputerShopContracts/BindingModels/EquipmentReceivingBindingModel.cs b/ComputerShopProvider/ComputerShopContracts/BindingModels/EquipmentReceivingBindingModel.cs index 20bdd22..fd86d9d 100644 --- a/ComputerShopProvider/ComputerShopContracts/BindingModels/EquipmentReceivingBindingModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/BindingModels/EquipmentReceivingBindingModel.cs @@ -11,6 +11,7 @@ namespace ComputerShopContracts.BindingModels public class EquipmentReceivingBindingModel : IEquipmentReceivingModel { public int Id { get; set; } + public int ClientId { get; set; } public EquipmentReceivingStatus Status { get; set; } = EquipmentReceivingStatus.Неизвестен; public DateTime? DateImplement { get; set; } diff --git a/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs b/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs index cbfa824..da1fd14 100644 --- a/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs @@ -11,6 +11,8 @@ namespace ComputerShopContracts.BindingModels public class SupplyBindingModel : ISupplyModel { public int Id { get; set; } + public int ClientId { get; set; } + public int ReceivingId { get; set; } public SupplyStatus Status { get; set; } = SupplyStatus.Неизвестен; diff --git a/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/ISupplyLogic.cs b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/ISupplyLogic.cs index d54a4b0..7d2912e 100644 --- a/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/ISupplyLogic.cs +++ b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/ISupplyLogic.cs @@ -18,5 +18,6 @@ namespace ComputerShopContracts.BusinessLogicContracts bool Delete(SupplyBindingModel model); bool TakeInWork(SupplyBindingModel model); bool Finish(SupplyBindingModel model); + bool AddOrder(SupplySearchModel supplymodel, OrderSearchModel model); } } diff --git a/ComputerShopProvider/ComputerShopContracts/SearchModels/EquipmentReceivingSearchModel.cs b/ComputerShopProvider/ComputerShopContracts/SearchModels/EquipmentReceivingSearchModel.cs index 526cd2e..27d729d 100644 --- a/ComputerShopProvider/ComputerShopContracts/SearchModels/EquipmentReceivingSearchModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/SearchModels/EquipmentReceivingSearchModel.cs @@ -10,6 +10,7 @@ namespace ComputerShopContracts.SearchModels public class EquipmentReceivingSearchModel { public int? Id { get; set; } + public int? ClientId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public SupplySearchModel? Supply { get; set; } diff --git a/ComputerShopProvider/ComputerShopContracts/SearchModels/SupplySearchModel.cs b/ComputerShopProvider/ComputerShopContracts/SearchModels/SupplySearchModel.cs index 74abc66..9249ee5 100644 --- a/ComputerShopProvider/ComputerShopContracts/SearchModels/SupplySearchModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/SearchModels/SupplySearchModel.cs @@ -9,6 +9,7 @@ namespace ComputerShopContracts.SearchModels public class SupplySearchModel { public int? Id { get; set; } + public int? ClientId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public ComponentSearchModel? Component { get; set; } diff --git a/ComputerShopProvider/ComputerShopContracts/ViewModels/EquipmentReceivingViewModel.cs b/ComputerShopProvider/ComputerShopContracts/ViewModels/EquipmentReceivingViewModel.cs index d99f07b..8f0fe1f 100644 --- a/ComputerShopProvider/ComputerShopContracts/ViewModels/EquipmentReceivingViewModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/ViewModels/EquipmentReceivingViewModel.cs @@ -19,5 +19,7 @@ namespace ComputerShopContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } + [DisplayName("Номер клиента")] + public int ClientId { get; set; } } } diff --git a/ComputerShopProvider/ComputerShopContracts/ViewModels/OrderViewModel.cs b/ComputerShopProvider/ComputerShopContracts/ViewModels/OrderViewModel.cs index b852292..dd71aa4 100644 --- a/ComputerShopProvider/ComputerShopContracts/ViewModels/OrderViewModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/ViewModels/OrderViewModel.cs @@ -24,7 +24,7 @@ namespace ComputerShopContracts.ViewModels get; set; } = new(); - public Dictionary SupplyOrders + public Dictionary SupplyOrders { get; set; diff --git a/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs b/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs index ed365cb..62a7a4f 100644 --- a/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs @@ -22,6 +22,9 @@ namespace ComputerShopContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } + + [DisplayName("Номер клиента")] + public int ClientId { get; set; } [DisplayName("Номер получения")] public int ReceivingId { get; set; } public Dictionary SupplyOrders diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Assembly.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Assembly.cs index 711f131..e7b6217 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Assembly.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Assembly.cs @@ -38,20 +38,6 @@ namespace ComputerShopDatabaseImplement.Models } private Dictionary? _assemblyOrders = null; - [NotMapped] - public Dictionary AssemblyOrders - { - get - { - if (_assemblyOrders == null) - { - _assemblyOrders = Orders - .ToDictionary(recPC => recPC.OrderId, recPC => - (recPC.Order as IOrderModel, recPC.Count)); - } - return _assemblyOrders; - } - } [ForeignKey("AssemblyId")] public virtual List Components { get; set; } = new(); [ForeignKey("AssemblyId")] @@ -90,7 +76,6 @@ namespace ComputerShopDatabaseImplement.Models AssemblyName = AssemblyName, Price = Price, AssemblyComponents = AssemblyComponents, - AssemblyOrders = AssemblyOrders, ClientId = ClientId }; public void UpdateComponents(ComputerShopDatabase context, AssemblyBindingModel model) diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/EquipmentReceiving.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/EquipmentReceiving.cs index 37213b5..e5149bf 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/EquipmentReceiving.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/EquipmentReceiving.cs @@ -22,6 +22,8 @@ namespace ComputerShopDatabaseImplement.Models [ForeignKey("ReceivingId")] public List Supplies { get; set; } = new(); + [Required] + public int ClientId { get; set; } public static EquipmentReceiving? Create(EquipmentReceivingBindingModel? model) { @@ -34,6 +36,7 @@ namespace ComputerShopDatabaseImplement.Models Status = model.Status, DateImplement = model.DateImplement, Id = model.Id, + ClientId = model.ClientId }; } @@ -52,6 +55,7 @@ namespace ComputerShopDatabaseImplement.Models DateImplement = DateImplement, Id = Id, Status = Status, + ClientId = ClientId }; } } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs index fd8e607..f9a0295 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs @@ -24,8 +24,7 @@ namespace ComputerShopDatabaseImplement.Models public DateTime? DateImplement { get; private set; } [ForeignKey("OrderId")] - public virtual List Supplies { get; set; } = new(); - private Dictionary? _supplyOrders = null; + public virtual List SupplyOrders { get; set; } = new(); [ForeignKey("OrderId")] public virtual List Assemblies { get; set; } = new(); @@ -45,20 +44,6 @@ namespace ComputerShopDatabaseImplement.Models return _assemblyOrders; } } - [NotMapped] - public Dictionary SupplyOrders - { - get - { - if (_supplyOrders == null) - { - _supplyOrders = Supplies - .ToDictionary(recPC => recPC.SupplyId, recPC => - (recPC.Order as IOrderModel)); - } - return _supplyOrders; - } - } [Required] public int ClientId { get; set; } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs index 101c724..40461cc 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs @@ -24,9 +24,10 @@ namespace ComputerShopDatabaseImplement.Models public DateTime? DateImplement { get; private set; } public int OrderId { get; set; } + public int ClientId { get; set; } public int ReceivingId { get; set; } - public virtual EquipmentReceiving Receiving { get; set; } + public virtual EquipmentReceiving? Receiving { get; set; } private Dictionary? _supplyOrders = null; @@ -53,6 +54,7 @@ namespace ComputerShopDatabaseImplement.Models return new Supply { Id = model.Id, + ClientId = model.ClientId, Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, @@ -78,7 +80,8 @@ namespace ComputerShopDatabaseImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - SupplyOrders = SupplyOrders + SupplyOrders = SupplyOrders, + ClientId = ClientId }; public void UpdateOrders(ComputerShopDatabase context, SupplyBindingModel model) { diff --git a/ComputerShopProvider/ComputerShopRestApi/Controllers/EquipmentReceivingController.cs b/ComputerShopProvider/ComputerShopRestApi/Controllers/EquipmentReceivingController.cs index ae36476..c7bcaae 100644 --- a/ComputerShopProvider/ComputerShopRestApi/Controllers/EquipmentReceivingController.cs +++ b/ComputerShopProvider/ComputerShopRestApi/Controllers/EquipmentReceivingController.cs @@ -1,4 +1,8 @@ -using Microsoft.AspNetCore.Http; +using ComputerShopContracts.BindingModels; +using ComputerShopContracts.BusinessLogicContracts; +using ComputerShopContracts.SearchModels; +using ComputerShopContracts.ViewModels; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace ComputerShopRestApi.Controllers @@ -7,6 +11,55 @@ namespace ComputerShopRestApi.Controllers [ApiController] public class EquipmentReceivingController : Controller { - + private readonly ILogger _logger; + private readonly IEquipmentReceivingLogic _equipmentReceiving; + public EquipmentReceivingController(ILogger logger, IEquipmentReceivingLogic equipmentReceiving) + { + _logger = logger; + _equipmentReceiving = equipmentReceiving; + } + [HttpGet] + public List? GetReceivingList() + { + try + { + return _equipmentReceiving.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка компонентов"); + throw; + } + } + + [HttpGet] + public List? GetReceivings(int clientId) + { + try + { + return _equipmentReceiving.ReadList(new EquipmentReceivingSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка закупок клиента id ={ Id}", clientId); + throw; + } + } + [HttpPost] + public void CreateReceiving(EquipmentReceivingBindingModel model) + { + try + { + _equipmentReceiving.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания получения"); + throw; + } + } } } diff --git a/ComputerShopProvider/ComputerShopRestApi/Controllers/SupplyController.cs b/ComputerShopProvider/ComputerShopRestApi/Controllers/SupplyController.cs index 96c6c81..249a20c 100644 --- a/ComputerShopProvider/ComputerShopRestApi/Controllers/SupplyController.cs +++ b/ComputerShopProvider/ComputerShopRestApi/Controllers/SupplyController.cs @@ -14,24 +14,36 @@ namespace ComputerShopRestApi.Controllers private readonly ILogger _logger; private readonly ISupplyLogic _supply; private readonly IOrderLogic _order; - public SupplyController(ILogger logger, ISupplyLogic supply, IOrderLogic order) + private readonly IEquipmentReceivingLogic _equipmentReceiving; + + public SupplyController(ILogger logger, ISupplyLogic supply, IOrderLogic order, IEquipmentReceivingLogic equipmentReceiving) { _logger = logger; _supply = supply; _order = order; + _equipmentReceiving = equipmentReceiving; } - /* - [HttpGet] - public List? GetAssemblyList(int clientId) + public List? GetReceivingList() { try { - return _supply.ReadList(new SupplySearchModel - { + return _equipmentReceiving.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка компонентов"); + throw; + } + } - }); + [HttpGet] + public List? GetSupplyList(int componentid) + { + try + { + return _supply.ReadList(new SupplySearchModel { ComponentId = componentid }); } catch (Exception ex) { @@ -41,91 +53,72 @@ namespace ComputerShopRestApi.Controllers } [HttpGet] - public Tuple>>? GetAssembly(int assemblyId) + public List? GetOrderList() { try { - var elem = _supply.ReadElement(new SupplySearchModel { Id = assemblyId }); - if (elem == null) - return null; - return Tuple.Create(elem, elem.AssemblyComponents.Select(x => Tuple.Create(x.Value.Item1.ComponentName, x.Value.Item2)).ToList()); + return _order.ReadList(null); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения сборки по id={Id}", assemblyId); - throw; - } - } - - [HttpGet] - public List? GetComponentList() - { - try - { - return _component.ReadList(null); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка компонентов"); + _logger.LogError(ex, "Ошибка получения списка заказов"); throw; } } [HttpPost] - public void CreateAssembly(AssemblyBindingModel model) + public void CreateAssembly(SupplyBindingModel model) { try { - _assembly.Create(model); + _supply.Create(model); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка создания сборки"); + _logger.LogError(ex, "Ошибка создания поставки"); throw; } } [HttpPost] - public void DeleteAssembly(AssemblyBindingModel model) + public void DeleteSupply(SupplyBindingModel model) { try { - _assembly.Delete(model); + _supply.Delete(model); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления сборки"); + _logger.LogError(ex, "Ошибка удаления поставки"); throw; } } [HttpPost] - public void AddComponentToAssembly(Tuple model) + public void AddOrderToSupply(Tuple model) { try { - _assembly.AddComponentToAssembly(model.Item1, model.Item2, model.Item3); + _supply.AddOrder(model.Item1, model.Item2); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка добавления компонента в сборку."); + _logger.LogError(ex, "Ошибка."); throw; } } [HttpPost] - public void EditAssembly(AssemblyBindingModel model) + public void EditOrder(OrderBindingModel model) { try { - _assembly.Update(model); + _order.Update(model); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления сборки"); + _logger.LogError(ex, "Ошибка удаления заказа"); throw; } } - */ - } }