make it better

This commit is contained in:
Sergey Kozyrev 2024-02-24 10:02:06 +04:00
parent c8d59d9fbc
commit e9f8e389ff
3 changed files with 26 additions and 35 deletions
SewingDresses
SewingDressesBusinessLogic/BusinessLogic
SewingDressesContracts/StoragesContracts
SewingDressesListImplement/Implements

@ -122,8 +122,32 @@ namespace SewingDressesBusinessLogic.BusinessLogic
public bool MakeSupply(ShopSearchModel model, IDressModel dress, int count)
{
if (model == null)
return false;
return _shopStorage.SupplyDress(model, dress, count);
throw new ArgumentNullException(nameof(model));
if (dress == null)
throw new ArgumentNullException(nameof(dress));
if (count <= 0)
throw new ArgumentNullException("Количество должно быть положительным числом");
ShopViewModel? curModel = _shopStorage.GetElement(model);
_logger.LogInformation("Make Supply");
if (curModel == null)
throw new ArgumentNullException(nameof(curModel));
if (curModel.ShopDresses.TryGetValue(dress.Id, out var pair))
{
curModel.ShopDresses[dress.Id] = (pair.Item1, pair.Item2 + count);
}
else
{
curModel.ShopDresses.Add(dress.Id, (dress, count));
}
return Update(new()
{
Id = curModel.Id,
ShopName = curModel.ShopName,
DateOpen = curModel.DateOpen,
Adress = curModel.Adress,
ShopDresses = curModel.ShopDresses,
});
}
}
}

@ -18,6 +18,5 @@ namespace SewingDressesContracts.StoragesContracts
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool SupplyDress(ShopSearchModel model, IDressModel dress, int count);
}
}

@ -104,37 +104,5 @@ namespace SewingDressesListImplement.Implements
}
return null;
}
public bool SupplyDress(ShopSearchModel model, IDressModel dress, int count)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
if (dress == null)
throw new ArgumentNullException(nameof(dress));
if (count <= 0)
throw new ArgumentNullException("Количество должно быть положительным числом");
ShopViewModel curModel = GetElement(model);
if (curModel == null)
throw new ArgumentNullException(nameof(curModel));
if (curModel.ShopDresses.TryGetValue(dress.Id, out var pair))
{
curModel.ShopDresses[dress.Id] = (pair.Item1, pair.Item2 + count);
}
else
{
curModel.ShopDresses.Add(dress.Id, (dress, count));
}
Update(new()
{
Id = curModel.Id,
ShopName = curModel.ShopName,
DateOpen = curModel.DateOpen,
Adress = curModel.Adress,
ShopDresses = curModel.ShopDresses,
});
return true;
}
}
}