Business Logic fix 0.3

This commit is contained in:
Илья Федотов 2024-04-30 21:31:36 +04:00
parent bdf27f1607
commit e2dd3b3b4f
2 changed files with 20 additions and 13 deletions

View File

@ -83,17 +83,24 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
private void CheckModel(ProductBindingModel model, bool withParams = true)
{
if (model == null) throw new ArgumentNullException(nameof(model));
if (!withParams) return;
if (string.IsNullOrEmpty(model.ProductName))
if (model == null) {
throw new ArgumentNullException(nameof(model));
}
if (!withParams) {
return;
}
if (string.IsNullOrEmpty(model.ProductName)) {
throw new ArgumentNullException("Нет названия продукта", nameof(model.ProductName));
if (model.Price <= 0)
}
if (model.Price <= 0) {
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}");
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("Продукт с таким названием уже есть");
}
}
}
}

View File

@ -51,7 +51,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
_logger.LogInformation($"Delete.ID:{model.ID}");
if (_storage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failes");
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
@ -64,28 +64,28 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
{
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);
if (element == null)
{
_logger.LogWarning("ReadElement element not fount");
_logger.LogWarning("ReadElement. element not fount");
return null;
}
_logger.LogInformation($"ReadElement: find.ID:{element.ID}");
_logger.LogInformation($"ReadElement.find.ID:{element.ID}");
return element;
}
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); ;
if (list == null)
{
_logger.LogWarning("ReadList: return null list");
_logger.LogWarning("ReadList. return null list");
return null;
}
_logger.LogInformation($"ReadList:Count:{list.Count}");
_logger.LogInformation($"ReadList.Count:{list.Count}");
return list;
}