CourseWork_BankYouBankrupt/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CardController.cs

87 lines
2.7 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;
2023-05-14 15:47:08 +04:00
private readonly ICreditingLogic _creditingLogic;
private readonly IAccountLogic _accountLogic;
public CardController(ICardLogic cardLogic, IDebitingLogic debitingLogic, ICreditingLogic creditingLogic, IAccountLogic accountLogic, 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 15:47:08 +04:00
_creditingLogic = creditingLogic;
_accountLogic = accountLogic;
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);
2023-05-16 20:11:29 +04:00
}
2023-05-14 11:48:00 +04:00
catch (Exception ex)
{
2023-05-14 15:47:08 +04:00
_logger.LogError(ex, "Ошибка создания запроса на снятие наличных");
Response.StatusCode = (int)HttpStatusCode.NotAcceptable;
}
}
[HttpPost]
public void CreateCreditingOperation(CreditingBindingModel model) {
try {
_creditingLogic.Create(model);
}
catch (Exception ex) {
_logger.LogError(ex, "Ошибка создания операции на пополнение");
2023-05-14 11:48:00 +04:00
Response.StatusCode = (int)HttpStatusCode.NotAcceptable;
}
2023-05-14 15:47:08 +04:00
}
2023-05-14 09:29:11 +04:00
}
}