Готово, доделано полностью

This commit is contained in:
Yunusov_Niyaz 2024-02-28 17:04:10 +04:00
parent 8ac1d44d0e
commit 7f02b269a0
3 changed files with 39 additions and 34 deletions

View File

@ -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)

View File

@ -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);
}
}

View File

@ -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;
}
}
}