Artyom_Yashin 2024-04-28 22:42:01 +04:00
commit ee88e831c4
11 changed files with 428 additions and 9 deletions

View File

@ -0,0 +1,106 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.StoragesContracts;
using BankContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankBusinessLogic.BusinessLogic
{
public class AccountLogic : IAccountLogic
{
private readonly ILogger _logger;
private readonly IAccountStorage _accountStorage;
public AccountLogic(ILogger logger, IAccountStorage accountStorage)
{
_logger = logger;
_accountStorage = accountStorage;
}
public List<AccountViewModel>? ReadList(AccountSearchModel? model)
{
_logger.LogInformation("ReadList. Account. Number: {Number}, Id: {Id}",
model?.Number, model?.Id);
var list = model == null ?
_accountStorage.GetFullList() : _accountStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("readList return null list");
return null;
}
_logger.LogInformation("ReadList Count: {Count}", list.Count);
return list;
}
public AccountViewModel? ReadElement(AccountSearchModel model)
{
_logger.LogInformation("ReadElement. Account. Number: {Number}, Id: {Id}",
model?.Number, model?.Id);
if (model == null)
throw new ArgumentNullException(nameof(model));
var element = _accountStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find Id:{ Id}", element.Id);
return element;
}
public bool Create(AccountBindingModel model)
{
CheckModel(model);
if (_accountStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(AccountBindingModel model)
{
CheckModel(model);
if (_accountStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(AccountBindingModel model)
{
CheckModel(model, false);
if (_accountStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
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.Number))
throw new ArgumentNullException("Нет номера счёта", nameof(model.Number));
if (model.ManagerId <= 0)
throw new ArgumentNullException("Нет id менеджера", nameof(model.ManagerId));
_logger.LogInformation("Account. Number: {Number}. ManagerId: {ManagerId}. Id: {Id} ",
model.Number, model.ManagerId, model.Id);
var element = _accountStorage.GetElement(new AccountSearchModel { Number = model.Number });
if (element != null)
throw new InvalidOperationException("Счет с таким номером уже есть");
}
}
}

View File

@ -36,8 +36,8 @@ namespace BankBusinessLogic.BusinessLogic
}
public CardViewModel? ReadElement(CardSearchModel model)
{
if (model == null) throw new ArgumentNullException(nameof(model));
_logger.LogInformation("ReadElement Number: {Number}, Id: {Id}", model?.Number, model?.Id);
if (model == null) throw new ArgumentNullException(nameof(model));
var element = _cardStorage.GetElement(model);
if (element == null)
{

View File

@ -37,8 +37,8 @@ namespace BankBusinessLogic.BusinessLogic
}
public ClientViewModel? ReadElement(ClientSearchModel model)
{
if (model == null) throw new ArgumentNullException(nameof(model));
_logger.LogInformation("ReadElement. Fio: {Fio}. Id: {Id}", model?.Fio, model?.Id);
if (model == null) throw new ArgumentNullException(nameof(model));
var element = _clientStorage.GetElement(model);
if (element == null)
{

View File

@ -0,0 +1,109 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.StoragesContracts;
using BankContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankBusinessLogic.BusinessLogic
{
public class ManagerLogic : IManagerLogic
{
private readonly ILogger _logger;
private readonly IManagerStorage _managerStorage;
public ManagerLogic(ILogger logger, IManagerStorage managerStorage)
{
_logger = logger;
_managerStorage = managerStorage;
}
public List<ManagerViewModel>? ReadList(ManagerSearchModel? model)
{
_logger.LogInformation("ReadList. Managers. Fio:{ Fio}. Id: {Id}",
model?.Fio, model?.Id);
var list = model == null ?
_managerStorage.GetFullList() : _managerStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList Count: {Count}", list.Count);
return list;
}
public ManagerViewModel? ReadElement(ManagerSearchModel model)
{
_logger.LogInformation("ReadElement. Fio: {Fio}. Id: {Id}",
model?.Fio, model?.Id);
if (model == null)
throw new ArgumentNullException(nameof(model));
var element = _managerStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
return element;
}
public bool Create(ManagerBindingModel model)
{
CheckModel(model);
if (_managerStorage.Insert(model) == null)
{
_logger.LogWarning("insert operation failed");
return false;
}
return true;
}
public bool Update(ManagerBindingModel model)
{
CheckModel(model);
if (_managerStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ManagerBindingModel model)
{
CheckModel(model, false);
if (_managerStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ManagerBindingModel model, bool withParams = true)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
if (!withParams)
return;
if (string.IsNullOrEmpty(model.Fio))
throw new ArgumentNullException("Нет ФИО менеджера", nameof(model.Fio));
if (string.IsNullOrEmpty(model.Email))
throw new ArgumentNullException("Нет email менеджера", nameof(model.Email));
if (string.IsNullOrEmpty(model.Password))
throw new ArgumentNullException("Нет пароля менеджера", nameof(model.Password));
_logger.LogInformation("Manager. FIO:{FIO}. Email:{ Email}. Password:{ Password}. Id: { Id} ",
model.Fio, model.Email, model.Password, model.Id);
var element = _managerStorage.GetElement(new ManagerSearchModel { Email = model.Email });
if (element != null)
throw new InvalidOperationException("Менеджер с таким Email уже есть");
}
}
}

View File

@ -36,8 +36,8 @@ namespace BankBusinessLogic.BusinessLogic
}
public OperationViewModel? ReadElement(OperationSearchModel model)
{
if (model == null) throw new ArgumentNullException(nameof(model));
_logger.LogInformation("ReadElement. Id: {Id}", model?.Id);
if (model == null) throw new ArgumentNullException(nameof(model));
var element = _operationStorage.GetElement(model);
if (element == null)
{

View File

@ -35,10 +35,11 @@ namespace BankBusinessLogic.BusinessLogic
_logger.LogInformation("ReadList Count: {Count}", list.Count);
return list;
}
public RequestViewModel? ReadElement(RequestSearchModel model)
public RequestViewModel? ReadElement(RequestSearchModel model)
{
if (model == null) throw new ArgumentNullException(nameof(model));
_logger.LogInformation("ReadElement. Id: {Id}", model?.Id);
if (model == null)
throw new ArgumentNullException(nameof(model));
var element = _requestStorage.GetElement(model);
if (element == null)
{

View File

@ -0,0 +1,106 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.StoragesContracts;
using BankContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankBusinessLogic.BusinessLogic
{
public class TransferLogic : ITransferLogic
{
private readonly ILogger _logger;
private readonly ITransferStorage _transferStorage;
public TransferLogic(ILogger logger, ITransferStorage transferStorage)
{
_logger = logger;
_transferStorage = transferStorage;
}
public List<TransferViewModel>? ReadList(TransferSearchModel? model)
{
_logger.LogInformation("ReadList. Transfer. Id: {Id}", model?.Id);
var list = model == null ?
_transferStorage.GetFullList() : _transferStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList Count: {Count}", list.Count);
return list;
}
public TransferViewModel? ReadElement(TransferSearchModel model)
{
_logger.LogInformation("ReadElement. Transfer. Id: {Id}", model?.Id);
if (model == null) throw new ArgumentNullException(nameof(model));
var element = _transferStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
return element;
}
public bool Create(TransferBindingModel model)
{
CheckModel(model);
if (_transferStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(TransferBindingModel model)
{
CheckModel(model);
if (_transferStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(TransferBindingModel model)
{
CheckModel(model, false);
if (_transferStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(TransferBindingModel model, bool withParams = true)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
if (!withParams)
return;
if (model.Sum <= 0)
throw new ArgumentNullException("Неверная сумма перевода",
nameof(model.Sum));
if (model.SenderAccountId <= 0)
throw new ArgumentNullException("Неверный id счёта отправителя",
nameof(model.SenderAccountId));
if (model.RecipientAccountId <= 0)
throw new ArgumentNullException("Неверный id счёта получателя",
nameof(model.RecipientAccountId));
_logger.LogInformation("Transfer. Sum:{Sum}. SenderAccountId: {SenderAccountId}. " +
"RecipientAccountId: {RecipientAccountId}. Id: { Id} ",
model.Sum, model.SenderAccountId, model.RecipientAccountId, model.Id);
}
}
}

View File

@ -0,0 +1,97 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.StoragesContracts;
using BankContracts.ViewModels;
using BankDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankBusinessLogic.BusinessLogic
{
public class WithdrawalLogic : IWithdrawalLogic
{
private readonly ILogger _logger;
private readonly IWithdrawalStorage _withdrawalStorage;
public WithdrawalLogic(ILogger logger, IWithdrawalStorage withdrawalStorage)
{
_logger = logger;
_withdrawalStorage = withdrawalStorage;
}
public List<WithdrawalViewModel>? ReadList(WithdrawalSearchModel? model)
{
_logger.LogInformation("ReadList. Withdrawal. Id: {Id}", model?.Id);
var list = model == null ?
_withdrawalStorage.GetFullList() : _withdrawalStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList Count: {Count}", list.Count);
return list;
}
public WithdrawalViewModel? ReadElement(WithdrawalSearchModel model)
{
_logger.LogInformation("ReadElement. Withdrawal. Id: {Id}", model?.Id);
if (model == null)
throw new ArgumentNullException(nameof(model));
var element = _withdrawalStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
return element;
}
public bool Create(WithdrawalBindingModel model)
{
CheckModel(model);
if (_withdrawalStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(WithdrawalBindingModel model)
{
CheckModel(model);
if (_withdrawalStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(WithdrawalBindingModel model)
{
CheckModel(model, false);
if (_withdrawalStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(WithdrawalBindingModel model, bool withParams = true)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
if (!withParams)
return;
_logger.LogInformation("Withdrawal. Id: { Id} ", model.Id);
}
}
}

View File

@ -39,9 +39,9 @@ namespace BankDatabaseImplement.Models
{
Id = model.Id,
Number = model.Number,
ReleaseDate = model.ReleaseDate,
ReleaseDate = DateOnly.FromDateTime(DateTime.Now),
ManagerId = model.ManagerId,
Money = model.Money,
Money = 0,
};
}

View File

@ -34,7 +34,7 @@ namespace BankDatabaseImplement.Models
{
Id = model.Id,
Sum = model.Sum,
TransferTime = model.TransferTime,
TransferTime = DateTime.Now,
SenderAccountId = model.SenderAccountId,
RecipientAccountId = model.RecipientAccountId,
};

View File

@ -43,7 +43,7 @@ namespace BankDatabaseImplement.Models
return new Withdrawal
{
Id = model.Id,
WithdrawalTime = model.WithdrawalTime,
WithdrawalTime = DateTime.Now,
Accounts = model.WithdrawalAccounts.Select(x => new AccountWithdrawal
{
Account = context.Accounts.First(y => y.Id == x.Key)