Lab03: create AccountsBusinessLogic project

This commit is contained in:
abazov73 2023-11-16 19:36:15 +04:00
parent 1f2abc1e93
commit 173f299f93
3 changed files with 206 additions and 0 deletions

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AccountsContracts\AccountsContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,100 @@
using AccountsContracts.BindingModels;
using AccountsContracts.BusinessLogicContracts;
using AccountsContracts.SearchModels;
using AccountsContracts.StorageContracts;
using AccountsContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AccountsBusinessLogic.BusinessLogics
{
public class AccountLogic : IAccountLogic
{
private readonly IAccountStorage _accountStorage;
public AccountLogic(IAccountStorage accountStorage)
{
_accountStorage = accountStorage;
}
public List<AccountViewModel>? ReadList(AccountSearchModel? model)
{
var list = model == null ? _accountStorage.GetFullList() : _accountStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public AccountViewModel? ReadElement(AccountSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _accountStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public bool Create(AccountBindingModel model)
{
CheckModel(model);
if (_accountStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Update(AccountBindingModel model)
{
CheckModel(model);
if (_accountStorage.Update(model) == null)
{
return false;
}
return true;
}
public bool Delete(AccountBindingModel model)
{
CheckModel(model, false);
if (_accountStorage.Delete(model) == null)
{
return false;
}
return true;
}
private void CheckModel(AccountBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Login))
{
throw new ArgumentNullException("Нет логина пользователя", nameof(model.Login));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Нет электронной почты пользователя", nameof(model.Email));
}
}
}
}

View File

@ -0,0 +1,93 @@
using AccountsContracts.BindingModels;
using AccountsContracts.BusinessLogicContracts;
using AccountsContracts.SearchModels;
using AccountsContracts.StorageContracts;
using AccountsContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace AccountsBusinessLogic.BusinessLogics
{
public class InterestLogic : IInterestLogic
{
private readonly IInterestStorage _interestStorage;
public InterestLogic(IInterestStorage interestStorage)
{
_interestStorage = interestStorage;
}
public List<InterestViewModel>? ReadList(InterestSearchModel? model)
{
var list = model == null ? _interestStorage.GetFullList() : _interestStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public InterestViewModel? ReadElement(InterestSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _interestStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public bool Create(InterestBindingModel model)
{
CheckModel(model);
if (_interestStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Update(InterestBindingModel model)
{
CheckModel(model);
if (_interestStorage.Update(model) == null)
{
return false;
}
return true;
}
public bool Delete(InterestBindingModel model)
{
CheckModel(model, false);
if (_interestStorage.Delete(model) == null)
{
return false;
}
return true;
}
private void CheckModel(InterestBindingModel 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));
}
}
}
}