CourseWork_BankYouBankrupt/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CardController.cs

70 lines
2.0 KiB
C#
Raw Normal View History

2023-05-14 09:29:11 +04:00
using BankYouBankruptContracts.BindingModels;
using BankYouBankruptContracts.BusinessLogicsContracts;
using BankYouBankruptContracts.SearchModels;
using BankYouBankruptContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
using System.Linq.Expressions;
using System.Net;
namespace BankYouBankruptRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class CardController : Controller
{
private readonly ILogger _logger;
private readonly ICardLogic _cardLogic;
2023-05-14 11:48:00 +04:00
private readonly IDebitingLogic _debitingLogic;
public CardController(ICardLogic cardLogic, IDebitingLogic debitingLogic, ILogger<ClientController> logger)
2023-05-14 09:29:11 +04:00
{
_logger = logger;
_cardLogic = cardLogic;
2023-05-14 11:48:00 +04:00
_debitingLogic = debitingLogic;
2023-05-14 09:29:11 +04:00
}
[HttpGet]
public List<CardViewModel>? GetUsersCardsList(int id)
{
try
{
2023-05-14 10:01:11 +04:00
return _cardLogic.ReadList(new CardSearchModel { ClientID = id });
2023-05-14 09:29:11 +04:00
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения карт");
throw;
}
}
[HttpPost]
public void CreateCard(CardBindingModel model) {
try
{
_cardLogic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания карты");
Response.StatusCode = (int)HttpStatusCode.NotAcceptable;
}
}
2023-05-14 11:48:00 +04:00
[HttpPost]
public void CreateDebitingRequest(DebitingBindingModel model) {
try
{
_debitingLogic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания на снятие наличных");
Response.StatusCode = (int)HttpStatusCode.NotAcceptable;
}
}
2023-05-14 09:29:11 +04:00
}
}