Мегадоделал
This commit is contained in:
parent
32e642dc90
commit
bec7a3a706
@ -40,9 +40,46 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
|
||||
public bool MakeSupply(ShopSearchModel model, IComputerModel Computer, int count)
|
||||
{
|
||||
_logger.LogInformation("Try to supply shop. ShopName:{ShopName}. Id:{Id}", model.Name, model.Id);
|
||||
if (model == null)
|
||||
return false;
|
||||
return _shopStorage.SupplyComputer(model, Computer, count);
|
||||
{
|
||||
_logger.LogWarning("Read operation failed");
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (Computer == null)
|
||||
{
|
||||
_logger.LogWarning("Read operation failed");
|
||||
throw new ArgumentNullException(nameof(Computer));
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
_logger.LogWarning("Read operation failed");
|
||||
throw new ArgumentNullException("Количество должно быть положительным числом");
|
||||
}
|
||||
ShopViewModel curModel = ReadElement(model);
|
||||
if (curModel == null)
|
||||
{
|
||||
_logger.LogWarning("Read operation failed");
|
||||
throw new ArgumentNullException(nameof(curModel));
|
||||
}
|
||||
if (curModel.ShopComputers.TryGetValue(Computer.Id, out var pair))
|
||||
{
|
||||
curModel.ShopComputers[Computer.Id] = (pair.Item1, pair.Item2 + count);
|
||||
}
|
||||
else
|
||||
{
|
||||
curModel.ShopComputers.Add(Computer.Id, (Computer, count));
|
||||
}
|
||||
Update(new()
|
||||
{
|
||||
Id = curModel.Id,
|
||||
ShopName = curModel.ShopName,
|
||||
DateOpen = curModel.DateOpen,
|
||||
Address = curModel.Address,
|
||||
ShopComputers = curModel.ShopComputers,
|
||||
});
|
||||
_logger.LogInformation("Success. ComputerName:{ComputerName}. Id:{Id}. Supply:{count}", Computer.ComputerName, Computer.Id, count);
|
||||
return true;
|
||||
}
|
||||
|
||||
public ShopViewModel ReadElement(ShopSearchModel model)
|
||||
|
@ -18,6 +18,5 @@ namespace ComputersShopContracts.StoragesContracts
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
bool SupplyComputer(ShopSearchModel model, IComputerModel computer, int Count);
|
||||
}
|
||||
}
|
||||
|
@ -104,36 +104,5 @@ namespace ComputersShopListImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool SupplyComputer(ShopSearchModel model, IComputerModel Computer, int count)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
if (Computer == null)
|
||||
throw new ArgumentNullException(nameof(Computer));
|
||||
if (count <= 0)
|
||||
throw new ArgumentNullException("Количество должно быть положительным числом");
|
||||
|
||||
ShopViewModel curModel = GetElement(model);
|
||||
if (curModel == null)
|
||||
throw new ArgumentNullException(nameof(curModel));
|
||||
if (curModel.ShopComputers.TryGetValue(Computer.Id, out var pair))
|
||||
{
|
||||
curModel.ShopComputers[Computer.Id] = (pair.Item1, pair.Item2 + count);
|
||||
}
|
||||
else
|
||||
{
|
||||
curModel.ShopComputers.Add(Computer.Id, (Computer, count));
|
||||
}
|
||||
Update(new()
|
||||
{
|
||||
Id = curModel.Id,
|
||||
ShopName = curModel.ShopName,
|
||||
DateOpen = curModel.DateOpen,
|
||||
Address = curModel.Address,
|
||||
ShopComputers = curModel.ShopComputers,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user