From eae58286194413014cdf5f0a4b827006607c9f71 Mon Sep 17 00:00:00 2001 From: ksenianeva <95441235+ksenianeva@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:27:26 +0400 Subject: [PATCH] =?UTF-8?q?Controllers=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=BE?= =?UTF-8?q?=D0=BB=D0=B8=20=D0=9F=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D1=89=D0=B8?= =?UTF-8?q?=D0=BA.=20=D0=A4=D0=B8=D0=BA=D1=81=20GetElement=20=D0=B2=20Bank?= =?UTF-8?q?OperatorStorage.=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20Password=20=D0=B2=20=D1=81=D0=BE=D0=BE?= =?UTF-8?q?=D1=82=D0=B2=D0=B5=D1=82=D1=81=D1=82=D0=B2=D1=83=D1=8E=D1=89?= =?UTF-8?q?=D1=83=D1=8E=20SearchModel.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SearchModels/BankOperatorSearchModel.cs | 1 + .../Implements/BankOperatorStorage.cs | 20 +++- .../Controllers/BankOperatorController.cs | 86 +++++++++++++++++ .../Controllers/CreditProgramController.cs | 94 +++++++++++++++++++ .../Controllers/CurrencyController.cs | 93 ++++++++++++++++++ .../Controllers/CurrencyPurchaseController.cs | 93 ++++++++++++++++++ 6 files changed, 382 insertions(+), 5 deletions(-) create mode 100644 Bank/BankRestApi/Controllers/BankOperatorController.cs create mode 100644 Bank/BankRestApi/Controllers/CreditProgramController.cs create mode 100644 Bank/BankRestApi/Controllers/CurrencyController.cs create mode 100644 Bank/BankRestApi/Controllers/CurrencyPurchaseController.cs diff --git a/Bank/BankContracts/SearchModels/BankOperatorSearchModel.cs b/Bank/BankContracts/SearchModels/BankOperatorSearchModel.cs index 368ba42..ce98fb7 100644 --- a/Bank/BankContracts/SearchModels/BankOperatorSearchModel.cs +++ b/Bank/BankContracts/SearchModels/BankOperatorSearchModel.cs @@ -10,5 +10,6 @@ namespace BankContracts.SearchModels { public int? Id { get; set; } public string? Login { get; set; } + public string? Password { get; set; } } } diff --git a/Bank/BankDatabaseImplement/Implements/BankOperatorStorage.cs b/Bank/BankDatabaseImplement/Implements/BankOperatorStorage.cs index f890965..9517aee 100644 --- a/Bank/BankDatabaseImplement/Implements/BankOperatorStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/BankOperatorStorage.cs @@ -28,14 +28,24 @@ namespace BankDatabaseImplement.Implements public BankOperatorViewModel? GetElement(BankOperatorSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password)) { return null; } - using var context = new BankDatabase(); - return context.BankOperators - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; + if (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password)) + { + using var context = new BankDatabase(); + return context.BankOperators + .FirstOrDefault(x => x.Login == model.Login && x.Password == model.Password) + ?.GetViewModel; + } + else + { + using var context = new BankDatabase(); + return context.BankOperators + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } } public List GetFilteredList(BankOperatorSearchModel model) diff --git a/Bank/BankRestApi/Controllers/BankOperatorController.cs b/Bank/BankRestApi/Controllers/BankOperatorController.cs new file mode 100644 index 0000000..fe7e00a --- /dev/null +++ b/Bank/BankRestApi/Controllers/BankOperatorController.cs @@ -0,0 +1,86 @@ +using BankContracts.BindingModels; +using BankContracts.BusinessLogicsContracts; +using BankContracts.SearchModels; +using BankContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace BankRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class BankOperatorController : Controller + { + private readonly ILogger _logger; + private readonly IBankOperatorLogic _bankOperator; + + public BankOperatorController(ILogger logger, IBankOperatorLogic bankOperatorC) + { + _logger = logger; + _bankOperator = bankOperatorC; + } + + [HttpGet] + public BankOperatorViewModel? Login(string login, string password) + { + try + { + return _bankOperator.ReadElement(new BankOperatorSearchModel + { + Login = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + + [HttpPost] + public void CreateBankOperator(BankOperatorBindingModel model) + { + try + { + _bankOperator.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания зачисления"); + throw; + } + } + + [HttpPatch] + public void UpdateBankOperator(BankOperatorBindingModel model) + { + try + { + _bankOperator.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления зачисления"); + throw; + } + } + [HttpDelete] + public void DeleteBankOperator(int bankOperatorId) + { + try + { + BankOperatorBindingModel model = new BankOperatorBindingModel + { + Id = bankOperatorId + }; + _bankOperator.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления зачисления"); + throw; + } + } + } +} + diff --git a/Bank/BankRestApi/Controllers/CreditProgramController.cs b/Bank/BankRestApi/Controllers/CreditProgramController.cs new file mode 100644 index 0000000..6b165c6 --- /dev/null +++ b/Bank/BankRestApi/Controllers/CreditProgramController.cs @@ -0,0 +1,94 @@ +using BankContracts.BindingModels; +using BankContracts.BusinessLogicsContracts; +using BankContracts.SearchModels; +using BankContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace BankRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class CreditProgramController : Controller + { + private readonly ILogger _logger; + private readonly ICreditProgramLogic _creditProgram; + + public CreditProgramController(ILogger logger, ICreditProgramLogic creditProgram) + { + _logger = logger; + _creditProgram = creditProgram; + } + [HttpGet] + public List? GetCreditProgramsList() + { + try + { + return _creditProgram.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка кредитных программ"); + throw; + } + } + [HttpGet] + public List? GetCreditPrograms(int bankOperatorId) + { + try + { + return _creditProgram.ReadList(new CreditProgramSearchModel { BankOperatorId = bankOperatorId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка кредитных программ оператора id={Id}", bankOperatorId); + throw; + } + } + + [HttpPost] + public void CreateCreditProgram(CreditProgramBindingModel model) + { + try + { + _creditProgram.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания кредитной программы"); + throw; + } + } + + [HttpPatch] + public void UpdateCreditProgram(CreditProgramBindingModel model) + { + try + { + _creditProgram.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления кредитной программы"); + throw; + } + } + [HttpDelete] + public void DeleteCreditProgram(int creditProgramId) + { + try + { + CreditProgramBindingModel model = new CreditProgramBindingModel + { + Id = creditProgramId, + }; + _creditProgram.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления кредитной программы"); + throw; + } + } + } + +} diff --git a/Bank/BankRestApi/Controllers/CurrencyController.cs b/Bank/BankRestApi/Controllers/CurrencyController.cs new file mode 100644 index 0000000..f403ae1 --- /dev/null +++ b/Bank/BankRestApi/Controllers/CurrencyController.cs @@ -0,0 +1,93 @@ +using BankContracts.BindingModels; +using BankContracts.BusinessLogicsContracts; +using BankContracts.SearchModels; +using BankContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace BankRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class CurrencyController : Controller + { + private readonly ILogger _logger; + private readonly ICurrencyLogic _currency; + + public CurrencyController(ILogger logger, ICurrencyLogic currency) + { + _logger = logger; + _currency = currency; + } + [HttpGet] + public List? GetCurrencysList() + { + try + { + return _currency.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка валют"); + throw; + } + } + [HttpGet] + public List? GetCurrencys(int bankOperatorId) + { + try + { + return _currency.ReadList(new CurrencySearchModel { BankOperatorId = bankOperatorId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка валют оператора id={Id}", bankOperatorId); + throw; + } + } + + [HttpPost] + public void CreateCurrency(CurrencyBindingModel model) + { + try + { + _currency.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания валюты"); + throw; + } + } + + [HttpPatch] + public void UpdateCurrency(CurrencyBindingModel model) + { + try + { + _currency.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления валюты"); + throw; + } + } + [HttpDelete] + public void DeleteCurrency(int currencyId) + { + try + { + CurrencyBindingModel model = new CurrencyBindingModel + { + Id = currencyId, + }; + _currency.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления валюты"); + throw; + } + } + } +} diff --git a/Bank/BankRestApi/Controllers/CurrencyPurchaseController.cs b/Bank/BankRestApi/Controllers/CurrencyPurchaseController.cs new file mode 100644 index 0000000..32925cf --- /dev/null +++ b/Bank/BankRestApi/Controllers/CurrencyPurchaseController.cs @@ -0,0 +1,93 @@ +using BankContracts.BindingModels; +using BankContracts.BusinessLogicsContracts; +using BankContracts.SearchModels; +using BankContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace BankRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class CurrencyPurchaseController : Controller + { + private readonly ILogger _logger; + private readonly ICurrencyPurchaseLogic _currencyPurchase; + + public CurrencyPurchaseController(ILogger logger, ICurrencyPurchaseLogic currencyPurchase) + { + _logger = logger; + _currencyPurchase = currencyPurchase; + } + [HttpGet] + public List? GetCurrencyPurchasesList() + { + try + { + return _currencyPurchase.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка закупки валют"); + throw; + } + } + [HttpGet] + public List? GetCurrencyPurchases(int bankOperatorId) + { + try + { + return _currencyPurchase.ReadList(new CurrencyPurchaseSearchModel { BankOperatorId = bankOperatorId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка закупки валют оператора id={Id}", bankOperatorId); + throw; + } + } + + [HttpPost] + public void CreateCurrencyPurchase(CurrencyPurchaseBindingModel model) + { + try + { + _currencyPurchase.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания закупки валют"); + throw; + } + } + + [HttpPatch] + public void UpdateCurrencyPurchase(CurrencyPurchaseBindingModel model) + { + try + { + _currencyPurchase.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления закупки валют"); + throw; + } + } + [HttpDelete] + public void DeleteCurrencyPurchase(int currencyPurchaseId) + { + try + { + CurrencyPurchaseBindingModel model = new CurrencyPurchaseBindingModel + { + Id = currencyPurchaseId, + }; + _currencyPurchase.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления закупки валют"); + throw; + } + } + } +} \ No newline at end of file