PIbd23_Ivanova_Yakobchuk_Co.../LawCompany/LawCompanyRestApi/Controllers/HearingController.cs

116 lines
2.5 KiB
C#
Raw Normal View History

using LawCompanyContracts.BindingModels;
using LawCompanyContracts.BusinessLogicContracts;
using LawCompanyContracts.SearchModels;
using LawCompanyContracts.ViewModels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace LawCompanyRestApi.Controllers
2024-05-03 02:24:54 +04:00
{
[Route("api/[controller]/[action]")]
[ApiController]
public class HearingController : Controller
2024-05-03 02:24:54 +04:00
{
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;
}
}
2024-05-03 02:24:54 +04:00
}
}