diff --git a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashWithdrawalLogic.cs b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashWithdrawalLogic.cs index 800f2c5..dd071bc 100644 --- a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashWithdrawalLogic.cs +++ b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashWithdrawalLogic.cs @@ -3,6 +3,7 @@ using BankYouBankruptContracts.BusinessLogicsContracts; using BankYouBankruptContracts.SearchModels; using BankYouBankruptContracts.StoragesContracts; using BankYouBankruptContracts.ViewModels; +using BankYouBankruptDataModels.Enums; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -18,10 +19,13 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics private readonly ICashWithdrawalStorage _cashWithdrawalStorage; - public CashWithdrawalLogic(ILogger logger, ICashWithdrawalStorage cashWithdrawalStorage) + private readonly IDebitingStorage _debitingStorage; + + public CashWithdrawalLogic(ILogger logger, ICashWithdrawalStorage cashWithdrawalStorage, IDebitingStorage debitingStorage) { _logger = logger; _cashWithdrawalStorage = cashWithdrawalStorage; + _debitingStorage = debitingStorage; } public CashWithdrawalViewModel? ReadElement(CashWithdrawalSearchModel model) @@ -78,6 +82,13 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics return false; } + _debitingStorage.Update(new DebitingBindingModel + { + Id = model.DebitingId, + DateClose = DateTime.Now, + Status = StatusEnum.Закрыта + }); + return true; } @@ -126,7 +137,7 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics } //проверка на корректность Id счёта - if (model.AccountId > 0) + if (model.AccountId < 0) { throw new ArgumentNullException("Некорректный Id счёта", nameof(model.AccountId)); } diff --git a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/DebitingLogic.cs b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/DebitingLogic.cs index 42df87a..ef4aa56 100644 --- a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/DebitingLogic.cs +++ b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/DebitingLogic.cs @@ -78,11 +78,14 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics public bool Update(DebitingBindingModel model) { CheckModel(model); + if (_debitingStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); + return false; } + return true; } diff --git a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/CashWithdrawalViewModel.cs b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/CashWithdrawalViewModel.cs index b39d5e4..5545a84 100644 --- a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/CashWithdrawalViewModel.cs +++ b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/CashWithdrawalViewModel.cs @@ -20,7 +20,7 @@ namespace BankYouBankruptContracts.ViewModels public int AccountId { get; set; } [DisplayName("Номер счёта")] - public int AccountNumber { get; set; } + public string AccountNumber { get; set; } = string.Empty; public int CashierId { get; set; } diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/DebitingStorage.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/DebitingStorage.cs index 5ca7324..06db9c9 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/DebitingStorage.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/DebitingStorage.cs @@ -88,7 +88,7 @@ namespace BankYouBankruptDatabaseImplement.Implements { var debiting = context.Debitings.FirstOrDefault(rec => rec.Id == model.Id); - if (debiting == null) + if (debiting == null && debiting.Status == StatusEnum.Закрыта) { return null; } @@ -97,8 +97,11 @@ namespace BankYouBankruptDatabaseImplement.Implements context.SaveChanges(); transaction.Commit(); - return debiting.GetViewModel; - } + return context.Debitings + .Include(x => x.Card) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } catch { transaction.Rollback(); diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/CashWithdrawal.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/CashWithdrawal.cs index 8d96b14..89c3bdb 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/CashWithdrawal.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/CashWithdrawal.cs @@ -45,6 +45,11 @@ namespace BankYouBankruptDatabaseImplement.Models { Id = model.Id, AccountId = model.AccountId, + Account = context.Accounts.First(x => x.Id == model.AccountId), + DebitingId = model.DebitingId, + Debiting = context.Debitings.First(x => x.Id == model.DebitingId), + CashierId = model.CashierId, + Cashier = context.Cashiers.First(x => x.Id == model.CashierId), Sum = model.Sum, DateOperation = model.DateOperation }; @@ -59,6 +64,11 @@ namespace BankYouBankruptDatabaseImplement.Models { Id = Id, AccountId = AccountId, + CashierId = CashierId, + DebitingId = DebitingId, + AccountNumber = Account.AccountNumber, + SurmaneCashier = Cashier.Surname, + DebbitingNumber = Debiting.Id, Sum = Sum, DateOperation = DateOperation }; diff --git a/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/AccountController.cs b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/AccountController.cs index a3330ac..a37cbe8 100644 --- a/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/AccountController.cs +++ b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/AccountController.cs @@ -2,6 +2,7 @@ using BankYouBankruptContracts.BusinessLogicsContracts; using BankYouBankruptContracts.SearchModels; using BankYouBankruptContracts.ViewModels; +using BankYouBankruptDatabaseImplement.Models; using BankYouBankruptDataModels.Enums; using Microsoft.AspNetCore.Mvc; @@ -18,11 +19,14 @@ namespace BankYouBankruptRestApi.Controllers private readonly IDebitingLogic _debitingLogic; - public AccountController(IAccountLogic accountLogic, IDebitingLogic debitingLogic, ILogger logger) + private readonly ICashWithdrawalLogic _cashLogic; + + public AccountController(IAccountLogic accountLogic, IDebitingLogic debitingLogic, ICashWithdrawalLogic cashLogic, ILogger logger) { _logger = logger; _accountLogic = accountLogic; _debitingLogic = debitingLogic; + _cashLogic = cashLogic; } [HttpGet] @@ -128,5 +132,20 @@ namespace BankYouBankruptRestApi.Controllers throw; } } + + //подтверждение заявки на снятие средств со счёта + [HttpPost] + public void CloseApplication(CashWithdrawalBindingModel CashWithdrawal) + { + try + { + _cashLogic.Create(CashWithdrawal); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } } }