95 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BankContracts.BindingModels.Cashier;
using BankContracts.BusinessLogicsContracts.Cashier;
using BankContracts.BusinessLogicsContracts.Client;
using BankContracts.SearchModels.Cashier;
using BankContracts.ViewModels.Cashier.ViewModels;
using BankContracts.ViewModels.Client.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace BankRestAPI.Controllers
{
// Route будет строиться по наванию контроллера и по названию метода (два Post-метода)
[Route("api/[controller]/[action]")]
[ApiController]
public class CashierController : Controller
{
private readonly ILogger _logger;
private readonly ICashierLogic _cashierLogic;
// Конструктор
public CashierController(ICashierLogic cashierLogic, ILogger<AccountController> logger)
{
_logger = logger;
_cashierLogic = cashierLogic;
}
[HttpGet]
public CashierViewModel? Login(string login, string password)
{
try
{
// Попытка найти кассира (запись) по переданным логину и паролю
return _cashierLogic.ReadElement(new CashierSearchModel
{
Email = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
[HttpGet]
public CashierViewModel? GetCashier(int id)
{
try
{
// Попытка найти кассира
return _cashierLogic.ReadElement(new CashierSearchModel
{
Id = id
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
[HttpPost]
public void Register(CashierBindingModel model)
{
try
{
// Cоздание кассира
_cashierLogic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
}
[HttpPost]
public void UpdateData(CashierBindingModel model)
{
try
{
// Изменение данных о кассире
_cashierLogic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
}
}
}