From 8b96d82fa24a106d3f3e292f39d2899a3405bc5c Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sat, 20 May 2023 03:34:28 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D0=BF?= =?UTF-8?q?=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/CashWithdrawalLogic.cs | 58 +++++++++++++++---- .../Controllers/HomeController.cs | 11 ++-- .../Views/Home/ReportWithCards.cshtml | 4 +- .../Enums/StatusEnum.cs | 4 +- 4 files changed, 61 insertions(+), 16 deletions(-) diff --git a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashWithdrawalLogic.cs b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashWithdrawalLogic.cs index 2495f23..0245ebe 100644 --- a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashWithdrawalLogic.cs +++ b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashWithdrawalLogic.cs @@ -21,11 +21,15 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics private readonly IDebitingStorage _debitingStorage; - public CashWithdrawalLogic(ILogger logger, ICashWithdrawalStorage cashWithdrawalStorage, IDebitingStorage debitingStorage) + private readonly ICardStorage _cardStorage; + + public CashWithdrawalLogic(ILogger logger, ICashWithdrawalStorage cashWithdrawalStorage, + IDebitingStorage debitingStorage, ICardStorage cardStorage) { _logger = logger; _cashWithdrawalStorage = cashWithdrawalStorage; _debitingStorage = debitingStorage; + _cardStorage = cardStorage; } public CashWithdrawalViewModel? ReadElement(CashWithdrawalSearchModel model) @@ -77,19 +81,32 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics if (flag) { - if (_cashWithdrawalStorage.Insert(model) == null) + //проверка на то, что карта не просрочилась + if (CheckCardPeriod(model)) { - _logger.LogWarning("Insert operation failed"); + if (_cashWithdrawalStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); - return false; + return false; + } + + _debitingStorage.Update(new DebitingBindingModel + { + Id = model.DebitingId, + DateClose = DateTime.Now, + Status = StatusEnum.Закрыта + }); } - - _debitingStorage.Update(new DebitingBindingModel + else { - Id = model.DebitingId, - DateClose = DateTime.Now, - Status = StatusEnum.Закрыта - }); + _debitingStorage.Update(new DebitingBindingModel + { + Id = model.DebitingId, + DateClose = DateTime.Now, + Status = StatusEnum.Карта_просрочена + }); + } } else { @@ -169,5 +186,26 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics _logger.LogInformation("CashWithdrawal: AccountId:{AccountId}. Sum:{Sum}. DateOperation:{DateOperation}. Id:{Id}", model.AccountId, model.Sum, model.DateOperation, model?.Id); } + + bool CheckCardPeriod(CashWithdrawalBindingModel model) + { + var debiting = _debitingStorage.GetElement(new DebitingSearchModel + { + Id = model.DebitingId + }); + + var card = _cardStorage.GetElement(new CardSearchModel + { + Id = debiting.CardId + }); + + //если карта просрочена + if(card.Period < DateTime.Now) + { + return false; + } + + return true; + } } } diff --git a/BankYouBankrupt/BankYouBankruptClientApp/Controllers/HomeController.cs b/BankYouBankrupt/BankYouBankruptClientApp/Controllers/HomeController.cs index d86b531..111537d 100644 --- a/BankYouBankrupt/BankYouBankruptClientApp/Controllers/HomeController.cs +++ b/BankYouBankrupt/BankYouBankruptClientApp/Controllers/HomeController.cs @@ -14,7 +14,6 @@ using System.Collections; using System.Diagnostics; using System.Reflection; using System.Xml.Linq; -using static System.Net.Mime.MediaTypeNames; namespace BankYouBankruptClientApp.Controllers { @@ -497,9 +496,11 @@ namespace BankYouBankruptClientApp.Controllers Operations = result, }); } - #endregion + #endregion - [HttpGet] + #region Диаграмма + + [HttpGet] public IActionResult Diagram() { if (APIClient.Client == null) { @@ -527,5 +528,7 @@ namespace BankYouBankruptClientApp.Controllers Elements = APIClient.GetRequest>($"api/Card/getCardMonthResult?cardId={cardId}") }); } - } + + #endregion + } } \ No newline at end of file diff --git a/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/ReportWithCards.cshtml b/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/ReportWithCards.cshtml index 5ca2fa5..b97e59a 100644 --- a/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/ReportWithCards.cshtml +++ b/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/ReportWithCards.cshtml @@ -1,4 +1,6 @@ @using BankYouBankruptContracts.ViewModels.Client.Reports; +@using Microsoft.JSInterop; +@inject IJSRuntime JS @model ReportClientCardsViewModel @@ -105,4 +107,4 @@ - \ No newline at end of file + diff --git a/BankYouBankrupt/BankYouBankruptDataModels/Enums/StatusEnum.cs b/BankYouBankrupt/BankYouBankruptDataModels/Enums/StatusEnum.cs index d60a177..0048351 100644 --- a/BankYouBankrupt/BankYouBankruptDataModels/Enums/StatusEnum.cs +++ b/BankYouBankrupt/BankYouBankruptDataModels/Enums/StatusEnum.cs @@ -12,6 +12,8 @@ namespace BankYouBankruptDataModels.Enums Закрыта = 1, - Отклонено = 2 + Отклонено = 2, + + Карта_просрочена = 3 } }