Compare commits

...

2 Commits

7 changed files with 444 additions and 4 deletions

View File

@ -0,0 +1,110 @@
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.BusinessLogics
{
public class DealLogic : IDealLogic
{
private readonly ILogger _logger;
private readonly IDealStorage _dealStorage;
public DealLogic(ILogger<DealLogic> logger, IDealStorage dealStorage)
{
_logger = logger;
_dealStorage = dealStorage;
}
public List<DealViewModel>? ReadList(DealSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
var list = model == null ? _dealStorage.GetFullList() : _dealStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public DealViewModel? ReadElement(DealSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
var element = _dealStorage.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(DealBindingModel model)
{
CheckModel(model);
if (_dealStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(DealBindingModel model)
{
CheckModel(model);
if (_dealStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(DealBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_dealStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(DealBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.ClientId < 0)
{
throw new InvalidOperationException("Неверный ID клиента");
}
if (model.OperatorId < 0)
{
throw new InvalidOperationException("Неверный ID оператора");
}
_logger.LogInformation("Deal. DealDate:{DealDate}. ClientId:{ClientId}. OperatorId:{OperatorId}. Id:{Id}", model.DealDate, model.ClientId, model.OperatorId, model.Id);
}
}
}

View File

@ -0,0 +1,126 @@
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.BusinessLogics
{
public class OperatorLogic : IOperatorLogic
{
private readonly ILogger _logger;
private readonly IOperatorStorage _operatorStorage;
public OperatorLogic(ILogger<OperatorLogic> logger, IOperatorStorage operatorStorage)
{
_logger = logger;
_operatorStorage = operatorStorage;
}
public List<OperatorViewModel>? ReadList(OperatorSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
var list = model == null ? _operatorStorage.GetFullList() : _operatorStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public OperatorViewModel? ReadElement(OperatorSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
var element = _operatorStorage.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(OperatorBindingModel model)
{
CheckModel(model);
if (_operatorStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(OperatorBindingModel model)
{
CheckModel(model);
if (_operatorStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(OperatorBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_operatorStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(OperatorBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.FirstName))
{
throw new ArgumentNullException("Нет имени оператора", nameof(model.FirstName));
}
if (string.IsNullOrEmpty(model.LastName))
{
throw new ArgumentNullException("Нет фамилии оператора", nameof(model.LastName));
}
if (string.IsNullOrEmpty(model.Login))
{
throw new ArgumentNullException("Нет логина оператора", nameof(model.Login));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля оператора", nameof(model.Password));
}
_logger.LogInformation("Operator. LastName:{LastName}. FirstName:{FirstName}. Login:{Login}. Password:{Password}. Id:{Id}", model.LastName, model.FirstName, model.Login, model.Password, model.Id);
var element = _operatorStorage.GetElement(new OperatorSearchModel
{
Login = model.Login
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Оператор с таким логином уже есть");
}
}
}
}

View File

@ -0,0 +1,98 @@
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.BusinessLogics
{
public class PaymentLogic : IPaymentLogic
{
private readonly ILogger _logger;
private readonly IPaymentStorage _paymentStorage;
public PaymentLogic(ILogger<PaymentLogic> logger, IPaymentStorage paymentStorage)
{
_logger = logger;
_paymentStorage = paymentStorage;
}
public List<PaymentViewModel>? ReadList(PaymentSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
var list = model == null ? _paymentStorage.GetFullList() : _paymentStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public PaymentViewModel? ReadElement(PaymentSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
var element = _paymentStorage.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(PaymentBindingModel model)
{
CheckModel(model);
if (_paymentStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(PaymentBindingModel model)
{
CheckModel(model);
if (_paymentStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(PaymentBindingModel model)
{
CheckModel(model);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_paymentStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(PaymentBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("Payment. PaymentDate:{PaymentDate}. Id:{Id}", model.PaymentDate, model.Id);
}
}
}

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.BusinessLogics
{
public class TransferLogic : ITransferLogic
{
private readonly ILogger _logger;
private readonly ITransferStorage _transferStorage;
public TransferLogic(ILogger<TransferLogic> logger, ITransferStorage transferStorage)
{
_logger = logger;
_transferStorage = transferStorage;
}
public List<TransferViewModel>? ReadList(TransferSearchModel? model)
{
_logger.LogInformation("ReadList. 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)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
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);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
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.Amount <= 0)
{
throw new InvalidOperationException("Сумма зачисления не может быть меньше 0");
}
_logger.LogInformation("Transfer. TransferDateTime:{TransferDateTime}. Amount:{Amount}. PaymentId:{PaymentId}. Id:{Id}", model.TransferDateTime, model.Amount, model.PaymentId, model.Id);
}
}
}

View File

@ -15,7 +15,7 @@ namespace BankContracts.BindingModels
public int OperatorId { get; set; } public int OperatorId { get; set; }
public int CreditProgramId {get; set; } public int? CreditProgramId {get; set; }
public int Id { get; set; } public int Id { get; set; }
} }

View File

@ -18,9 +18,9 @@ namespace BankContracts.ViewModels
public int OperatorId { get;set;} public int OperatorId { get;set;}
[DisplayName("ФИО оператора")] [DisplayName("ФИО оператора")]
public string OperatorName { get; set; } = string.Empty; public string OperatorName { get; set; } = string.Empty;
public int CreditProgramId {get;set;} public int? CreditProgramId {get;set;}
[DisplayName("Название кредитной программы")] [DisplayName("Название кредитной программы")]
public string CreditProgramName { get; set; } = string.Empty; public string? CreditProgramName { get; set; } = string.Empty;
[DisplayName("Номер сделки")] [DisplayName("Номер сделки")]
public int Id {get;set;} public int Id {get;set;}
} }

View File

@ -11,6 +11,6 @@ namespace BankDataModels.Models
int ClientId { get; } int ClientId { get; }
DateTime DealDate { get; } DateTime DealDate { get; }
int OperatorId { get; } int OperatorId { get; }
int CreditProgramId { get; } int? CreditProgramId { get; }
} }
} }