PIbd23_Ivanova_Yakobchuk_Co.../LawCompany/LawCompanyRestApi/Controllers/ConsultationController.cs
2024-05-03 02:31:59 +04:00

116 lines
2.6 KiB
C#

using LawCompanyContracts.BindingModels;
using LawCompanyContracts.BusinessLogicContracts;
using LawCompanyContracts.SearchModels;
using LawCompanyContracts.ViewModels;
using LawCompanyBusinessLogic.BusinessLogics;
using Microsoft.AspNetCore.Mvc;
namespace LawCompanyRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ConsultationController : Controller
{
private readonly ILogger _logger;
private readonly IConsultationLogic _logic;
private readonly ILawyerLogic _lawyerlogic;
public ConsultationController(IConsultationLogic logic, ILogger<ConsultationController>
logger, ILawyerLogic lawyerLogic)
{
_logger = logger;
_logic = logic;
_lawyerlogic = lawyerLogic;
}
[HttpGet]
public List<ConsultationViewModel>? GetConsultationList(int guarantorId)
{
try
{
return _logic.ReadList(new ConsultationSearchModel
{
GuarantorId = guarantorId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка консультаций");
throw;
}
}
[HttpPost]
public void CreateConsultation(ConsultationBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания кунсультации");
throw;
}
}
[HttpPost]
public void UpdateConsultation(ConsultationBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления консультации");
throw;
}
}
[HttpPost]
public void DeleteConsultation(ConsultationBindingModel model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления консультации");
throw;
}
}
[HttpPost]
public void AddLawyerToConsultation(Tuple<ConsultationSearchModel, int> model)
{
try
{
var modelLawyer = _lawyerlogic.ReadElement(new LawyerSearchModel { Id = model.Item2 });
if (modelLawyer != null) { _logic.AddLawyerToConsultation(model.Item1, modelLawyer); }
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка добавления юристов в консультацию");
throw;
}
}
[HttpGet]
public List<LawyerViewModel>? GetLawyerListToConsultation(int conId)
{
try
{
return _lawyerlogic.ReadConsultationElementList(new ConsultationSearchModel
{
Id = conId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка юристов консультации");
throw;
}
}
}
}