From a94d30e65dde6da3d8172e1a98b85845ef30574a Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 14 May 2023 14:00:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/CardLogic.cs | 20 ++++++++++++++++--- .../BusinessLogics/CashierLogic.cs | 2 +- .../Models/Card.cs | 4 +++- .../BankYouBankruptRestAPI/Program.cs | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CardLogic.cs b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CardLogic.cs index b254ac3..c456e48 100644 --- a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CardLogic.cs +++ b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CardLogic.cs @@ -16,10 +16,12 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly ICardStorage _cardStorage; + private readonly IAccountStorage _accountStorage; - public CardLogic(ILogger logger, ICardStorage cardStorage) { + public CardLogic(ILogger 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); } diff --git a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashierLogic.cs b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashierLogic.cs index 2ebe3d1..d7e810c 100644 --- a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashierLogic.cs +++ b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashierLogic.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace BankYouBankruptBusinessLogic.BusinessLogics { - public class CashierLogic : IAccountLogic + public class CashierLogic : ICashierLogic { private readonly ILogger _logger; diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Card.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Card.cs index 8194ca3..b7790d5 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Card.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Card.cs @@ -41,7 +41,8 @@ namespace BankYouBankruptDatabaseImplement.Models public CardViewModel GetViewModel => new() { Id = Id, - ClientID = ClientID, + AccountId = AccountId, + ClientID = ClientID, ClientSurname = Client.Surname, Number = Number, Period = Period, @@ -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, diff --git a/BankYouBankrupt/BankYouBankruptRestAPI/Program.cs b/BankYouBankrupt/BankYouBankruptRestAPI/Program.cs index 2247491..c00d53b 100644 --- a/BankYouBankrupt/BankYouBankruptRestAPI/Program.cs +++ b/BankYouBankrupt/BankYouBankruptRestAPI/Program.cs @@ -21,7 +21,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient();