Business Implementer
This commit is contained in:
parent
2a5332cc99
commit
52914c9bd4
@ -19,7 +19,7 @@ namespace BusinessLogic.BusinessLogic
|
||||
}
|
||||
public List<DetailViewModel>? ReadList(DetailSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. DetailName:{name}. Id:{Id}", model.Name, model.Id);
|
||||
_logger.LogInformation("ReadList. DetailName:{name}. Id:{Id}. UserId:{UserId}", model?.Name, model?.Id, model?.UserId);
|
||||
var list = model == null ? _detailStorage.GetFullList() : _detailStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
|
112
Course/BusinessLogic/BusinessLogic/ImplementerLogic.cs
Normal file
112
Course/BusinessLogic/BusinessLogic/ImplementerLogic.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.BusinessLogicsContracts;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StoragesContracts;
|
||||
using Contracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ImplementerLogic : IImplementerLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImplementerStorage _storage;
|
||||
|
||||
public ImplementerLogic(ILogger<ImplementerLogic> logger, IImplementerStorage storage)
|
||||
{
|
||||
_logger = logger;
|
||||
_storage = storage;
|
||||
}
|
||||
public List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Login:{Login}. Id:{Id}", model.Login, model.Id);
|
||||
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null");
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
public ImplementerViewModel? ReadElement(ImplementerSearchModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Login:{Login}. Id:{Id}.", model.Login, model.Id);
|
||||
var elem = _storage.GetElement(model);
|
||||
if (elem == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", elem.Id);
|
||||
return elem;
|
||||
}
|
||||
private void CheckModel(ImplementerBindingModel? 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));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
throw new ArgumentNullException("Нет логина пользователя", nameof(model));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля пользователя", nameof(model));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
throw new ArgumentNullException("Нет почты пользователя", nameof(model));
|
||||
}
|
||||
var elem = _storage.GetElement(new ImplementerSearchModel
|
||||
{
|
||||
Login = model.Login
|
||||
});
|
||||
if (elem != null && model.Id != elem.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Такой логин уже используется в системе");
|
||||
}
|
||||
}
|
||||
public bool Create(ImplementerBindingModel? model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_storage.Insert(model!) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(ImplementerBindingModel? model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_storage.Update(model!) == null)
|
||||
{
|
||||
_logger.LogWarning("Update error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ImplementerBindingModel? model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete Implementer. Id:{Id}", model!.Id);
|
||||
if (_storage.Delete(model!) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
107
Course/BusinessLogic/BusinessLogic/ProductLogic.cs
Normal file
107
Course/BusinessLogic/BusinessLogic/ProductLogic.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
using Contracts.StoragesContracts;
|
||||
using Contracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ProductLogic : IProductLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IProductStorage _productStorage;
|
||||
public ProductLogic(ILogger<ProductLogic> logger, IProductStorage productStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_productStorage = productStorage;
|
||||
}
|
||||
public List<ProductViewModel>? ReadList(ProductSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ProductName:{name}. Id:{Id}. UserId:{UserId}", model?.Name, model?.Id, model?.UserId);
|
||||
var list = model == null ? _productStorage.GetFullList() : _productStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogWarning("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public ProductViewModel? ReadElement(ProductSearchModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ProductName:{Name}. Id:{Id}", model.Name, model.Id);
|
||||
var elem = _productStorage.GetElement(model);
|
||||
if (elem == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", elem.Id);
|
||||
return elem;
|
||||
}
|
||||
private void CheckModel(ProductBindingModel? 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));
|
||||
}
|
||||
if (model.Cost <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Cost));
|
||||
}
|
||||
_logger.LogInformation("Product. ProductName:{Name}. Cost:{Cost}. Id:{Id}", model.Name, model.Cost, model.Id);
|
||||
var elem = _productStorage.GetElement(new ProductSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (elem != null && elem.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Изделие с таким названием уже существует");
|
||||
}
|
||||
}
|
||||
public bool Create(ProductBindingModel? model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_productStorage.Insert(model!) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(ProductBindingModel? model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_productStorage.Update(model!) == null)
|
||||
{
|
||||
_logger.LogWarning("Update error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ProductBindingModel? model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete Id:{Id}", model!.Id);
|
||||
if (_productStorage.Delete(model!) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
110
Course/BusinessLogic/BusinessLogic/ProductionLogic.cs
Normal file
110
Course/BusinessLogic/BusinessLogic/ProductionLogic.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.BusinessLogicsContracts;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StoragesContracts;
|
||||
using Contracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ProductionLogic : IProductionLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IProductionStorage _productionStorage;
|
||||
|
||||
public ProductionLogic(ILogger<ProductionLogic> logger, IProductionStorage productionStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_productionStorage = productionStorage;
|
||||
}
|
||||
public List<ProductionViewModel>? ReadList(ProductionSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ProductionName:{name}. Id:{Id}. UserId:{UserId}", model?.Name, model?.Id, model?.UserId);
|
||||
var list = model == null ? _productionStorage.GetFullList() : _productionStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogWarning("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public ProductionViewModel? ReadElement(ProductionSearchModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ProductionName:{Name}. Id:{Id}", model.Name, model.Id);
|
||||
var elem = _productionStorage.GetElement(model);
|
||||
if (elem == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", elem.Id);
|
||||
return elem;
|
||||
}
|
||||
|
||||
|
||||
private void CheckModel(ProductionBindingModel? 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));
|
||||
}
|
||||
if (model.Cost <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена производства должна быть больше 0", nameof(model.Cost));
|
||||
}
|
||||
_logger.LogInformation("Production. ProductionName:{Name}. Cost:{Cost}. Id:{Id}", model.Name, model.Cost, model.Id);
|
||||
var elem = _productionStorage.GetElement(new ProductionSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (elem != null && elem.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Деталь с таким названием уже существует");
|
||||
}
|
||||
}
|
||||
public bool Create(ProductionBindingModel? model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_productionStorage.Insert(model!) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(ProductionBindingModel? model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_productionStorage.Update(model!) == null)
|
||||
{
|
||||
_logger.LogWarning("Update error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ProductionBindingModel? model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete Id:{Id}", model!.Id);
|
||||
if (_productionStorage.Delete(model!) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ namespace Contracts.BusinessLogicsContracts
|
||||
List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model);
|
||||
ImplementerViewModel? ReadElement(ImplementerSearchModel? model);
|
||||
bool Create(ImplementerBindingModel? model);
|
||||
bool Update(ImplementerViewModel? model);
|
||||
bool Delete(ImplementerViewModel? model);
|
||||
bool Update(ImplementerBindingModel? model);
|
||||
bool Delete(ImplementerBindingModel? model);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace Contracts.BusinessLogicsContracts
|
||||
List<ProductionViewModel>? ReadList(ProductionSearchModel? model);
|
||||
ProductionViewModel? ReadElement(ProductionSearchModel? model);
|
||||
bool Create(ProductionBindingModel? model);
|
||||
bool Update(ProductionViewModel? model);
|
||||
bool Delete(ProductionViewModel? model);
|
||||
bool Update(ProductionBindingModel? model);
|
||||
bool Delete(ProductionBindingModel? model);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user