CourseWork_Borschevskaya_A..../Hospital/HospitalRestApi/Controllers/PrescriptionController.cs

100 lines
2.7 KiB
C#

using HospitalContracts.BindingModels;
using HospitalContracts.BusinessLogicContracts;
using HospitalContracts.SearchModels;
using HospitalContracts.ViewModels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace HospitalRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class PrescriptionController : ControllerBase
{
private readonly ILogger _logger;
private readonly IPrescriptionLogic _logic;
public PrescriptionController(IPrescriptionLogic logic, ILogger<PrescriptionController> logger)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public List<PrescriptionViewModel>? GetPrescriptions(int apothecaryid)
{
try
{
return _logic.ReadList(new PrescriptionSearchModel
{
ApothecaryId = apothecaryid
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка поступлений аптекаря id ={ Id}", apothecaryid);
throw;
}
}
[HttpGet]
public PrescriptionViewModel? GetPrescription(int id)
{
try
{
return _logic.ReadElement(new PrescriptionSearchModel
{
Id = id
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения поступления ");
throw;
}
}
[HttpPost]
public void Create(PrescriptionBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания поступления");
throw;
}
}
[HttpPost]
public void Update(PrescriptionBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления поступления");
throw;
}
}
[HttpPost]
public void Delete(PrescriptionBindingModel model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления поступления");
throw;
}
}
}
}