From 3ba667323dc653595f880bf7677a93f77fbc1ee7 Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Sat, 20 May 2023 00:08:47 +0400 Subject: [PATCH] Models & Logic fix --- .../BusinessLogics/EquipmentReceivingLogic.cs | 79 ++++++++- .../BusinessLogics/OrderLogic.cs | 163 +++++++++++++++--- .../BusinessLogics/SupplyLogic.cs | 100 ++++++++--- .../BindingModels/OrderBindingModel.cs | 11 ++ .../BindingModels/SupplyBindingModel.cs | 5 +- .../IEquipmentReceivingLogic.cs | 7 +- .../BusinessLogicContracts/IOrderLogic.cs | 6 +- .../BusinessLogicContracts/ISupplyLogic.cs | 6 +- .../ViewModels/OrderViewModel.cs | 14 ++ .../ViewModels/SupplyViewModel.cs | 13 +- .../Models/ISupplyModel.cs | 3 +- .../Implements/PurchaseStorage.cs | 6 +- .../Implements/SupplyStorage.cs | 6 +- .../Models/Order.cs | 38 +++- .../Models/Supply.cs | 3 + 15 files changed, 375 insertions(+), 85 deletions(-) diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/EquipmentReceivingLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/EquipmentReceivingLogic.cs index 1b67b1d..fffdc81 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/EquipmentReceivingLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/EquipmentReceivingLogic.cs @@ -1,7 +1,10 @@ using ComputerShopContracts.BindingModels; using ComputerShopContracts.BusinessLogicContracts; using ComputerShopContracts.SearchModels; +using ComputerShopContracts.StorageContracts; using ComputerShopContracts.ViewModels; +using ComputerShopDataModels.Enums; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; @@ -12,29 +15,87 @@ namespace ComputerShopBusinessLogic.BusinessLogics { public class EquipmentReceivingLogic : IEquipmentReceivingLogic { + private readonly ILogger _logger; + private readonly IEquipmentReceivingStorage _receivingStorage; + + public EquipmentReceivingLogic(ILogger logger, IEquipmentReceivingStorage receivingStorage) + { + _logger = logger; + _receivingStorage = receivingStorage; + } public List? ReadList(EquipmentReceivingSearchModel? model) { - throw new NotImplementedException(); + var list = model == null ? _receivingStorage.GetFullList() : _receivingStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + return list; } - public bool CreateOrder(EquipmentReceivingBindingModel model) + public bool Create(EquipmentReceivingBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (model.Status != EquipmentReceivingStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Receiving status incorrect."); + return false; + } + model.Status = EquipmentReceivingStatus.Ожидается; + if (_receivingStorage.Insert(model) == null) + { + model.Status = EquipmentReceivingStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; } public bool TakeOrderInWork(EquipmentReceivingBindingModel model) { - throw new NotImplementedException(); + return StatusUpdate(model, EquipmentReceivingStatus.Ожидается); } - public bool FinishOrder(EquipmentReceivingBindingModel model) + public bool Finish(EquipmentReceivingBindingModel model) + { + return StatusUpdate(model, EquipmentReceivingStatus.Получено); + } + + private void CheckModel(EquipmentReceivingBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + } + public bool StatusUpdate(EquipmentReceivingBindingModel model, EquipmentReceivingStatus 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 == EquipmentReceivingStatus.Получено) model.DateImplement = DateTime.Now; + if (_receivingStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool TakeInWork(EquipmentReceivingBindingModel model) { throw new NotImplementedException(); } - public bool DeliveryOrder(EquipmentReceivingBindingModel model) - { - throw new NotImplementedException(); - } } } diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs index 56ecd65..6b3ede5 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -1,7 +1,10 @@ using ComputerShopContracts.BindingModels; using ComputerShopContracts.BusinessLogicContracts; using ComputerShopContracts.SearchModels; +using ComputerShopContracts.StorageContracts; using ComputerShopContracts.ViewModels; +using ComputerShopDataModels.Enums; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; @@ -12,44 +15,152 @@ namespace ComputerShopBusinessLogic.BusinessLogics { public class OrderLogic : IOrderLogic { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + private readonly IAssemblyStorage _assemblyStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IAssemblyStorage assemblyStorage) + { + _logger = logger; + _orderStorage = orderStorage; + _assemblyStorage = assemblyStorage; + } public bool CreateOrder(OrderBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; } - - public bool Delete(ComponentBindingModel model) - { - throw new NotImplementedException(); - } - - public bool DeliveryOrder(OrderBindingModel model) - { - throw new NotImplementedException(); - } - - public bool FinishOrder(OrderBindingModel model) - { - throw new NotImplementedException(); - } - - public OrderViewModel? ReadElement(OrderSearchModel model) - { - throw new NotImplementedException(); - } - public List? ReadList(OrderSearchModel? model) { - throw new NotImplementedException(); + _logger.LogInformation("ReadList. 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 Update(OrderBindingModel model) + { + CheckModel(model); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(OrderBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_orderStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; } public bool TakeOrderInWork(OrderBindingModel model) { - throw new NotImplementedException(); + return StatusUpdate(model, OrderStatus.Выполняется); } - public bool Update(ComponentBindingModel model) + public bool DeliveryOrder(OrderBindingModel model) { - throw new NotImplementedException(); + return StatusUpdate(model, OrderStatus.Выдан); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool StatusUpdate(OrderBindingModel model, OrderStatus _newStatus) + { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.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; + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model, false); + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.ClientId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор у клиента", nameof(model.ClientId)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. OrderID:{Id}. Sum:{ Sum}. ClientId: { ClientId}", model.Id, model.Sum, model.ClientId); + } + + public bool AddAssembly(OrderSearchModel model, AssemblySearchModel assemblymodel, int amount) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("AddAssemblyToOrder. AssemblyName:{AssemblyName}.Id:{ Id}", assemblymodel.AssemblyName, model.Id); + var element = _orderStorage.GetElement(model); + var assembly = _assemblyStorage.GetElement(assemblymodel); + + if (element == null || assembly == null) + { + return false; + } + + _logger.LogInformation("AddAssemblyToOrder find. Id:{Id}", element.Id); + + element.AssemblyOrders[assembly.Id] = (assembly, amount); + + _orderStorage.Update(new() + { + Id = element.Id, + Status = element.Status, + Sum = element.Sum + assembly.Price * amount, + ClientId = element.ClientId, + AssemblyOrders = element.AssemblyOrders + }); + + return true; } } } diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/SupplyLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/SupplyLogic.cs index e18be6d..c5b2bae 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/SupplyLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/SupplyLogic.cs @@ -1,7 +1,10 @@ using ComputerShopContracts.BindingModels; using ComputerShopContracts.BusinessLogicContracts; using ComputerShopContracts.SearchModels; +using ComputerShopContracts.StorageContracts; using ComputerShopContracts.ViewModels; +using ComputerShopDataModels.Enums; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; @@ -12,29 +15,33 @@ namespace ComputerShopBusinessLogic.BusinessLogics { public class SupplyLogic : ISupplyLogic { + private readonly ILogger _logger; + private readonly ISupplyStorage _supplyStorage; + public SupplyLogic(ILogger logger, ISupplyStorage supplyStorage) + { + _logger = logger; + _supplyStorage = supplyStorage; + } public bool Create(SupplyBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (_supplyStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; } - - public bool CreateOrder(PurchaseBindingModel model) - { - throw new NotImplementedException(); - } - public bool Delete(SupplyBindingModel model) { - throw new NotImplementedException(); - } - - public bool DeliveryOrder(PurchaseBindingModel model) - { - throw new NotImplementedException(); - } - - public bool FinishOrder(PurchaseBindingModel model) - { - throw new NotImplementedException(); + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_supplyStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; } public SupplyViewModel? ReadElement(SupplySearchModel model) @@ -44,17 +51,66 @@ namespace ComputerShopBusinessLogic.BusinessLogics public List? ReadList(SupplySearchModel? model) { - throw new NotImplementedException(); + _logger.LogInformation("ReadList. Supplyid:{ Id}", model?.Id); + var list = model == null ? _supplyStorage.GetFullList() : _supplyStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; } - public bool TakeOrderInWork(PurchaseBindingModel model) + public bool TakeInWork(SupplyBindingModel model) { - throw new NotImplementedException(); + return StatusUpdate(model, SupplyStatus.Отправляется); + } + public bool Finish(SupplyBindingModel model) + { + return StatusUpdate(model, SupplyStatus.Отправлено); } - public bool Update(SupplyBindingModel model) { throw new NotImplementedException(); } + private void CheckModel(SupplyBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + } + public bool StatusUpdate(SupplyBindingModel model, SupplyStatus _newStatus) + { + var viewModel = _supplyStorage.GetElement(new SupplySearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != _newStatus) + { + _logger.LogWarning("Status update to " + _newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } + model.Status = _newStatus; + if (model.Status == SupplyStatus.Отправлено) model.DateImplement = DateTime.Now; + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model, false); + if (_supplyStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } } } diff --git a/ComputerShopProvider/ComputerShopContracts/BindingModels/OrderBindingModel.cs b/ComputerShopProvider/ComputerShopContracts/BindingModels/OrderBindingModel.cs index cb46307..61d13dd 100644 --- a/ComputerShopProvider/ComputerShopContracts/BindingModels/OrderBindingModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/BindingModels/OrderBindingModel.cs @@ -18,6 +18,17 @@ namespace ComputerShopContracts.BindingModels public DateTime DateCreate { get; set; } public DateTime? DateImplement { get; set; } = DateTime.Now; + public int ClientId { get; set; } + public Dictionary AssemblyOrders + { + get; + set; + } = new(); + public Dictionary SupplyOrders + { + get; + set; + } = new(); } } diff --git a/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs b/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs index 8caef6b..cbfa824 100644 --- a/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs @@ -11,12 +11,13 @@ namespace ComputerShopContracts.BindingModels public class SupplyBindingModel : ISupplyModel { public int Id { get; set; } + public int ReceivingId { get; set; } public SupplyStatus Status { get; set; } = SupplyStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; - public DateTime? DateImplement { get; set; } - + public DateTime? DateImplement { get; set; } + public Dictionary SupplyOrders { get; diff --git a/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IEquipmentReceivingLogic.cs b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IEquipmentReceivingLogic.cs index 2852e8d..7c17b96 100644 --- a/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IEquipmentReceivingLogic.cs +++ b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IEquipmentReceivingLogic.cs @@ -12,9 +12,8 @@ namespace ComputerShopContracts.BusinessLogicContracts public interface IEquipmentReceivingLogic { List? ReadList(EquipmentReceivingSearchModel? model); - bool CreateOrder(EquipmentReceivingBindingModel model); - bool TakeOrderInWork(EquipmentReceivingBindingModel model); - bool FinishOrder(EquipmentReceivingBindingModel model); - bool DeliveryOrder(EquipmentReceivingBindingModel model); + bool Create(EquipmentReceivingBindingModel model); + bool TakeInWork(EquipmentReceivingBindingModel model); + bool Finish(EquipmentReceivingBindingModel model); } } diff --git a/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IOrderLogic.cs b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IOrderLogic.cs index 82706b8..43bd404 100644 --- a/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IOrderLogic.cs +++ b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IOrderLogic.cs @@ -12,12 +12,12 @@ namespace ComputerShopContracts.BusinessLogicContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); - OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); - bool Update(ComponentBindingModel model); - bool Delete(ComponentBindingModel model); + bool Update(OrderBindingModel model); + bool Delete(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); bool DeliveryOrder(OrderBindingModel model); + bool AddAssembly(OrderSearchModel ordermodel, AssemblySearchModel model, int amount); } } diff --git a/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/ISupplyLogic.cs b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/ISupplyLogic.cs index 8beb1cf..d54a4b0 100644 --- a/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/ISupplyLogic.cs +++ b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/ISupplyLogic.cs @@ -16,9 +16,7 @@ namespace ComputerShopContracts.BusinessLogicContracts bool Create(SupplyBindingModel model); bool Update(SupplyBindingModel model); bool Delete(SupplyBindingModel model); - bool CreateOrder(PurchaseBindingModel model); - bool TakeOrderInWork(PurchaseBindingModel model); - bool FinishOrder(PurchaseBindingModel model); - bool DeliveryOrder(PurchaseBindingModel model); + bool TakeInWork(SupplyBindingModel model); + bool Finish(SupplyBindingModel model); } } diff --git a/ComputerShopProvider/ComputerShopContracts/ViewModels/OrderViewModel.cs b/ComputerShopProvider/ComputerShopContracts/ViewModels/OrderViewModel.cs index ceb1ff4..b852292 100644 --- a/ComputerShopProvider/ComputerShopContracts/ViewModels/OrderViewModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/ViewModels/OrderViewModel.cs @@ -19,6 +19,16 @@ namespace ComputerShopContracts.ViewModels [DisplayName("Дата создания")] public DateTime DateCreate { get; set; } = DateTime.Now; + public Dictionary AssemblyOrders + { + get; + set; + } = new(); + public Dictionary SupplyOrders + { + get; + set; + } = new(); [DisplayName("Дата выполнения")] @@ -26,5 +36,9 @@ namespace ComputerShopContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } + public int ClientId { get; set; } + + [DisplayName("ФИО клиента")] + public string ClientFIO { get; set; } = string.Empty; } } diff --git a/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs b/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs index db1c39e..ed365cb 100644 --- a/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs @@ -22,22 +22,13 @@ namespace ComputerShopContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } + [DisplayName("Номер получения")] + public int ReceivingId { get; set; } public Dictionary SupplyOrders { get; set; } = new(); - public int? ReceivingId { get; set; } - - - - - - - - - - } } diff --git a/ComputerShopProvider/ComputerShopDataModels/Models/ISupplyModel.cs b/ComputerShopProvider/ComputerShopDataModels/Models/ISupplyModel.cs index 7c91b95..c159c15 100644 --- a/ComputerShopProvider/ComputerShopDataModels/Models/ISupplyModel.cs +++ b/ComputerShopProvider/ComputerShopDataModels/Models/ISupplyModel.cs @@ -3,10 +3,11 @@ namespace ComputerShopDataModels.Models { public interface ISupplyModel : IId - { + { SupplyStatus Status { get; } DateTime DateCreate { get; } DateTime? DateImplement { get; } + int ReceivingId { get; } Dictionary SupplyOrders { get; } } } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/PurchaseStorage.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/PurchaseStorage.cs index 3b16ba0..72c9e3f 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/PurchaseStorage.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/PurchaseStorage.cs @@ -21,7 +21,11 @@ namespace ComputerShopDatabaseImplement.Implements return null; } using var context = new ComputerShopDatabase(); - return context.Purchases.Include(x => x.Component).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Purchases.Include(x => x.Component) + .FirstOrDefault(x => + (model.Id.HasValue && x.Id == + model.Id)) + ?.GetViewModel; } public List GetFilteredList(PurchaseSearchModel model) diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/SupplyStorage.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/SupplyStorage.cs index 3e114e4..8bc56a9 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/SupplyStorage.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/SupplyStorage.cs @@ -38,7 +38,7 @@ namespace ComputerShopDatabaseImplement.Implements using var context = new ComputerShopDatabase(); return context.Supplies .Include(x => x.Orders) - .ThenInclude(x => x.Order) + .ThenInclude(x => x.Order).Include(x => x.Receiving) .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) @@ -56,6 +56,7 @@ namespace ComputerShopDatabaseImplement.Implements return context.Supplies .Include(x => x.Orders) .ThenInclude(x => x.Order) + .Include(x => x.Receiving) .Where(x => x.Id == model.Id) .ToList() .Select(x => x.GetViewModel) @@ -64,6 +65,7 @@ namespace ComputerShopDatabaseImplement.Implements return context.Supplies .Include(x => x.Orders) .ThenInclude(x => x.Order) + .Include(x => x.Receiving) .Include(x => x.ComponentSupplies) .ThenInclude(x => x.Component) .Where(x => x.ComponentSupplies.Any(x => x.ComponentId == model.ComponentId)) @@ -78,6 +80,7 @@ namespace ComputerShopDatabaseImplement.Implements return context.Supplies .Include(x => x.Orders) .ThenInclude(x => x.Order) + .Include(x => x.Receiving) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -94,6 +97,7 @@ namespace ComputerShopDatabaseImplement.Implements context.Supplies.Add(newProduct); context.SaveChanges(); return newProduct.GetViewModel; + } public SupplyViewModel? Update(SupplyBindingModel model) diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs index e6093f4..fd8e607 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs @@ -24,9 +24,42 @@ namespace ComputerShopDatabaseImplement.Models public DateTime? DateImplement { get; private set; } [ForeignKey("OrderId")] - public virtual List SupplyOrders { get; set; } = new(); + public virtual List Supplies { get; set; } = new(); + private Dictionary? _supplyOrders = null; + [ForeignKey("OrderId")] public virtual List Assemblies { get; set; } = new(); + private Dictionary? _assemblyOrders = null; + + [NotMapped] + public Dictionary AssemblyOrders + { + get + { + if (_assemblyOrders == null) + { + _assemblyOrders = Assemblies + .ToDictionary(recPC => recPC.AssemblyId, recPC => + (recPC.Order as IOrderModel, recPC.Count)); + } + 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; } public static Order? Create(OrderBindingModel model) @@ -42,6 +75,7 @@ namespace ComputerShopDatabaseImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, + ClientId = model.ClientId }; } public static Order Create(OrderViewModel model) @@ -53,6 +87,7 @@ namespace ComputerShopDatabaseImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, + ClientId = model.ClientId }; } public void Update(OrderBindingModel model) @@ -71,6 +106,7 @@ namespace ComputerShopDatabaseImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, + ClientId = ClientId }; } } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs index c2bcd87..d6a3c49 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs @@ -26,6 +26,8 @@ namespace ComputerShopDatabaseImplement.Models public int OrderId { get; set; } public int ReceivingId { get; set; } + public virtual EquipmentReceiving Receiving { get; set; } + private Dictionary? _supplyOrders = null; [NotMapped] @@ -54,6 +56,7 @@ namespace ComputerShopDatabaseImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, + Receiving = model.Receiving, Orders = model.SupplyOrders.Select(x => new SupplyOrder {