105 lines
3.2 KiB
C#
105 lines
3.2 KiB
C#
|
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 RoleLogic : IRoleLogic
|
|||
|
{
|
|||
|
private readonly ILogger _logger;
|
|||
|
//private readonly ICategoryProductStorage _storage;
|
|||
|
|
|||
|
// todo нет интерфейса хранилища
|
|||
|
public RoleLogic(ILogger<RoleLogic> logger)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
}
|
|||
|
|
|||
|
public bool Create(RoleBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
// todo _storage.Insert(model) == null
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
_logger.LogWarning("Insert operation failed");
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool Delete(RoleBindingModel 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(RoleBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
// todo _storage.Insert(model) == null
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
_logger.LogWarning("Update operation failed");
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public List<RoleViewModel>? ReadList(RoleSearchModel? model)
|
|||
|
{
|
|||
|
_logger.LogInformation($"ReadList. ID:{model?.ID}");
|
|||
|
// todo model == null _RoleStorage.GetFullList() : _RoleStorage.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(RoleBindingModel 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 = _RoleStorage.GetElement(new RoleSearchModel
|
|||
|
{
|
|||
|
Name = model.Name
|
|||
|
});
|
|||
|
if (element != null && element.Id != model.ID)
|
|||
|
{
|
|||
|
throw new InvalidOperationException("Такая роль уже есть");
|
|||
|
}
|
|||
|
*/
|
|||
|
}
|
|||
|
}
|
|||
|
}
|