Case_accounting/CaseAccounting/CaseAccountingRestApi/Controllers/HearingController.cs
2023-05-18 01:15:02 +04:00

86 lines
1.3 KiB
C#

using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.BusinessLogicContracts;
using CaseAccountingContracts.SearchModels;
using CaseAccountingContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace CaseAccountingRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class HearingController : Controller
{
private readonly IHearingLogic _logic;
public HearingController(IHearingLogic logic)
{
_logic = logic;
}
[HttpGet]
public HearingViewModel? Get(int id)
{
try
{
return _logic.ReadElement(new HearingSearchModel { Id = id });
}
catch (Exception)
{
throw;
}
}
[HttpGet]
public List<HearingViewModel>? GetAllByUser(int userId)
{
try
{
return _logic.ReadList(new HearingSearchModel { UserId = userId });
}
catch (Exception)
{
throw;
}
}
[HttpPost]
public void Create(HearingBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception)
{
throw;
}
}
[HttpPost]
public void Update(HearingBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception)
{
throw;
}
}
[HttpPost]
public void Delete(HearingBindingModel model)
{
try
{
_logic.Delete(new() { Id = model.Id });
}
catch (Exception)
{
throw;
}
}
}
}