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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 20:46:40 +04:00
|
|
|
|
//получаем все имеющиеся счета
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public AccountViewModel? GetAccount(int accountId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _accountLogic.ReadElement(new AccountSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = accountId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 00:06:05 +04:00
|
|
|
|
[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
|
|
|
|
|
2023-05-18 12:19:37 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<CashWithdrawalViewModel>? FindAllCashWithdrawal()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _cashLogic.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<MoneyTransferViewModel>? FindAllMoneyTransfer()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _moneyTransferLogic.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//найти все открытые заявки на снятие средств
|
|
|
|
|
[HttpGet]
|
2023-05-14 19:07:43 +04:00
|
|
|
|
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
|
|
|
|
|
{
|
2023-05-17 20:00:17 +04:00
|
|
|
|
bool flag =_accountLogic.ChangeBalance(new AccountSearchModel
|
2023-05-16 20:11:29 +04:00
|
|
|
|
{
|
|
|
|
|
Id = CashWithdrawal.AccountId
|
|
|
|
|
}, CashWithdrawal.Sum * -1);
|
2023-05-17 20:00:17 +04:00
|
|
|
|
|
|
|
|
|
_cashLogic.Create(CashWithdrawal, flag);
|
2023-05-14 20:22:27 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-16 21:55:36 +04:00
|
|
|
|
|
2023-05-17 20:00:17 +04:00
|
|
|
|
//подтверждение заявки на перевод либо пополнение балланса
|
2023-05-16 21:55:36 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CloseCrediting(MoneyTransferBindingModel moneyTransfer)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_moneyTransferLogic.Create(moneyTransfer);
|
|
|
|
|
|
2023-05-17 20:00:17 +04:00
|
|
|
|
bool flag = true;
|
|
|
|
|
|
2023-05-17 22:13:56 +04:00
|
|
|
|
//если есть отправитель, т. е. операция на перевод денег со счёта на счёт
|
2023-05-16 21:55:36 +04:00
|
|
|
|
if (moneyTransfer.AccountSenderId.HasValue)
|
|
|
|
|
{
|
2023-05-17 20:00:17 +04:00
|
|
|
|
flag = _accountLogic.ChangeBalance(new AccountSearchModel
|
2023-05-16 21:55:36 +04:00
|
|
|
|
{
|
|
|
|
|
Id = moneyTransfer.AccountSenderId
|
|
|
|
|
}, moneyTransfer.Sum * -1);
|
|
|
|
|
}
|
2023-05-16 23:06:28 +04:00
|
|
|
|
|
2023-05-17 20:00:17 +04:00
|
|
|
|
if (flag)
|
|
|
|
|
{
|
|
|
|
|
_accountLogic.ChangeBalance(new AccountSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = moneyTransfer.AccountPayeeId
|
|
|
|
|
}, moneyTransfer.Sum);
|
|
|
|
|
}
|
|
|
|
|
else
|
2023-05-16 23:06:28 +04:00
|
|
|
|
{
|
2023-05-17 20:00:17 +04:00
|
|
|
|
throw new Exception("Недостаточно средств");
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 21:55:36 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-17 18:26:43 +04:00
|
|
|
|
|
2023-05-17 19:18:50 +04:00
|
|
|
|
//поиск заявки на зачисление по id
|
2023-05-17 18:26:43 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public CreditingViewModel FindCrediting(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _creditingLogic.ReadElement(new CreditingSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-17 19:18:50 +04:00
|
|
|
|
|
|
|
|
|
//поиск заявки на снятие по id
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public DebitingViewModel FindDebiting(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _debitingLogic.ReadElement(new DebitingSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-14 13:30:15 +04:00
|
|
|
|
}
|
|
|
|
|
}
|