base logic #5

Merged
mfnefd merged 25 commits from registration into main 2024-06-10 12:27:55 +04:00
2 changed files with 18 additions and 24 deletions
Showing only changes of commit 23d3ba8885 - Show all commits

View File

@ -1,6 +1,7 @@
using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using Contracts.Converters;
using Contracts.Exceptions;
using Contracts.SearchModels;
using Contracts.StorageContracts;
using Contracts.ViewModels;
@ -24,21 +25,20 @@ namespace BusinessLogic.BusinessLogic
_roleStorage = roleStorage;
}
public RoleViewModel? Create(RoleBindingModel model)
public RoleViewModel Create(RoleBindingModel model)
{
ArgumentNullException.ThrowIfNull(model);
var role = _roleStorage.Insert(model);
if (role is null)
{
_logger.LogWarning("Insert operation failed.");
return null;
throw new Exception("Insert operation failed.");
}
return RoleConverter.ToView(role);
}
public RoleViewModel? Delete(RoleSearchModel model)
public RoleViewModel Delete(RoleSearchModel model)
{
ArgumentNullException.ThrowIfNull(model);
@ -46,14 +46,13 @@ namespace BusinessLogic.BusinessLogic
var role = _roleStorage.Delete(model);
if (role is null)
{
_logger.LogWarning("Delete operation failed.");
return null;
throw new Exception("Delete operation failed.");
}
return RoleConverter.ToView(role);
}
public RoleViewModel? ReadElement(RoleSearchModel model)
public RoleViewModel ReadElement(RoleSearchModel model)
{
ArgumentNullException.ThrowIfNull(model);
@ -61,8 +60,7 @@ namespace BusinessLogic.BusinessLogic
var role = _roleStorage.GetElement(model);
if (role is null)
{
_logger.LogWarning("ReadElement element not found");
return null;
throw new ElementNotFoundException();
}
_logger.LogInformation("ReadElement find. Id: {0}", role.Id);
@ -83,15 +81,14 @@ namespace BusinessLogic.BusinessLogic
return list.Select(RoleConverter.ToView);
}
public RoleViewModel? Update(RoleBindingModel model)
public RoleViewModel Update(RoleBindingModel model)
{
ArgumentNullException.ThrowIfNull(model);
var role = _roleStorage.Update(model);
if (role is null)
{
_logger.LogWarning("Update operation failed.");
return null;
throw new Exception("Update operation failed.");
}
return RoleConverter.ToView(role);
}

View File

@ -1,6 +1,7 @@
using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using Contracts.Converters;
using Contracts.Exceptions;
using Contracts.SearchModels;
using Contracts.StorageContracts;
using Contracts.ViewModels;
@ -24,21 +25,20 @@ namespace BusinessLogic.BusinessLogic
_userStorage = userStorage;
}
public UserViewModel? Create(UserBindingModel model)
public UserViewModel Create(UserBindingModel model)
{
ArgumentNullException.ThrowIfNull(model);
var user = _userStorage.Insert(model);
if (user is null)
{
_logger.LogWarning("Insert operation failed.");
return null;
throw new Exception("Insert operation failed.");
}
return UserConverter.ToView(user);
}
public UserViewModel? Delete(UserSearchModel model)
public UserViewModel Delete(UserSearchModel model)
{
ArgumentNullException.ThrowIfNull(model);
@ -46,8 +46,7 @@ namespace BusinessLogic.BusinessLogic
var user = _userStorage.Delete(model);
if (user is null)
{
_logger.LogWarning("Delete operation failed.");
return null;
throw new Exception("Update operation failed.");
}
return UserConverter.ToView(user);
@ -67,7 +66,7 @@ namespace BusinessLogic.BusinessLogic
return list.Select(UserConverter.ToView);
}
public UserViewModel? ReadElement(UserSearchModel model)
public UserViewModel ReadElement(UserSearchModel model)
{
ArgumentNullException.ThrowIfNull(model);
@ -75,23 +74,21 @@ namespace BusinessLogic.BusinessLogic
var user = _userStorage.GetElement(model);
if (user is null)
{
_logger.LogWarning("ReadElement element not found");
return null;
throw new ElementNotFoundException();
}
_logger.LogInformation("ReadElement find. Id: {0}", user.Id);
return UserConverter.ToView(user);
}
public UserViewModel? Update(UserBindingModel model)
public UserViewModel Update(UserBindingModel model)
{
ArgumentNullException.ThrowIfNull(model);
var user = _userStorage.Update(model);
if (user is null)
{
_logger.LogWarning("Update operation failed.");
return null;
throw new Exception("Update operation failed.");
}
return UserConverter.ToView(user);
}