Models & Logic fix
This commit is contained in:
parent
1283b13869
commit
3ba667323d
@ -1,7 +1,10 @@
|
|||||||
using ComputerShopContracts.BindingModels;
|
using ComputerShopContracts.BindingModels;
|
||||||
using ComputerShopContracts.BusinessLogicContracts;
|
using ComputerShopContracts.BusinessLogicContracts;
|
||||||
using ComputerShopContracts.SearchModels;
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.StorageContracts;
|
||||||
using ComputerShopContracts.ViewModels;
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Enums;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -12,29 +15,87 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
public class EquipmentReceivingLogic : IEquipmentReceivingLogic
|
public class EquipmentReceivingLogic : IEquipmentReceivingLogic
|
||||||
{
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IEquipmentReceivingStorage _receivingStorage;
|
||||||
|
|
||||||
|
public EquipmentReceivingLogic(ILogger<PurchaseLogic> logger, IEquipmentReceivingStorage receivingStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_receivingStorage = receivingStorage;
|
||||||
|
}
|
||||||
public List<EquipmentReceivingViewModel>? ReadList(EquipmentReceivingSearchModel? model)
|
public List<EquipmentReceivingViewModel>? 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)
|
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();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool DeliveryOrder(EquipmentReceivingBindingModel model)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
using ComputerShopContracts.BindingModels;
|
using ComputerShopContracts.BindingModels;
|
||||||
using ComputerShopContracts.BusinessLogicContracts;
|
using ComputerShopContracts.BusinessLogicContracts;
|
||||||
using ComputerShopContracts.SearchModels;
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.StorageContracts;
|
||||||
using ComputerShopContracts.ViewModels;
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Enums;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -12,44 +15,152 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
public class OrderLogic : IOrderLogic
|
public class OrderLogic : IOrderLogic
|
||||||
{
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
private readonly IAssemblyStorage _assemblyStorage;
|
||||||
|
public OrderLogic(ILogger<ComponentLogic> logger, IOrderStorage orderStorage, IAssemblyStorage assemblyStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_orderStorage = orderStorage;
|
||||||
|
_assemblyStorage = assemblyStorage;
|
||||||
|
}
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
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<OrderViewModel>? ReadList(OrderSearchModel? model)
|
public List<OrderViewModel>? 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)
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
using ComputerShopContracts.BindingModels;
|
using ComputerShopContracts.BindingModels;
|
||||||
using ComputerShopContracts.BusinessLogicContracts;
|
using ComputerShopContracts.BusinessLogicContracts;
|
||||||
using ComputerShopContracts.SearchModels;
|
using ComputerShopContracts.SearchModels;
|
||||||
|
using ComputerShopContracts.StorageContracts;
|
||||||
using ComputerShopContracts.ViewModels;
|
using ComputerShopContracts.ViewModels;
|
||||||
|
using ComputerShopDataModels.Enums;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -12,29 +15,33 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
public class SupplyLogic : ISupplyLogic
|
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)
|
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)
|
public bool Delete(SupplyBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
CheckModel(model, false);
|
||||||
}
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_supplyStorage.Delete(model) == null)
|
||||||
public bool DeliveryOrder(PurchaseBindingModel model)
|
{
|
||||||
{
|
_logger.LogWarning("Delete operation failed");
|
||||||
throw new NotImplementedException();
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
public bool FinishOrder(PurchaseBindingModel model)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SupplyViewModel? ReadElement(SupplySearchModel model)
|
public SupplyViewModel? ReadElement(SupplySearchModel model)
|
||||||
@ -44,17 +51,66 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
public List<SupplyViewModel>? ReadList(SupplySearchModel? model)
|
public List<SupplyViewModel>? 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)
|
public bool Update(SupplyBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,17 @@ namespace ComputerShopContracts.BindingModels
|
|||||||
public DateTime DateCreate { get; set; }
|
public DateTime DateCreate { get; set; }
|
||||||
|
|
||||||
public DateTime? DateImplement { get; set; } = DateTime.Now;
|
public DateTime? DateImplement { get; set; } = DateTime.Now;
|
||||||
|
public int ClientId { get; set; }
|
||||||
|
public Dictionary<int, (IAssemblyModel, int)> AssemblyOrders
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = new();
|
||||||
|
public Dictionary<int, IOrderModel> SupplyOrders
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = new();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,13 @@ namespace ComputerShopContracts.BindingModels
|
|||||||
public class SupplyBindingModel : ISupplyModel
|
public class SupplyBindingModel : ISupplyModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
public int ReceivingId { get; set; }
|
||||||
public SupplyStatus Status { get; set; } = SupplyStatus.Неизвестен;
|
public SupplyStatus Status { get; set; } = SupplyStatus.Неизвестен;
|
||||||
|
|
||||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
public DateTime? DateImplement { get; set; }
|
public DateTime? DateImplement { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, IOrderModel> SupplyOrders
|
public Dictionary<int, IOrderModel> SupplyOrders
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
@ -12,9 +12,8 @@ namespace ComputerShopContracts.BusinessLogicContracts
|
|||||||
public interface IEquipmentReceivingLogic
|
public interface IEquipmentReceivingLogic
|
||||||
{
|
{
|
||||||
List<EquipmentReceivingViewModel>? ReadList(EquipmentReceivingSearchModel? model);
|
List<EquipmentReceivingViewModel>? ReadList(EquipmentReceivingSearchModel? model);
|
||||||
bool CreateOrder(EquipmentReceivingBindingModel model);
|
bool Create(EquipmentReceivingBindingModel model);
|
||||||
bool TakeOrderInWork(EquipmentReceivingBindingModel model);
|
bool TakeInWork(EquipmentReceivingBindingModel model);
|
||||||
bool FinishOrder(EquipmentReceivingBindingModel model);
|
bool Finish(EquipmentReceivingBindingModel model);
|
||||||
bool DeliveryOrder(EquipmentReceivingBindingModel model);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,12 @@ namespace ComputerShopContracts.BusinessLogicContracts
|
|||||||
public interface IOrderLogic
|
public interface IOrderLogic
|
||||||
{
|
{
|
||||||
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||||
OrderViewModel? ReadElement(OrderSearchModel model);
|
|
||||||
bool CreateOrder(OrderBindingModel model);
|
bool CreateOrder(OrderBindingModel model);
|
||||||
bool Update(ComponentBindingModel model);
|
bool Update(OrderBindingModel model);
|
||||||
bool Delete(ComponentBindingModel model);
|
bool Delete(OrderBindingModel model);
|
||||||
bool TakeOrderInWork(OrderBindingModel model);
|
bool TakeOrderInWork(OrderBindingModel model);
|
||||||
bool FinishOrder(OrderBindingModel model);
|
bool FinishOrder(OrderBindingModel model);
|
||||||
bool DeliveryOrder(OrderBindingModel model);
|
bool DeliveryOrder(OrderBindingModel model);
|
||||||
|
bool AddAssembly(OrderSearchModel ordermodel, AssemblySearchModel model, int amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,7 @@ namespace ComputerShopContracts.BusinessLogicContracts
|
|||||||
bool Create(SupplyBindingModel model);
|
bool Create(SupplyBindingModel model);
|
||||||
bool Update(SupplyBindingModel model);
|
bool Update(SupplyBindingModel model);
|
||||||
bool Delete(SupplyBindingModel model);
|
bool Delete(SupplyBindingModel model);
|
||||||
bool CreateOrder(PurchaseBindingModel model);
|
bool TakeInWork(SupplyBindingModel model);
|
||||||
bool TakeOrderInWork(PurchaseBindingModel model);
|
bool Finish(SupplyBindingModel model);
|
||||||
bool FinishOrder(PurchaseBindingModel model);
|
|
||||||
bool DeliveryOrder(PurchaseBindingModel model);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,16 @@ namespace ComputerShopContracts.ViewModels
|
|||||||
|
|
||||||
[DisplayName("Дата создания")]
|
[DisplayName("Дата создания")]
|
||||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
|
public Dictionary<int, (IAssemblyModel, int)> AssemblyOrders
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = new();
|
||||||
|
public Dictionary<int, ISupplyModel> SupplyOrders
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = new();
|
||||||
|
|
||||||
|
|
||||||
[DisplayName("Дата выполнения")]
|
[DisplayName("Дата выполнения")]
|
||||||
@ -26,5 +36,9 @@ namespace ComputerShopContracts.ViewModels
|
|||||||
|
|
||||||
[DisplayName("Номер")]
|
[DisplayName("Номер")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
public int ClientId { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("ФИО клиента")]
|
||||||
|
public string ClientFIO { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,22 +22,13 @@ namespace ComputerShopContracts.ViewModels
|
|||||||
|
|
||||||
[DisplayName("Номер")]
|
[DisplayName("Номер")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Номер получения")]
|
||||||
|
public int ReceivingId { get; set; }
|
||||||
public Dictionary<int, IOrderModel> SupplyOrders
|
public Dictionary<int, IOrderModel> SupplyOrders
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
} = new();
|
} = new();
|
||||||
|
|
||||||
public int? ReceivingId { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
namespace ComputerShopDataModels.Models
|
namespace ComputerShopDataModels.Models
|
||||||
{
|
{
|
||||||
public interface ISupplyModel : IId
|
public interface ISupplyModel : IId
|
||||||
{
|
{
|
||||||
SupplyStatus Status { get; }
|
SupplyStatus Status { get; }
|
||||||
DateTime DateCreate { get; }
|
DateTime DateCreate { get; }
|
||||||
DateTime? DateImplement { get; }
|
DateTime? DateImplement { get; }
|
||||||
|
int ReceivingId { get; }
|
||||||
Dictionary<int, IOrderModel> SupplyOrders { get; }
|
Dictionary<int, IOrderModel> SupplyOrders { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,11 @@ namespace ComputerShopDatabaseImplement.Implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
using var context = new ComputerShopDatabase();
|
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<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
|
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
|
||||||
|
@ -38,7 +38,7 @@ namespace ComputerShopDatabaseImplement.Implements
|
|||||||
using var context = new ComputerShopDatabase();
|
using var context = new ComputerShopDatabase();
|
||||||
return context.Supplies
|
return context.Supplies
|
||||||
.Include(x => x.Orders)
|
.Include(x => x.Orders)
|
||||||
.ThenInclude(x => x.Order)
|
.ThenInclude(x => x.Order).Include(x => x.Receiving)
|
||||||
.FirstOrDefault(x =>
|
.FirstOrDefault(x =>
|
||||||
(model.Id.HasValue && x.Id ==
|
(model.Id.HasValue && x.Id ==
|
||||||
model.Id))
|
model.Id))
|
||||||
@ -56,6 +56,7 @@ namespace ComputerShopDatabaseImplement.Implements
|
|||||||
return context.Supplies
|
return context.Supplies
|
||||||
.Include(x => x.Orders)
|
.Include(x => x.Orders)
|
||||||
.ThenInclude(x => x.Order)
|
.ThenInclude(x => x.Order)
|
||||||
|
.Include(x => x.Receiving)
|
||||||
.Where(x => x.Id == model.Id)
|
.Where(x => x.Id == model.Id)
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
@ -64,6 +65,7 @@ namespace ComputerShopDatabaseImplement.Implements
|
|||||||
return context.Supplies
|
return context.Supplies
|
||||||
.Include(x => x.Orders)
|
.Include(x => x.Orders)
|
||||||
.ThenInclude(x => x.Order)
|
.ThenInclude(x => x.Order)
|
||||||
|
.Include(x => x.Receiving)
|
||||||
.Include(x => x.ComponentSupplies)
|
.Include(x => x.ComponentSupplies)
|
||||||
.ThenInclude(x => x.Component)
|
.ThenInclude(x => x.Component)
|
||||||
.Where(x => x.ComponentSupplies.Any(x => x.ComponentId == model.ComponentId))
|
.Where(x => x.ComponentSupplies.Any(x => x.ComponentId == model.ComponentId))
|
||||||
@ -78,6 +80,7 @@ namespace ComputerShopDatabaseImplement.Implements
|
|||||||
return context.Supplies
|
return context.Supplies
|
||||||
.Include(x => x.Orders)
|
.Include(x => x.Orders)
|
||||||
.ThenInclude(x => x.Order)
|
.ThenInclude(x => x.Order)
|
||||||
|
.Include(x => x.Receiving)
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -94,6 +97,7 @@ namespace ComputerShopDatabaseImplement.Implements
|
|||||||
context.Supplies.Add(newProduct);
|
context.Supplies.Add(newProduct);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return newProduct.GetViewModel;
|
return newProduct.GetViewModel;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SupplyViewModel? Update(SupplyBindingModel model)
|
public SupplyViewModel? Update(SupplyBindingModel model)
|
||||||
|
@ -24,9 +24,42 @@ namespace ComputerShopDatabaseImplement.Models
|
|||||||
|
|
||||||
public DateTime? DateImplement { get; private set; }
|
public DateTime? DateImplement { get; private set; }
|
||||||
[ForeignKey("OrderId")]
|
[ForeignKey("OrderId")]
|
||||||
public virtual List<SupplyOrder> SupplyOrders { get; set; } = new();
|
public virtual List<SupplyOrder> Supplies { get; set; } = new();
|
||||||
|
private Dictionary<int, IOrderModel>? _supplyOrders = null;
|
||||||
|
|
||||||
[ForeignKey("OrderId")]
|
[ForeignKey("OrderId")]
|
||||||
public virtual List<AssemblyOrder> Assemblies { get; set; } = new();
|
public virtual List<AssemblyOrder> Assemblies { get; set; } = new();
|
||||||
|
private Dictionary<int, (IOrderModel, int)>? _assemblyOrders = null;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IOrderModel, int)> AssemblyOrders
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_assemblyOrders == null)
|
||||||
|
{
|
||||||
|
_assemblyOrders = Assemblies
|
||||||
|
.ToDictionary(recPC => recPC.AssemblyId, recPC =>
|
||||||
|
(recPC.Order as IOrderModel, recPC.Count));
|
||||||
|
}
|
||||||
|
return _assemblyOrders;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, IOrderModel> SupplyOrders
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_supplyOrders == null)
|
||||||
|
{
|
||||||
|
_supplyOrders = Supplies
|
||||||
|
.ToDictionary(recPC => recPC.SupplyId, recPC =>
|
||||||
|
(recPC.Order as IOrderModel));
|
||||||
|
}
|
||||||
|
return _supplyOrders;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int ClientId { get; set; }
|
public int ClientId { get; set; }
|
||||||
public static Order? Create(OrderBindingModel model)
|
public static Order? Create(OrderBindingModel model)
|
||||||
@ -42,6 +75,7 @@ namespace ComputerShopDatabaseImplement.Models
|
|||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
DateCreate = model.DateCreate,
|
DateCreate = model.DateCreate,
|
||||||
DateImplement = model.DateImplement,
|
DateImplement = model.DateImplement,
|
||||||
|
ClientId = model.ClientId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static Order Create(OrderViewModel model)
|
public static Order Create(OrderViewModel model)
|
||||||
@ -53,6 +87,7 @@ namespace ComputerShopDatabaseImplement.Models
|
|||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
DateCreate = model.DateCreate,
|
DateCreate = model.DateCreate,
|
||||||
DateImplement = model.DateImplement,
|
DateImplement = model.DateImplement,
|
||||||
|
ClientId = model.ClientId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void Update(OrderBindingModel model)
|
public void Update(OrderBindingModel model)
|
||||||
@ -71,6 +106,7 @@ namespace ComputerShopDatabaseImplement.Models
|
|||||||
Status = Status,
|
Status = Status,
|
||||||
DateCreate = DateCreate,
|
DateCreate = DateCreate,
|
||||||
DateImplement = DateImplement,
|
DateImplement = DateImplement,
|
||||||
|
ClientId = ClientId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ namespace ComputerShopDatabaseImplement.Models
|
|||||||
public int OrderId { get; set; }
|
public int OrderId { get; set; }
|
||||||
|
|
||||||
public int ReceivingId { get; set; }
|
public int ReceivingId { get; set; }
|
||||||
|
public virtual EquipmentReceiving Receiving { get; set; }
|
||||||
|
|
||||||
private Dictionary<int, IOrderModel>? _supplyOrders =
|
private Dictionary<int, IOrderModel>? _supplyOrders =
|
||||||
null;
|
null;
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
@ -54,6 +56,7 @@ namespace ComputerShopDatabaseImplement.Models
|
|||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
DateCreate = model.DateCreate,
|
DateCreate = model.DateCreate,
|
||||||
DateImplement = model.DateImplement,
|
DateImplement = model.DateImplement,
|
||||||
|
Receiving = model.Receiving,
|
||||||
Orders = model.SupplyOrders.Select(x => new
|
Orders = model.SupplyOrders.Select(x => new
|
||||||
SupplyOrder
|
SupplyOrder
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user