Готово, доделано полностью
This commit is contained in:
parent
8ac1d44d0e
commit
7f02b269a0
@ -35,9 +35,46 @@ namespace CarRepairShopBusinessLogic
|
||||
|
||||
public bool MakeSupply(ShopSearchModel model, IRepairModel repair, int count)
|
||||
{
|
||||
_logger.LogInformation("Try to supply shop. ShopName:{ShopName}. Id:{Id}", model.Name, model.Id);
|
||||
if (model == null)
|
||||
return false;
|
||||
return _shopStorage.SupplyRepair(model, repair, count);
|
||||
{
|
||||
_logger.LogWarning("Read operation failed");
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (repair == null)
|
||||
{
|
||||
_logger.LogWarning("Read operation failed");
|
||||
throw new ArgumentNullException(nameof(repair));
|
||||
}
|
||||
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.ShopRepairs.TryGetValue(repair.Id, out var pair))
|
||||
{
|
||||
curModel.ShopRepairs[repair.Id] = (pair.Item1, pair.Item2 + count);
|
||||
}
|
||||
else
|
||||
{
|
||||
curModel.ShopRepairs.Add(repair.Id, (repair, count));
|
||||
}
|
||||
Update(new()
|
||||
{
|
||||
Id = curModel.Id,
|
||||
ShopName = curModel.ShopName,
|
||||
DateOpen = curModel.DateOpen,
|
||||
Address = curModel.Address,
|
||||
ShopRepairs = curModel.ShopRepairs,
|
||||
});
|
||||
_logger.LogInformation("Success. RepairName:{RepairName}. Id:{Id}. Supply:{count}", repair.RepairName, repair.Id, count);
|
||||
return true;
|
||||
}
|
||||
|
||||
public ShopViewModel ReadElement(ShopSearchModel model)
|
||||
|
@ -13,6 +13,5 @@ namespace CarRepairShopContracts.StoragesContracts
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
bool SupplyRepair(ShopSearchModel model, IRepairModel repair, int Count);
|
||||
}
|
||||
}
|
||||
|
@ -100,36 +100,5 @@ namespace CarRepairShopListImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool SupplyRepair(ShopSearchModel model, IRepairModel repair, int count)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
if (repair == null)
|
||||
throw new ArgumentNullException(nameof(repair));
|
||||
if (count <= 0)
|
||||
throw new ArgumentNullException("Количество должно быть положительным числом");
|
||||
|
||||
ShopViewModel curModel = GetElement(model);
|
||||
if (curModel == null)
|
||||
throw new ArgumentNullException(nameof(curModel));
|
||||
if (curModel.ShopRepairs.TryGetValue(repair.Id, out var pair))
|
||||
{
|
||||
curModel.ShopRepairs[repair.Id] = (pair.Item1, pair.Item2 + count);
|
||||
}
|
||||
else
|
||||
{
|
||||
curModel.ShopRepairs.Add(repair.Id, (repair, count));
|
||||
}
|
||||
Update(new()
|
||||
{
|
||||
Id = curModel.Id,
|
||||
ShopName = curModel.ShopName,
|
||||
DateOpen = curModel.DateOpen,
|
||||
Address = curModel.Address,
|
||||
ShopRepairs = curModel.ShopRepairs,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user