CourseWork_Hotel/Hotel/HotelRestApi/Controllers/HeadwaiterController.cs

68 lines
1.8 KiB
C#

using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace HotelRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class HeadwaiterController : Controller
{
private readonly ILogger _logger;
private readonly IHeadwaiterLogic _logic;
public HeadwaiterController(IHeadwaiterLogic logic, ILogger<HeadwaiterController> logger)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public HeadwaiterViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new HeadwaiterSearchModel
{
//HeadwaiterEmail = login,
HeadwaiterPassword = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
[HttpPost]
public void Register(HeadwaiterBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
}
[HttpPost]
public void UpdateData(HeadwaiterBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
}
}
}