diff --git a/Bank/BankRestApi/Controllers/AccountController.cs b/Bank/BankRestApi/Controllers/AccountController.cs new file mode 100644 index 0000000..990e762 --- /dev/null +++ b/Bank/BankRestApi/Controllers/AccountController.cs @@ -0,0 +1,96 @@ +using BankContracts.BindingModels; +using BankContracts.BusinessLogicsContracts; +using BankContracts.SearchModels; +using BankContracts.ViewModels; +using BankDatabaseImplement.Models; +using Microsoft.AspNetCore.Mvc; + +namespace BankRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class AccountController : Controller + { + private readonly ILogger _logger; + private readonly IAccountLogic _logic; + + public AccountController(ILogger logger, IAccountLogic logic) + { + _logger = logger; + _logic = logic; + } + + [HttpGet] + public List? GetAccountList() + { + try + { + return _logic.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка счетов"); + throw; + } + } + + [HttpGet] + public AccountViewModel? GetAccount(int AccountId) + { + try + { + return _logic.ReadElement(new AccountSearchModel + { + Id = AccountId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения счета по Id={Id}", AccountId); + throw; + } + } + + [HttpPost] + public void CreateAccount(AccountBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания счета"); + throw; + } + } + + [HttpPut] + public void UpdateAccount(AccountBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления счета"); + throw; + } + } + + [HttpDelete] + public void DeleteAccount(AccountBindingModel model) + { + try + { + _logic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления счета"); + throw; + } + } + } +} diff --git a/Bank/BankRestApi/Controllers/MainController.cs b/Bank/BankRestApi/Controllers/MainController.cs index f2ee0e7..1586700 100644 --- a/Bank/BankRestApi/Controllers/MainController.cs +++ b/Bank/BankRestApi/Controllers/MainController.cs @@ -49,7 +49,8 @@ namespace BankRestApi.Controllers { Id = ClientId }); - }catch (Exception ex) + } + catch (Exception ex) { _logger.LogError(ex, "Ошибка получения клиента по Id={Id}", ClientId); throw; diff --git a/Bank/BankRestApi/Controllers/ManagerController.cs b/Bank/BankRestApi/Controllers/ManagerController.cs new file mode 100644 index 0000000..161dd78 --- /dev/null +++ b/Bank/BankRestApi/Controllers/ManagerController.cs @@ -0,0 +1,97 @@ +using BankContracts.BindingModels; +using BankContracts.BusinessLogicsContracts; +using BankContracts.SearchModels; +using BankContracts.ViewModels; +using BankDatabaseImplement.Models; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace BankRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ManagerController : Controller + { + private readonly ILogger _logger; + private readonly IManagerLogic _logic; + + public ManagerController(ILogger logger, IManagerLogic logic) + { + _logger = logger; + _logic = logic; + } + + [HttpGet] + public List? GetManagerList() + { + try + { + return _logic.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка менеджеров"); + throw; + } + } + + [HttpGet] + public ManagerViewModel? GetManager(int ManagerId) + { + try + { + return _logic.ReadElement(new ManagerSearchModel + { + Id = ManagerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения менеджера по Id={Id}", ManagerId); + throw; + } + } + + [HttpPost] + public void CreateManager(ManagerBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания менеджера"); + throw; + } + } + + [HttpPut] + public void UpdateManager(ManagerBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления менеджера"); + throw; + } + } + + [HttpDelete] + public void DeleteManager(ManagerBindingModel model) + { + try + { + _logic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления менеджера"); + throw; + } + } + } +} diff --git a/Bank/BankRestApi/Controllers/TransferController.cs b/Bank/BankRestApi/Controllers/TransferController.cs new file mode 100644 index 0000000..6461c7e --- /dev/null +++ b/Bank/BankRestApi/Controllers/TransferController.cs @@ -0,0 +1,93 @@ +using BankContracts.BindingModels; +using BankContracts.BusinessLogicsContracts; +using BankContracts.SearchModels; +using BankContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace BankRestApi.Controllers +{ + public class TransferController : Controller + { + private readonly ILogger _logger; + private readonly ITransferLogic _logic; + + public TransferController(ILogger logger, ITransferLogic logic) + { + _logger = logger; + _logic = logic; + } + + [HttpGet] + public List? getTransferList() + { + try + { + return _logic.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка переводов"); + throw; + } + } + + [HttpGet] + public TransferViewModel? GetTransfer(int TransferId) + { + try + { + return _logic.ReadElement(new TransferSearchModel + { + Id = TransferId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения перевода по Id={Id}", TransferId); + throw; + } + } + + [HttpPost] + public void CreateTransfer(TransferBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания перевода"); + throw; + } + } + + [HttpPut] + public void UpdateTransfer(TransferBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления перевода"); + throw; + } + } + + [HttpDelete] + public void DeleteTransfer(TransferBindingModel model) + { + try + { + _logic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления перевода"); + throw; + } + } + } +} diff --git a/Bank/BankRestApi/Controllers/WithdrawalController.cs b/Bank/BankRestApi/Controllers/WithdrawalController.cs new file mode 100644 index 0000000..5716525 --- /dev/null +++ b/Bank/BankRestApi/Controllers/WithdrawalController.cs @@ -0,0 +1,93 @@ +using BankContracts.BindingModels; +using BankContracts.BusinessLogicsContracts; +using BankContracts.SearchModels; +using BankContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace BankRestApi.Controllers +{ + public class WithdrawalController : Controller + { + private readonly ILogger _logger; + private readonly IWithdrawalLogic _logic; + + public WithdrawalController(ILogger logger, IWithdrawalLogic logic) + { + _logger = logger; + _logic = logic; + } + + [HttpGet] + public List? getWithdrawalList() + { + try + { + return _logic.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка выдач"); + throw; + } + } + + [HttpGet] + public WithdrawalViewModel? GetWithdrawal(int WithdrawalId) + { + try + { + return _logic.ReadElement(new WithdrawalSearchModel + { + Id = WithdrawalId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения выдачи по Id={Id}", WithdrawalId); + throw; + } + } + + [HttpPost] + public void CreateWithdrawal(WithdrawalBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания выдачи"); + throw; + } + } + + [HttpPut] + public void UpdateWithdrawal(WithdrawalBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления выдачи"); + throw; + } + } + + [HttpDelete] + public void DeleteWithdrawal(WithdrawalBindingModel model) + { + try + { + _logic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления выдачи"); + throw; + } + } + } +}