2023-05-16 20:11:29 +04:00
|
|
|
|
using BankYouBankruptBusinessLogic.BusinessLogics;
|
|
|
|
|
using BankYouBankruptContracts.BindingModels;
|
2023-05-14 13:30:15 +04:00
|
|
|
|
using BankYouBankruptContracts.BusinessLogicsContracts;
|
|
|
|
|
using BankYouBankruptContracts.SearchModels;
|
|
|
|
|
using BankYouBankruptContracts.ViewModels;
|
2023-05-14 20:22:27 +04:00
|
|
|
|
using BankYouBankruptDatabaseImplement.Models;
|
2023-05-14 19:07:43 +04:00
|
|
|
|
using BankYouBankruptDataModels.Enums;
|
2023-05-14 13:30:15 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace BankYouBankruptRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
//указание у контроллера, что Route будет строиться не только по наванию контроллера, но и по названию метода (так как у нас два Post-метода)
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class AccountController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
private readonly IAccountLogic _accountLogic;
|
|
|
|
|
|
2023-05-14 19:07:43 +04:00
|
|
|
|
private readonly IDebitingLogic _debitingLogic;
|
|
|
|
|
|
2023-05-16 21:55:36 +04:00
|
|
|
|
private readonly ICreditingLogic _creditingLogic;
|
|
|
|
|
|
2023-05-14 20:22:27 +04:00
|
|
|
|
private readonly ICashWithdrawalLogic _cashLogic;
|
|
|
|
|
|
2023-05-16 21:55:36 +04:00
|
|
|
|
private readonly IMoneyTransferLogic _moneyTransferLogic;
|
|
|
|
|
|
|
|
|
|
public AccountController(IAccountLogic accountLogic, IDebitingLogic debitingLogic, ICashWithdrawalLogic cashLogic,
|
|
|
|
|
ICreditingLogic creditingLogic, IMoneyTransferLogic moneyTransferLogic, ILogger<AccountController> logger)
|
2023-05-14 13:30:15 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_accountLogic = accountLogic;
|
2023-05-14 19:07:43 +04:00
|
|
|
|
_debitingLogic = debitingLogic;
|
2023-05-14 20:22:27 +04:00
|
|
|
|
_cashLogic = cashLogic;
|
2023-05-16 21:55:36 +04:00
|
|
|
|
_creditingLogic = creditingLogic;
|
|
|
|
|
_moneyTransferLogic = moneyTransferLogic;
|
2023-05-14 13:30:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public AccountViewModel? Login(string accountNumber, string passwordAccount)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//попытка найти запись по переданным номеру и паролю счёта
|
|
|
|
|
return _accountLogic.ReadElement(new AccountSearchModel
|
|
|
|
|
{
|
|
|
|
|
AccountNumber = accountNumber,
|
|
|
|
|
PasswordAccount = passwordAccount
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 00:06:05 +04:00
|
|
|
|
//получаем все имеющиеся счета
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<AccountViewModel>? GetAllAccounts()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _accountLogic.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-14 13:30:15 +04:00
|
|
|
|
public void Register(AccountBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//создание счёта
|
|
|
|
|
_accountLogic.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка регистрации");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateData(AccountBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//изменение счёта
|
|
|
|
|
_accountLogic.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления данных");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-14 13:31:41 +04:00
|
|
|
|
//найти все счета, которые создал конкретный кассир
|
2023-05-14 13:30:15 +04:00
|
|
|
|
[HttpGet]
|
2023-05-14 13:31:41 +04:00
|
|
|
|
public List<AccountViewModel>? SearchAccounts(int cashierId)
|
2023-05-14 13:30:15 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _accountLogic.ReadList(new AccountSearchModel
|
|
|
|
|
{
|
|
|
|
|
CashierId = cashierId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-14 13:31:41 +04:00
|
|
|
|
|
|
|
|
|
//найти все счета клиента
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<AccountViewModel>? SearchAccountsOfCLient(int clientId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//попытка найти запись по переданным номеру и паролю счёта
|
|
|
|
|
return _accountLogic.ReadList(new AccountSearchModel
|
|
|
|
|
{
|
|
|
|
|
ClientId = clientId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-14 19:07:43 +04:00
|
|
|
|
|
|
|
|
|
//найти все открытые заявки на снятие средств
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<DebitingViewModel>? FindOpenDebiting()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _debitingLogic.ReadList(new DebitingSearchModel
|
|
|
|
|
{
|
|
|
|
|
Status = StatusEnum.Открыта
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-14 20:22:27 +04:00
|
|
|
|
|
2023-05-16 21:55:36 +04:00
|
|
|
|
//найти все открытые заявки на снятие средств
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<CreditingViewModel>? FindOpenCrediting()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _creditingLogic.ReadList(new CreditingSearchModel
|
|
|
|
|
{
|
|
|
|
|
Status = StatusEnum.Открыта
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-14 20:22:27 +04:00
|
|
|
|
//подтверждение заявки на снятие средств со счёта
|
|
|
|
|
[HttpPost]
|
2023-05-16 21:55:36 +04:00
|
|
|
|
public void CloseDebiting(CashWithdrawalBindingModel CashWithdrawal)
|
2023-05-14 20:22:27 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_cashLogic.Create(CashWithdrawal);
|
2023-05-16 20:11:29 +04:00
|
|
|
|
|
|
|
|
|
_accountLogic.ChangeBalance(new AccountSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = CashWithdrawal.AccountId
|
|
|
|
|
}, CashWithdrawal.Sum * -1);
|
2023-05-14 20:22:27 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-16 21:55:36 +04:00
|
|
|
|
|
|
|
|
|
//подтверждение заявки на снятие средств со счёта
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CloseCrediting(MoneyTransferBindingModel moneyTransfer)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_moneyTransferLogic.Create(moneyTransfer);
|
|
|
|
|
|
|
|
|
|
//если нет отправителя, т. е. операция на перевод денег из нала в виртуал на карту
|
|
|
|
|
if (moneyTransfer.AccountSenderId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
_accountLogic.ChangeBalance(new AccountSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = moneyTransfer.AccountSenderId
|
|
|
|
|
}, moneyTransfer.Sum * -1);
|
|
|
|
|
}
|
2023-05-16 23:06:28 +04:00
|
|
|
|
|
|
|
|
|
_accountLogic.ChangeBalance(new AccountSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = moneyTransfer.AccountPayeeId
|
|
|
|
|
}, moneyTransfer.Sum);
|
2023-05-16 21:55:36 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-14 13:30:15 +04:00
|
|
|
|
}
|
|
|
|
|
}
|