116 lines
2.5 KiB
C#
116 lines
2.5 KiB
C#
using LawCompanyContracts.BindingModels;
|
|
using LawCompanyContracts.BusinessLogicContracts;
|
|
using LawCompanyContracts.SearchModels;
|
|
using LawCompanyContracts.ViewModels;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace LawCompanyRestApi.Controllers
|
|
{
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class HearingController : Controller
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IHearingLogic _logic;
|
|
private readonly ILawyerLogic _lawyerlogic;
|
|
|
|
public HearingController(IHearingLogic logic, ILogger<HearingController>
|
|
logger, ILawyerLogic lawyerlogic)
|
|
{
|
|
_logger = logger;
|
|
_logic = logic;
|
|
_lawyerlogic = lawyerlogic;
|
|
}
|
|
[HttpGet]
|
|
public List<HearingViewModel>? GetHearingList(int guarantorId)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadList(new HearingSearchModel
|
|
{
|
|
GuarantorId = guarantorId
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения списка слушаний");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CreateHearing(HearingBindingModel model)
|
|
{
|
|
|
|
try
|
|
{
|
|
_logic.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка создания слушания");
|
|
throw;
|
|
}
|
|
|
|
}
|
|
[HttpPost]
|
|
public void UpdateHearing(HearingBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка обновления слушания");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost]
|
|
public void DeleteHearing(HearingBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Delete(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка удаления слушания");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost]
|
|
public void AddLawyerToHearing(Tuple<HearingSearchModel, int> model)
|
|
{
|
|
try
|
|
{
|
|
var modelLawyer = _lawyerlogic.ReadElement(new LawyerSearchModel { Id = model.Item2 });
|
|
if (modelLawyer != null) { _logic.AddLawyerToHearing(model.Item1, modelLawyer); }
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка добавления юриста в слушание");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpGet]
|
|
public List<LawyerViewModel>? GetLawyerListToHearing(int hearingId)
|
|
{
|
|
try
|
|
{
|
|
return _lawyerlogic.ReadHearingElementList(new HearingSearchModel
|
|
{
|
|
Id = hearingId
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения списка юристов слушания");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|