CourseWork_BankYouBankrupt/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CardController.cs
2023-05-14 11:48:00 +04:00

70 lines
2.0 KiB
C#

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;
private readonly IDebitingLogic _debitingLogic;
public CardController(ICardLogic cardLogic, IDebitingLogic debitingLogic, ILogger<ClientController> logger)
{
_logger = logger;
_cardLogic = cardLogic;
_debitingLogic = debitingLogic;
}
[HttpGet]
public List<CardViewModel>? GetUsersCardsList(int id)
{
try
{
return _cardLogic.ReadList(new CardSearchModel { ClientID = id });
}
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;
}
}
[HttpPost]
public void CreateDebitingRequest(DebitingBindingModel model) {
try
{
_debitingLogic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания на снятие наличных");
Response.StatusCode = (int)HttpStatusCode.NotAcceptable;
}
}
}
}