Business Logic fix 0.3
This commit is contained in:
parent
bdf27f1607
commit
e2dd3b3b4f
@ -83,17 +83,24 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
|
|
||||||
private void CheckModel(ProductBindingModel model, bool withParams = true)
|
private void CheckModel(ProductBindingModel model, bool withParams = true)
|
||||||
{
|
{
|
||||||
if (model == null) throw new ArgumentNullException(nameof(model));
|
if (model == null) {
|
||||||
if (!withParams) return;
|
throw new ArgumentNullException(nameof(model));
|
||||||
if (string.IsNullOrEmpty(model.ProductName))
|
}
|
||||||
|
if (!withParams) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.ProductName)) {
|
||||||
throw new ArgumentNullException("Нет названия продукта", nameof(model.ProductName));
|
throw new ArgumentNullException("Нет названия продукта", nameof(model.ProductName));
|
||||||
if (model.Price <= 0)
|
}
|
||||||
|
if (model.Price <= 0) {
|
||||||
throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price));
|
throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price));
|
||||||
_logger.LogInformation($"Product. ID:{model.ID}.ProductName:{model.ProductName}.Price:{model.Price}.Count:{model.Count}" +
|
}
|
||||||
|
_logger.LogInformation($"Product. ID:{model.ID}.ProductName:{model.ProductName}.Price:{model.Price}" +
|
||||||
$".CategoryID:{model.CategoryID}");
|
$".CategoryID:{model.CategoryID}");
|
||||||
var element = _storage.GetElement(new ProductSearchModel { ProductName = model.ProductName });
|
var element = _storage.GetElement(new ProductSearchModel { ProductName = model.ProductName });
|
||||||
if (element != null && element.ID != model.ID)
|
if (element != null && element.ID != model.ID) {
|
||||||
throw new InvalidOperationException("Продукт с таким названием уже есть");
|
throw new InvalidOperationException("Продукт с таким названием уже есть");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -51,7 +51,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
_logger.LogInformation($"Delete.ID:{model.ID}");
|
_logger.LogInformation($"Delete.ID:{model.ID}");
|
||||||
if (_storage.Delete(model) == null)
|
if (_storage.Delete(model) == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Delete operation failes");
|
_logger.LogWarning("Delete operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -64,28 +64,28 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
}
|
||||||
_logger.LogInformation($"ReadElement: logint:{model.Login}.ID:{model.ID}");
|
_logger.LogInformation($"ReadElement.Login:{model.Login}.ID:{model.ID}");
|
||||||
var element = _storage.GetElement(model);
|
var element = _storage.GetElement(model);
|
||||||
if (element == null)
|
if (element == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("ReadElement element not fount");
|
_logger.LogWarning("ReadElement. element not fount");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
_logger.LogInformation($"ReadElement: find.ID:{element.ID}");
|
_logger.LogInformation($"ReadElement.find.ID:{element.ID}");
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UserViewModel>? ReadList(UserSearchModel? model)
|
public List<UserViewModel>? ReadList(UserSearchModel? model)
|
||||||
{
|
{
|
||||||
|
|
||||||
_logger.LogInformation($"ReadList: ClientID:{model?.ID}");
|
_logger.LogInformation($"ReadList. ClientID:{model?.ID}");
|
||||||
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model); ;
|
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model); ;
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("ReadList: return null list");
|
_logger.LogWarning("ReadList. return null list");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
_logger.LogInformation($"ReadList:Count:{list.Count}");
|
_logger.LogInformation($"ReadList.Count:{list.Count}");
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user