Error fix
This commit is contained in:
parent
e0c39713ee
commit
4967f035d9
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -18,11 +18,13 @@ namespace ComputerShopBusinessLogic.BusinessLogics
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IAssemblyStorage _assemblyStorage;
|
||||
public OrderLogic(ILogger<ComponentLogic> logger, IOrderStorage orderStorage, IAssemblyStorage assemblyStorage)
|
||||
private readonly ISupplyStorage _supplyStorage;
|
||||
public OrderLogic(ILogger<ComponentLogic> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
|
@ -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.Неизвестен;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
|
@ -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; }
|
||||
|
@ -19,5 +19,7 @@ namespace ComputerShopContracts.ViewModels
|
||||
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Номер клиента")]
|
||||
public int ClientId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace ComputerShopContracts.ViewModels
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
public Dictionary<int, ISupplyModel> SupplyOrders
|
||||
public Dictionary<int, IOrderModel> SupplyOrders
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -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<int, IOrderModel> SupplyOrders
|
||||
|
@ -38,20 +38,6 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
}
|
||||
|
||||
private Dictionary<int, (IOrderModel, int)>? _assemblyOrders = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IOrderModel, int)> 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<AssemblyComponent> 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)
|
||||
|
@ -22,6 +22,8 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
|
||||
[ForeignKey("ReceivingId")]
|
||||
public List<Supply> 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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,7 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
[ForeignKey("OrderId")]
|
||||
public virtual List<SupplyOrder> Supplies { get; set; } = new();
|
||||
private Dictionary<int, IOrderModel>? _supplyOrders = null;
|
||||
public virtual List<SupplyOrder> SupplyOrders { get; set; } = new();
|
||||
|
||||
[ForeignKey("OrderId")]
|
||||
public virtual List<AssemblyOrder> Assemblies { get; set; } = new();
|
||||
@ -45,20 +44,6 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
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]
|
||||
public int ClientId { get; set; }
|
||||
|
@ -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<int, IOrderModel>? _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)
|
||||
{
|
||||
|
@ -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<MainController> logger, IEquipmentReceivingLogic equipmentReceiving)
|
||||
{
|
||||
_logger = logger;
|
||||
_equipmentReceiving = equipmentReceiving;
|
||||
}
|
||||
[HttpGet]
|
||||
public List<EquipmentReceivingViewModel>? GetReceivingList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _equipmentReceiving.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка компонентов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<EquipmentReceivingViewModel>? 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,24 +14,36 @@ namespace ComputerShopRestApi.Controllers
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISupplyLogic _supply;
|
||||
private readonly IOrderLogic _order;
|
||||
public SupplyController(ILogger<SupplyController> logger, ISupplyLogic supply, IOrderLogic order)
|
||||
private readonly IEquipmentReceivingLogic _equipmentReceiving;
|
||||
|
||||
public SupplyController(ILogger<SupplyController> logger, ISupplyLogic supply, IOrderLogic order, IEquipmentReceivingLogic equipmentReceiving)
|
||||
{
|
||||
_logger = logger;
|
||||
_supply = supply;
|
||||
_order = order;
|
||||
_equipmentReceiving = equipmentReceiving;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
[HttpGet]
|
||||
public List<AssemblyViewModel>? GetAssemblyList(int clientId)
|
||||
public List<EquipmentReceivingViewModel>? GetReceivingList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _supply.ReadList(new SupplySearchModel
|
||||
{
|
||||
return _equipmentReceiving.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка компонентов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
[HttpGet]
|
||||
public List<SupplyViewModel>? GetSupplyList(int componentid)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _supply.ReadList(new SupplySearchModel { ComponentId = componentid });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -41,91 +53,72 @@ namespace ComputerShopRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<AssemblyViewModel, List<Tuple<string, int>>>? GetAssembly(int assemblyId)
|
||||
public List<OrderViewModel>? 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<ComponentViewModel>? 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<AssemblySearchModel, ComponentSearchModel, int> model)
|
||||
public void AddOrderToSupply(Tuple<SupplySearchModel, OrderSearchModel> 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;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user