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 CurrencyController : Controller { private readonly ILogger _logger; private readonly ICurrencyLogic _logic; public CurrencyController(ILogger logger, ICurrencyLogic logic) { _logger = logger; _logic = logic; } [HttpGet] public List? GetCurrencyList() { try { return _logic.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка валют"); throw; } } [HttpGet] public CurrencyViewModel? GetCurrency(int CurrencyId) { try { return _logic.ReadElement(new CurrencySearchModel { Id = CurrencyId }); } catch (Exception ex) { _logger.LogError( ex, "Ошибка получения валюты по Id={Id}", CurrencyId); throw; } } [HttpPost] public void CreateCurrency(CurrencyBindingModel model) { try { _logic.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания валюты"); throw; } } [HttpPut] public void UpdateCurrency(CurrencyBindingModel model) { try { _logic.Update(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка обновления валюты"); throw; } } [HttpDelete] public void DeleteCurrency(CurrencyBindingModel model) { try { _logic.Delete(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка удаления валюты"); throw; } } } }