PIbd-22_Filippov_D.S._Cours.../VeterinaryRestApi/Controllers/DoctorController.cs
2024-05-30 07:33:38 +04:00

79 lines
1.6 KiB
C#

using Microsoft.AspNetCore.Mvc;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
using VeterinaryDatabaseImplement.Models;
namespace VeterinaryRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class DoctorController : Controller
{
private readonly ILogger _logger;
private readonly IDoctorLogic _logic;
public DoctorController(IDoctorLogic logic, ILogger<DoctorController> logger)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public DoctorViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new DoctorSearchModel
{
Login = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
[HttpPost]
public void Register(DoctorBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
}
[HttpPost]
public void UpdateData(DoctorBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
}
[HttpGet]
public List<DoctorViewModel> GetDoctors()
{
try
{
return _logic.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка врачей");
throw;
}
}
}
}