PIbd-21_BatylkinaAO_MusoevD.../Canteen/CanteenRestApi/Controllers/ManagerController.cs

69 lines
1.7 KiB
C#
Raw Normal View History

using CanteenContracts.BindingModels;
using CanteenContracts.BusinessLogicsContracts;
using CanteenContracts.SearchModel;
using CanteenContracts.View;
using Microsoft.AspNetCore.Mvc;
namespace CanteenRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ManagerController : Controller
{
private readonly ILogger _logger;
private readonly IManagerLogic _logic;
public ManagerController(IManagerLogic logic, ILogger<ManagerController> logger)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public ManagerViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new ManagerSearchModel
{
Login = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during logging in");
throw;
}
}
[HttpPost]
public void Register(ManagerBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during registration");
throw;
}
}
[HttpPost]
public void UpdateData(ManagerBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during updating");
throw;
}
}
}
}