Supply fix
This commit is contained in:
@@ -26,18 +26,18 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
public int OrderId { get; set; }
|
||||
|
||||
public int ReceivingId { get; set; }
|
||||
private Dictionary<int, (IOrderModel, int)>? _supplyOrders =
|
||||
private Dictionary<int, (int, IOrderModel)>? _supplyOrders =
|
||||
null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IOrderModel, int)> SupplyOrders
|
||||
public Dictionary<int, (int, IOrderModel)> SupplyOrders
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_supplyOrders == null)
|
||||
{
|
||||
_supplyOrders = Orders
|
||||
.ToDictionary(recPC => recPC.OrderId, recPC =>
|
||||
(recPC.Order as IOrderModel, recPC.Count));
|
||||
.ToDictionary(recPC => recPC.SupplyId, recPC =>
|
||||
(recPC.OrderId, recPC.Order as IOrderModel));
|
||||
}
|
||||
return _supplyOrders;
|
||||
}
|
||||
@@ -61,7 +61,6 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
SupplyOrder
|
||||
{
|
||||
Order = context.Orders.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
@@ -94,7 +93,6 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateOrder in SupplyOrders)
|
||||
{
|
||||
updateOrder.Count = model.SupplyOrders[updateOrder.OrderId].Item2;
|
||||
model.SupplyOrders.Remove(updateOrder.OrderId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
@@ -105,8 +103,7 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
context.SupplyOrders.Add(new SupplyOrder
|
||||
{
|
||||
Supply = supply,
|
||||
Order = context.Orders.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
Order = context.Orders.First(x => x.Id == pc.Key)
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user