diff --git a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashWithdrawalLogic.cs b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashWithdrawalLogic.cs index 0245ebe..e916c94 100644 --- a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashWithdrawalLogic.cs +++ b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashWithdrawalLogic.cs @@ -21,15 +21,12 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics private readonly IDebitingStorage _debitingStorage; - private readonly ICardStorage _cardStorage; - public CashWithdrawalLogic(ILogger logger, ICashWithdrawalStorage cashWithdrawalStorage, - IDebitingStorage debitingStorage, ICardStorage cardStorage) + IDebitingStorage debitingStorage) { _logger = logger; _cashWithdrawalStorage = cashWithdrawalStorage; _debitingStorage = debitingStorage; - _cardStorage = cardStorage; } public CashWithdrawalViewModel? ReadElement(CashWithdrawalSearchModel model) @@ -81,32 +78,19 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics if (flag) { - //проверка на то, что карта не просрочилась - if (CheckCardPeriod(model)) + if (_cashWithdrawalStorage.Insert(model) == null) { - if (_cashWithdrawalStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); + _logger.LogWarning("Insert operation failed"); - return false; - } - - _debitingStorage.Update(new DebitingBindingModel - { - Id = model.DebitingId, - DateClose = DateTime.Now, - Status = StatusEnum.Закрыта - }); + return false; } - else + + _debitingStorage.Update(new DebitingBindingModel { - _debitingStorage.Update(new DebitingBindingModel - { - Id = model.DebitingId, - DateClose = DateTime.Now, - Status = StatusEnum.Карта_просрочена - }); - } + Id = model.DebitingId, + DateClose = DateTime.Now, + Status = StatusEnum.Закрыта + }); } else { @@ -186,26 +170,5 @@ 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/BankYouBankruptBusinessLogic/BusinessLogics/CreditingLogic.cs b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CreditingLogic.cs index ea54126..6fb7a0e 100644 --- a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CreditingLogic.cs +++ b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CreditingLogic.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using BankYouBankruptContracts.ViewModels.Client.Default; +using BankYouBankruptDataModels.Enums; namespace BankYouBankruptBusinessLogic.BusinessLogics { @@ -16,16 +17,27 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly ICreditingStorage _creditingStorage; + private readonly ICardStorage _cardStorage; - public CreditingLogic(ILogger logger, ICreditingStorage creditingStorage) { + public CreditingLogic(ILogger logger, ICreditingStorage creditingStorage, ICardStorage cardStorage) { _logger = logger; _creditingStorage = creditingStorage; + _cardStorage = cardStorage; } public bool Create(CreditingBindingModel model) { CheckModel(model); + if (!CheckCardPeriod(model)) + { + model.Status = StatusEnum.Карта_просрочена; + } + else + { + model.Status = StatusEnum.Открыта; + } + if (_creditingStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -111,5 +123,22 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics _logger.LogInformation("Crediting. Sum:{Sum}.CardId:{CardId}.Date:{date}.Id:{Id}", model.Sum, model.CardId, model.DateOpen.ToString(), model.Id); } - } + + //проверка карты на просроченность + bool CheckCardPeriod(CreditingBindingModel model) + { + var card = _cardStorage.GetElement(new CardSearchModel + { + Id = model.CardId + }); + + //если карта просрочена + if (card.Period < DateTime.Now) + { + return false; + } + + return true; + } + } } diff --git a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/DebitingLogic.cs b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/DebitingLogic.cs index c3e5d49..95331e0 100644 --- a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/DebitingLogic.cs +++ b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/DebitingLogic.cs @@ -9,27 +9,43 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using BankYouBankruptContracts.ViewModels.Client.Default; +using BankYouBankruptDataModels.Enums; namespace BankYouBankruptBusinessLogic.BusinessLogics { public class DebitingLogic : IDebitingLogic { private readonly ILogger _logger; + private readonly IDebitingStorage _debitingStorage; - public DebitingLogic(ILogger logger, IDebitingStorage debitingStorage) { + private readonly ICardStorage _cardStorage; + + public DebitingLogic(ILogger logger, IDebitingStorage debitingStorage, ICardStorage cardStorage) { _logger = logger; _debitingStorage = debitingStorage; + _cardStorage = cardStorage; } public bool Create(DebitingBindingModel model) { CheckModel(model); - if (_debitingStorage.Insert(model) == null) + + if (!CheckCardPeriod(model)) + { + model.Status = StatusEnum.Карта_просрочена; + } + else + { + model.Status = StatusEnum.Открыта; + } + + if (_debitingStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; } + return true; } @@ -111,5 +127,22 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics _logger.LogInformation("Debiting. Sum:{Sum}.CardId:{CardId}.DateOpen:{DateOpen}.DateOpen:{DateOpen}.Id:{Id}", model.Sum, model.CardId, model.DateOpen.ToString(), model.DateClose.ToString(), model.Id); } - } + + //проверка карты на просроченность + bool CheckCardPeriod(DebitingBindingModel model) + { + var card = _cardStorage.GetElement(new CardSearchModel + { + Id = model.CardId + }); + + //если карта просрочена + if (card.Period < DateTime.Now) + { + return false; + } + + return true; + } + } } diff --git a/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/CreditingList.cshtml b/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/CreditingList.cshtml index 54649be..9b7d1b0 100644 --- a/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/CreditingList.cshtml +++ b/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/CreditingList.cshtml @@ -1,4 +1,5 @@ @using BankYouBankruptContracts.ViewModels.Client.Default +@using BankYouBankruptDataModels.Enums; @model List @@ -51,7 +52,7 @@ @Html.DisplayFor(modelItem => item.Sum) - @Html.DisplayFor(modelItem => item.Status) + @item.Status.ToString().Replace("_", " ") @Html.DisplayFor(modelItem => item.DateOpen) diff --git a/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/DebitingList.cshtml b/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/DebitingList.cshtml index 6956490..45e0ba7 100644 --- a/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/DebitingList.cshtml +++ b/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/DebitingList.cshtml @@ -51,7 +51,7 @@ @Html.DisplayFor(modelItem => item.Sum) - @Html.DisplayFor(modelItem => item.Status) + @item.Status.ToString().Replace("_", " ") @Html.DisplayFor(modelItem => item.DateOpen) diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Crediting.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Crediting.cs index 0f57947..5c2a9dd 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Crediting.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Crediting.cs @@ -56,7 +56,8 @@ namespace BankYouBankruptDatabaseImplement.Models CardId = model.CardId, Card = context.Cards.First(x => x.Id == model.CardId), Sum = model.Sum, - DateOpen = model.DateOpen + DateOpen = model.DateOpen, + Status = model.Status }; } diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Debiting.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Debiting.cs index b77b3c6..ffaf097 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Debiting.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Debiting.cs @@ -51,7 +51,7 @@ namespace BankYouBankruptDatabaseImplement.Models Card = context.Cards.First(x => x.Id == model.CardId), Sum = model.Sum, DateOpen = model.DateOpen, - Status = StatusEnum.Открыта + Status = model.Status }; } diff --git a/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CardController.cs b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CardController.cs index d60b8dc..12b1f3b 100644 --- a/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CardController.cs +++ b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CardController.cs @@ -48,7 +48,6 @@ namespace BankYouBankruptRestApi.Controllers } - [HttpGet] public List? GetUsersCardsList(int id) { diff --git a/BankYouBankrupt/BankYouBankruptRestAPI/Отчёт по снятиям.docx b/BankYouBankrupt/BankYouBankruptRestAPI/Отчёт по снятиям.docx index bbd9c22..1dbe712 100644 Binary files a/BankYouBankrupt/BankYouBankruptRestAPI/Отчёт по снятиям.docx and b/BankYouBankrupt/BankYouBankruptRestAPI/Отчёт по снятиям.docx differ