Часть бизнесс-логики готова
This commit is contained in:
parent
1f6488fa7c
commit
9512a118d0
@ -6,10 +6,6 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="BusinessLogic\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
|
||||
|
100
Bank/BankBusinessLogic/BusinessLogic/CardLogic.cs
Normal file
100
Bank/BankBusinessLogic/BusinessLogic/CardLogic.cs
Normal file
@ -0,0 +1,100 @@
|
||||
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 CardLogic : ICardLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICardStorage _cardStorage;
|
||||
public CardLogic(ILogger logger, ICardStorage cardStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_cardStorage = cardStorage;
|
||||
}
|
||||
|
||||
public List<CardViewModel>? ReadList(CardSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Number: {Number}, Id: {Id}", model?.Number, model?.Id);
|
||||
var list = model == null ? _cardStorage.GetFullList() : _cardStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("readList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public CardViewModel? ReadElement(CardSearchModel model)
|
||||
{
|
||||
if (model == null) throw new ArgumentNullException(nameof(model));
|
||||
_logger.LogInformation("ReadElement Number: {Number}, Id: {Id}", model?.Number, model?.Id);
|
||||
var element = _cardStorage.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(CardBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_cardStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(CardBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_cardStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(CardBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_cardStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(CardBindingModel 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 (string.IsNullOrEmpty(model.Cvv))
|
||||
throw new ArgumentNullException("Нет cvv карты", nameof(model.Cvv));
|
||||
if (string.IsNullOrEmpty(model.Pin))
|
||||
throw new ArgumentNullException("Нет pin карты", nameof(model.Pin));
|
||||
_logger.LogInformation("Card. Number:{Number}." +
|
||||
"Cvv:{ Cvv}. Pin:{ Pin}. Id: { Id} ", model.Number, model.Cvv, model.Pin, model.Id);
|
||||
var element = _cardStorage.GetElement(new CardSearchModel { Number = model.Number });
|
||||
if (element != null && element.Id == model.Id)
|
||||
throw new InvalidOperationException("Карта с таким номером уже есть");
|
||||
}
|
||||
}
|
||||
}
|
101
Bank/BankBusinessLogic/BusinessLogic/ClientLogic.cs
Normal file
101
Bank/BankBusinessLogic/BusinessLogic/ClientLogic.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.BusinessLogicsContracts;
|
||||
using BankContracts.SearchModels;
|
||||
using BankContracts.StoragesContracts;
|
||||
using BankContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PdfSharp.Drawing.BarCodes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ClientLogic : IClientLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientStorage _clientStorage;
|
||||
public ClientLogic(ILogger logger, IClientStorage clientStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_clientStorage = clientStorage;
|
||||
}
|
||||
|
||||
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Fio:{ Fio}. Id: {Id}", model?.Fio, model?.Id);
|
||||
var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public ClientViewModel? ReadElement(ClientSearchModel model)
|
||||
{
|
||||
if (model == null) throw new ArgumentNullException(nameof(model));
|
||||
_logger.LogInformation("ReadElement. Fio: {Fio}. Id: {Id}", model?.Fio, model?.Id);
|
||||
var element = _clientStorage.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(ClientBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_clientStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(ClientBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_clientStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ClientBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_clientStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ClientBindingModel 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("Client. ClientFIO:{ClientFIO}." +
|
||||
"Email:{ Email}. Password:{ Password}. Id: { Id} ", model.Fio, model.Email, model.Password, model.Id);
|
||||
var element = _clientStorage.GetElement(new ClientSearchModel { Email = model.Email });
|
||||
if (element != null && element.Id == model.Id)
|
||||
throw new InvalidOperationException("Клиент с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
92
Bank/BankBusinessLogic/BusinessLogic/OperationLogic.cs
Normal file
92
Bank/BankBusinessLogic/BusinessLogic/OperationLogic.cs
Normal file
@ -0,0 +1,92 @@
|
||||
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 OperationLogic : IOperationLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOperationStorage _operationStorage;
|
||||
public OperationLogic(ILogger logger, IOperationStorage operationStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_operationStorage = operationStorage;
|
||||
}
|
||||
|
||||
public List<OperationViewModel>? ReadList(OperationSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id: {Id}", model?.Id);
|
||||
var list = model == null ? _operationStorage.GetFullList() : _operationStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public OperationViewModel? ReadElement(OperationSearchModel model)
|
||||
{
|
||||
if (model == null) throw new ArgumentNullException(nameof(model));
|
||||
_logger.LogInformation("ReadElement. Id: {Id}", model?.Id);
|
||||
var element = _operationStorage.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(OperationBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_operationStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(OperationBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_operationStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(OperationBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_operationStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(OperationBindingModel 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));
|
||||
_logger.LogInformation("Operation. Sum:{Sum}. Id: { Id} ", model.Sum, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
111
Bank/BankBusinessLogic/BusinessLogic/RequestLogic.cs
Normal file
111
Bank/BankBusinessLogic/BusinessLogic/RequestLogic.cs
Normal file
@ -0,0 +1,111 @@
|
||||
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 RequestLogic : IRequestLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRequestStorage _requestStorage;
|
||||
public RequestLogic(ILogger logger, IRequestStorage requestStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_requestStorage = requestStorage;
|
||||
}
|
||||
|
||||
public List<RequestViewModel>? ReadList(RequestSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id: {Id}", model?.Id);
|
||||
var list = model == null ? _requestStorage.GetFullList() : _requestStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public RequestViewModel? ReadElement(RequestSearchModel model)
|
||||
{
|
||||
if (model == null) throw new ArgumentNullException(nameof(model));
|
||||
_logger.LogInformation("ReadElement. Id: {Id}", model?.Id);
|
||||
var element = _requestStorage.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(RequestBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (model.Status != RequestStatus.Неизвестен) return false;
|
||||
model.Status = RequestStatus.Принята;
|
||||
if (_requestStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(RequestBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_requestStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(RequestBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (_requestStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool DeclineRequest(RequestBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, RequestStatus.Выполнена);
|
||||
}
|
||||
public bool SatisfyRequest(RequestBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, RequestStatus.Отклонена);
|
||||
}
|
||||
|
||||
private void CheckModel(RequestBindingModel 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));
|
||||
_logger.LogInformation("Request. Sum:{Sum}. Id: { Id} ", model.Sum, model.Id);
|
||||
}
|
||||
|
||||
private bool ChangeStatus(RequestBindingModel model, RequestStatus status)
|
||||
{
|
||||
//поменять
|
||||
model.Status = status;
|
||||
_requestStorage.Update(model);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user