fixed 0.4 категории воскресли!

This commit is contained in:
Илья Федотов 2024-04-28 23:53:21 +04:00
parent f899455329
commit 15f995b6ce

View File

@ -0,0 +1,95 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class CategoryProductLogic : ICategoryProductLogic
{
private readonly ILogger _logger;
//private readonly ICategoryProductStorage _storage;
// todo нет интерфейса хранилища
public CategoryProductLogic(ILogger<CategoryProductLogic> logger) {
_logger = logger;
}
public bool Create(CategoryProductBindingModel model)
{
CheckModel(model);
// todo _storage.Insert(model) == null
if (model == null) {
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(CategoryProductBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation($"Delete. ID:{model.ID}");
// todo _storage.Insert(model) == null
if (model == null) {
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool Update(CategoryProductBindingModel model)
{
CheckModel(model);
// todo _storage.Insert(model) == null
if (model == null) {
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public List<CategoryProductViewModel>? ReadList(CategoryProductSearchModel? model)
{
_logger.LogInformation($"ReadList. ID:{model?.ID}");
// todo model == null _CategoryProductStorage.GetFullList() : _CategoryProductStorage.GetFilteredList(model);
var list = model;
if (list == null) {
_logger.LogWarning("ReadList return null list");
return null;
}
// todo $"ReadList. Count:{list.count}"
_logger.LogInformation("ReadList. Count:{Count}");
// todo return list;
return null;
}
private void CheckModel(CategoryProductBindingModel model, bool withParams = true) {
if (model == null) {
throw new ArgumentNullException(nameof(model));
}
if (!withParams) {
return;
}
if (string.IsNullOrEmpty(model.Name)) {
throw new ArgumentNullException("Нет названия категории продукта", nameof(model.Name));
}
_logger.LogInformation($"CategoryProduct. Name:{model.Name}");
/*
var element = _ CategoryProductStorage.GetElement(new CategoryProductSearchModel
{
Name = model.Name
});
if (element != null && element.Id != model.ID)
{
throw new InvalidOperationException("Категория с таким названием уже есть");
}
*/
}
}
}