ClientsBuisnessLogic

This commit is contained in:
shadowik 2023-04-01 10:24:54 +04:00
parent 75e20bdeea
commit 30cb243a84
5 changed files with 360 additions and 6 deletions

View File

@ -7,7 +7,6 @@
</PropertyGroup>
<ItemGroup>
<Folder Include="BusinessLogics\" />
<Folder Include="Implements\" />
<Folder Include="OfficePackage\" />
</ItemGroup>

View File

@ -0,0 +1,116 @@
using Microsoft.Extensions.Logging;
using BankYouBankruptContracts.BindingModels;
using BankYouBankruptContracts.BusinessLogicsContracts;
using BankYouBankruptContracts.SearchModels;
using BankYouBankruptContracts.StoragesContracts;
using BankYouBankruptContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankYouBankruptBusinessLogic.BusinessLogics
{
public class CardLogic : ICardLogic
{
private readonly ILogger _logger;
private readonly ICardStorage _cardStorage;
public CardLogic(ILogger<CardLogic> logger, ICardStorage cardStorage) {
_logger = logger;
_cardStorage = cardStorage;
}
public bool Create(CardBindingModel model)
{
CheckModel(model);
if (_cardStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(CardBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_cardStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public CardViewModel? ReadElement(CardSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. CardNumber:{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 List<CardViewModel>? ReadList(CardSearchModel? model)
{
_logger.LogInformation("ReadList. CardId:{Id}", 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 bool Update(CardBindingModel model)
{
CheckModel(model);
if (_cardStorage.Update(model) == null)
{
_logger.LogWarning("Update 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.CVC))
{
throw new ArgumentNullException("Нет СVC карты", nameof(model.CVC));
}
if (model.Period < DateTime.Now)
{
throw new ArgumentNullException("Нет периода действия", nameof(model.Period));
}
_logger.LogInformation("Card. Number:{Number}.CVC:{CVC}.ClientId:{ClientID}.Patronymic:{Period}.Id:{Id}",
model.Number, model.CVC, model.Period.ToString(), model.ClientID, model.Id);
}
}
}

View File

@ -96,9 +96,17 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
{
return;
}
if (string.IsNullOrEmpty(model.ClientFIO))
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException("Нет ФИО пользователя", nameof(model.ClientFIO));
throw new ArgumentNullException("Нет имени пользователя", nameof(model.Name));
}
if (string.IsNullOrEmpty(model.Surname))
{
throw new ArgumentNullException("Нет фамилии пользователя", nameof(model.Surname));
}
if (string.IsNullOrEmpty(model.Patronymic))
{
throw new ArgumentNullException("Нет отчества пользователя", nameof(model.Patronymic));
}
if (string.IsNullOrEmpty(model.Email))
{
@ -108,11 +116,18 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
{
throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password));
}
_logger.LogInformation("Client. ClientFIO:{ClientFIO}.Email:{Email}.Password:{Password}.Id:{Id}",
model.ClientFIO, model.Email, model.Password, model.Id);
if (string.IsNullOrEmpty(model.Telephone))
{
throw new ArgumentNullException("Нет телефона пользователя", nameof(model.Telephone));
}
_logger.LogInformation("Client. Name:{Name}.Surname:{Surname}.Patronymic:{Patronymic}.Email:{Email}.Password:{Password}.Telephone:{Telephone}.Id:{Id}",
model.Name, model.Surname, model.Patronymic, model.Email, model.Password, model.Telephone, model.Id);
var element = _clientStorage.GetElement(new ClientSearchModel
{
ClientFIO = model.ClientFIO
Name = model.Name,
Surname = model.Surname,
Patronymic = model.Surname,
Email = model.Email,
});
if (element != null && element.Id != model.Id)
{

View File

@ -0,0 +1,112 @@
using Microsoft.Extensions.Logging;
using BankYouBankruptContracts.BindingModels;
using BankYouBankruptContracts.BusinessLogicsContracts;
using BankYouBankruptContracts.SearchModels;
using BankYouBankruptContracts.StoragesContracts;
using BankYouBankruptContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankYouBankruptBusinessLogic.BusinessLogics
{
public class CreditingLogic : ICreditingLogic
{
private readonly ILogger _logger;
private readonly ICreditingStorage _creditingStorage;
public CreditingLogic(ILogger<CreditingLogic> logger, ICreditingStorage creditingStorage) {
_logger = logger;
_creditingStorage = creditingStorage;
}
public bool Create(CreditingBindingModel model)
{
CheckModel(model);
if (_creditingStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(CreditingBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_creditingStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public CreditingViewModel? ReadElement(CreditingSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. CreditingId:{ Id }", model.Id);
var element = _creditingStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<CreditingViewModel>? ReadList(CreditingSearchModel? model)
{
_logger.LogInformation("ReadList. CreditingId:{Id}", model?.Id);
var list = model == null ? _creditingStorage.GetFullList() : _creditingStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(CreditingBindingModel model)
{
CheckModel(model);
if (_creditingStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(CreditingBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Sum <= 0)
{
throw new ArgumentNullException("Сумма операции должна быть больше 0", nameof(model.Sum));
}
if (model.date < DateTime.Now)
{
throw new ArgumentNullException("Дата не может быть меньше текущего времени", nameof(model.date));
}
_logger.LogInformation("Crediting. Sum:{Sum}.CardId:{CardId}.Date:{date}.Id:{Id}",
model.Sum, model.CardId, model.date.ToString(), model.Id);
}
}
}

View File

@ -0,0 +1,112 @@
using Microsoft.Extensions.Logging;
using BankYouBankruptContracts.BindingModels;
using BankYouBankruptContracts.BusinessLogicsContracts;
using BankYouBankruptContracts.SearchModels;
using BankYouBankruptContracts.StoragesContracts;
using BankYouBankruptContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankYouBankruptBusinessLogic.BusinessLogics
{
public class DebitingLogic : IDebitingLogic
{
private readonly ILogger _logger;
private readonly IDebitingStorage _debitingStorage;
public DebitingLogic(ILogger<DebitingLogic> logger, IDebitingStorage debitingStorage) {
_logger = logger;
_debitingStorage = debitingStorage;
}
public bool Create(DebitingBindingModel model)
{
CheckModel(model);
if (_debitingStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(DebitingBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_debitingStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public DebitingViewModel? ReadElement(DebitingSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. DebitingId:{ Id }", model.Id);
var element = _debitingStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<DebitingViewModel>? ReadList(DebitingSearchModel? model)
{
_logger.LogInformation("ReadList. DebitingId:{Id}", model?.Id);
var list = model == null ? _debitingStorage.GetFullList() : _debitingStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(DebitingBindingModel model)
{
CheckModel(model);
if (_debitingStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(DebitingBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Sum <= 0)
{
throw new ArgumentNullException("Сумма операции должна быть больше 0", nameof(model.Sum));
}
if (model.date < DateTime.Now)
{
throw new ArgumentNullException("Дата не может быть меньше текущего времени", nameof(model.date));
}
_logger.LogInformation("Debiting. Sum:{Sum}.CardId:{CardId}.Date:{date}.Id:{Id}",
model.Sum, model.CardId, model.date.ToString(), model.Id);
}
}
}