make it better
This commit is contained in:
parent
c8d59d9fbc
commit
e9f8e389ff
@ -122,8 +122,32 @@ namespace SewingDressesBusinessLogic.BusinessLogic
|
|||||||
public bool MakeSupply(ShopSearchModel model, IDressModel dress, int count)
|
public bool MakeSupply(ShopSearchModel model, IDressModel dress, int count)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
return false;
|
throw new ArgumentNullException(nameof(model));
|
||||||
return _shopStorage.SupplyDress(model, dress, count);
|
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? Insert(ShopBindingModel model);
|
||||||
ShopViewModel? Update(ShopBindingModel model);
|
ShopViewModel? Update(ShopBindingModel model);
|
||||||
ShopViewModel? Delete(ShopBindingModel model);
|
ShopViewModel? Delete(ShopBindingModel model);
|
||||||
bool SupplyDress(ShopSearchModel model, IDressModel dress, int count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,37 +104,5 @@ namespace SewingDressesListImplement.Implements
|
|||||||
}
|
}
|
||||||
return null;
|
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user