Правки.

This commit is contained in:
Programmist73 2023-05-14 14:00:44 +04:00
parent e0cb9ade43
commit a94d30e65d
4 changed files with 22 additions and 6 deletions

View File

@ -16,10 +16,12 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly ICardStorage _cardStorage;
private readonly IAccountStorage _accountStorage;
public CardLogic(ILogger<CardLogic> logger, ICardStorage cardStorage) {
public CardLogic(ILogger<CardLogic> logger, ICardStorage cardStorage, IAccountStorage accountStorage) {
_logger = logger;
_cardStorage = cardStorage;
_accountStorage = accountStorage;
}
public bool Create(CardBindingModel model)
@ -108,15 +110,27 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
{
throw new ArgumentNullException("Нет периода действия", nameof(model.Period));
}
var element = _cardStorage.GetElement(new CardSearchModel
var cardElement = _cardStorage.GetElement(new CardSearchModel
{
Number = model.Number,
});
if (element != null && element.Id != model.Id)
if (cardElement != null && cardElement.Id != model.Id)
{
throw new InvalidOperationException("Карта с таким ноиером уже есть");
}
var accountElement = _accountStorage.GetElement(new AccountSearchModel
{
Id = model.AccountId,
ClientId = model.ClientID
});
if (accountElement != null && accountElement.ClientId != model.ClientID)
{
throw new InvalidOperationException("Это не счёт данного клиента");
}
_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

@ -12,7 +12,7 @@ using System.Threading.Tasks;
namespace BankYouBankruptBusinessLogic.BusinessLogics
{
public class CashierLogic : IAccountLogic
public class CashierLogic : ICashierLogic
{
private readonly ILogger _logger;

View File

@ -41,6 +41,7 @@ namespace BankYouBankruptDatabaseImplement.Models
public CardViewModel GetViewModel => new()
{
Id = Id,
AccountId = AccountId,
ClientID = ClientID,
ClientSurname = Client.Surname,
Number = Number,
@ -53,6 +54,7 @@ namespace BankYouBankruptDatabaseImplement.Models
return new Card()
{
Id = model.Id,
AccountId = model.AccountId,
ClientID = model.ClientID,
Client = context.Clients.First(x => x.Id == model.ClientID),
Number = model.Number,

View File

@ -21,7 +21,7 @@ builder.Services.AddTransient<IDebitingStorage, DebitingStorage>();
builder.Services.AddTransient<ICashWithdrawalStorage, CashWithdrawalStorage>();
builder.Services.AddTransient<IClientLogic, ClientLogic>();
builder.Services.AddTransient<IAccountLogic, CashierLogic>();
builder.Services.AddTransient<ICashierLogic, CashierLogic>();
builder.Services.AddTransient<IAccountLogic, AccountLogic>();
builder.Services.AddTransient<ICardLogic, CardLogic>();
builder.Services.AddTransient<ICreditingLogic, CreditingLogic>();