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 VisitController : Controller { private readonly ILogger _logger; private readonly IVisitLogic _logic; private readonly IClientLogic _clientlogic; public VisitController(IVisitLogic logic, ILogger logger, IClientLogic clientLogic) { _logger = logger; _logic = logic; _clientlogic = clientLogic; } [HttpGet] public List? GetVisitList(int executorId) { try { return _logic.ReadList(new VisitSearchModel { ExecutorId = executorId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка продуктов"); throw; } } [HttpGet] public VisitViewModel? GetVisit(int id) { try { return _logic.ReadElement(new VisitSearchModel { Id = id, }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка продуктов"); throw; } } [HttpPost] public void CreateVisit(VisitBindingModel model) { try { _logic.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания заказа"); throw; } } [HttpPost] public void UpdateVisit(VisitBindingModel model) { try { _logic.Update(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания заказа"); throw; } } [HttpPost] public void DeleteVisit(VisitBindingModel model) { try { _logic.Delete(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания заказа"); throw; } } [HttpPost] public void AddClientToVisit(Tuple model) { try { var modelClient = _clientlogic.ReadElement(new ClientSearchModel { Id = model.Item2 }); if (modelClient != null) { _logic.AddClientToVisit(model.Item1, modelClient); } } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания заказа"); throw; } } [HttpGet] public List? GetClientListToVisit(int visitId) { try { return _clientlogic.ReadVisitElementList(new VisitSearchModel { Id = visitId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка продуктов"); throw; } } } }