fix logic
This commit is contained in:
parent
72e40c79e6
commit
23d3ba8885
@ -1,6 +1,7 @@
|
|||||||
using Contracts.BindingModels;
|
using Contracts.BindingModels;
|
||||||
using Contracts.BusinessLogicContracts;
|
using Contracts.BusinessLogicContracts;
|
||||||
using Contracts.Converters;
|
using Contracts.Converters;
|
||||||
|
using Contracts.Exceptions;
|
||||||
using Contracts.SearchModels;
|
using Contracts.SearchModels;
|
||||||
using Contracts.StorageContracts;
|
using Contracts.StorageContracts;
|
||||||
using Contracts.ViewModels;
|
using Contracts.ViewModels;
|
||||||
@ -24,21 +25,20 @@ namespace BusinessLogic.BusinessLogic
|
|||||||
_roleStorage = roleStorage;
|
_roleStorage = roleStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RoleViewModel? Create(RoleBindingModel model)
|
public RoleViewModel Create(RoleBindingModel model)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(model);
|
ArgumentNullException.ThrowIfNull(model);
|
||||||
|
|
||||||
var role = _roleStorage.Insert(model);
|
var role = _roleStorage.Insert(model);
|
||||||
if (role is null)
|
if (role is null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert operation failed.");
|
throw new Exception("Insert operation failed.");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return RoleConverter.ToView(role);
|
return RoleConverter.ToView(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RoleViewModel? Delete(RoleSearchModel model)
|
public RoleViewModel Delete(RoleSearchModel model)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(model);
|
ArgumentNullException.ThrowIfNull(model);
|
||||||
|
|
||||||
@ -46,14 +46,13 @@ namespace BusinessLogic.BusinessLogic
|
|||||||
var role = _roleStorage.Delete(model);
|
var role = _roleStorage.Delete(model);
|
||||||
if (role is null)
|
if (role is null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Delete operation failed.");
|
throw new Exception("Delete operation failed.");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return RoleConverter.ToView(role);
|
return RoleConverter.ToView(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RoleViewModel? ReadElement(RoleSearchModel model)
|
public RoleViewModel ReadElement(RoleSearchModel model)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(model);
|
ArgumentNullException.ThrowIfNull(model);
|
||||||
|
|
||||||
@ -61,8 +60,7 @@ namespace BusinessLogic.BusinessLogic
|
|||||||
var role = _roleStorage.GetElement(model);
|
var role = _roleStorage.GetElement(model);
|
||||||
if (role is null)
|
if (role is null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("ReadElement element not found");
|
throw new ElementNotFoundException();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
_logger.LogInformation("ReadElement find. Id: {0}", role.Id);
|
_logger.LogInformation("ReadElement find. Id: {0}", role.Id);
|
||||||
|
|
||||||
@ -83,15 +81,14 @@ namespace BusinessLogic.BusinessLogic
|
|||||||
return list.Select(RoleConverter.ToView);
|
return list.Select(RoleConverter.ToView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RoleViewModel? Update(RoleBindingModel model)
|
public RoleViewModel Update(RoleBindingModel model)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(model);
|
ArgumentNullException.ThrowIfNull(model);
|
||||||
|
|
||||||
var role = _roleStorage.Update(model);
|
var role = _roleStorage.Update(model);
|
||||||
if (role is null)
|
if (role is null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Update operation failed.");
|
throw new Exception("Update operation failed.");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
return RoleConverter.ToView(role);
|
return RoleConverter.ToView(role);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Contracts.BindingModels;
|
using Contracts.BindingModels;
|
||||||
using Contracts.BusinessLogicContracts;
|
using Contracts.BusinessLogicContracts;
|
||||||
using Contracts.Converters;
|
using Contracts.Converters;
|
||||||
|
using Contracts.Exceptions;
|
||||||
using Contracts.SearchModels;
|
using Contracts.SearchModels;
|
||||||
using Contracts.StorageContracts;
|
using Contracts.StorageContracts;
|
||||||
using Contracts.ViewModels;
|
using Contracts.ViewModels;
|
||||||
@ -24,21 +25,20 @@ namespace BusinessLogic.BusinessLogic
|
|||||||
_userStorage = userStorage;
|
_userStorage = userStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserViewModel? Create(UserBindingModel model)
|
public UserViewModel Create(UserBindingModel model)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(model);
|
ArgumentNullException.ThrowIfNull(model);
|
||||||
|
|
||||||
var user = _userStorage.Insert(model);
|
var user = _userStorage.Insert(model);
|
||||||
if (user is null)
|
if (user is null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert operation failed.");
|
throw new Exception("Insert operation failed.");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return UserConverter.ToView(user);
|
return UserConverter.ToView(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserViewModel? Delete(UserSearchModel model)
|
public UserViewModel Delete(UserSearchModel model)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(model);
|
ArgumentNullException.ThrowIfNull(model);
|
||||||
|
|
||||||
@ -46,8 +46,7 @@ namespace BusinessLogic.BusinessLogic
|
|||||||
var user = _userStorage.Delete(model);
|
var user = _userStorage.Delete(model);
|
||||||
if (user is null)
|
if (user is null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Delete operation failed.");
|
throw new Exception("Update operation failed.");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return UserConverter.ToView(user);
|
return UserConverter.ToView(user);
|
||||||
@ -67,7 +66,7 @@ namespace BusinessLogic.BusinessLogic
|
|||||||
return list.Select(UserConverter.ToView);
|
return list.Select(UserConverter.ToView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserViewModel? ReadElement(UserSearchModel model)
|
public UserViewModel ReadElement(UserSearchModel model)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(model);
|
ArgumentNullException.ThrowIfNull(model);
|
||||||
|
|
||||||
@ -75,23 +74,21 @@ namespace BusinessLogic.BusinessLogic
|
|||||||
var user = _userStorage.GetElement(model);
|
var user = _userStorage.GetElement(model);
|
||||||
if (user is null)
|
if (user is null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("ReadElement element not found");
|
throw new ElementNotFoundException();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
_logger.LogInformation("ReadElement find. Id: {0}", user.Id);
|
_logger.LogInformation("ReadElement find. Id: {0}", user.Id);
|
||||||
|
|
||||||
return UserConverter.ToView(user);
|
return UserConverter.ToView(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserViewModel? Update(UserBindingModel model)
|
public UserViewModel Update(UserBindingModel model)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(model);
|
ArgumentNullException.ThrowIfNull(model);
|
||||||
|
|
||||||
var user = _userStorage.Update(model);
|
var user = _userStorage.Update(model);
|
||||||
if (user is null)
|
if (user is null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Update operation failed.");
|
throw new Exception("Update operation failed.");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
return UserConverter.ToView(user);
|
return UserConverter.ToView(user);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user