using LawFirmBusinessLogic.BusinessLogics; using LawFirmContracts.BindingModels; using LawFirmContracts.BusinessLogicContracts; using LawFirmContracts.SearchModels; using LawFirmContracts.ViewModels; using Microsoft.AspNetCore.Mvc; namespace LawFirmRestApi.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 logger, ILawyerLogic lawyerLogic) { _logger = logger; _logic = logic; _lawyerlogic = lawyerLogic; } [HttpGet] public List? 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 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? GetLawyerListToConsultation(int conId) { try { return _lawyerlogic.ReadConsultationElementList(new ConsultationSearchModel { Id = conId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка юристов консультации"); throw; } } } }