Снова продвижение.

This commit is contained in:
Programmist73 2023-05-14 20:22:27 +04:00
parent 0d96bd546e
commit a3dee70b4b
6 changed files with 53 additions and 7 deletions

View File

@ -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<CashWithdrawalLogic> logger, ICashWithdrawalStorage cashWithdrawalStorage)
private readonly IDebitingStorage _debitingStorage;
public CashWithdrawalLogic(ILogger<CashWithdrawalLogic> 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));
}

View File

@ -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;
}

View File

@ -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; }

View File

@ -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,7 +97,10 @@ 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
{

View File

@ -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
};

View File

@ -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<AccountController> logger)
private readonly ICashWithdrawalLogic _cashLogic;
public AccountController(IAccountLogic accountLogic, IDebitingLogic debitingLogic, ICashWithdrawalLogic cashLogic, ILogger<AccountController> 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;
}
}
}
}