контроллеры в рест апи
This commit is contained in:
parent
de4aadb9c4
commit
e5e037f8fb
115
LawFim/LawFirmRestApi/Controllers/ConsultationController.cs
Normal file
115
LawFim/LawFirmRestApi/Controllers/ConsultationController.cs
Normal file
@ -0,0 +1,115 @@
|
||||
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<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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
69
LawFim/LawFirmRestApi/Controllers/GuarantorController.cs
Normal file
69
LawFim/LawFirmRestApi/Controllers/GuarantorController.cs
Normal file
@ -0,0 +1,69 @@
|
||||
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 GuarantorController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IGuarantorLogic _logic;
|
||||
|
||||
public GuarantorController(IGuarantorLogic logic, ILogger<GuarantorController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
|
||||
}
|
||||
[HttpGet]
|
||||
public GuarantorViewModel? Login(string fio, string login, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new GuarantorSearchModel
|
||||
{
|
||||
FIO = fio,
|
||||
Email = login,
|
||||
Password = password
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка входа в систему");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(GuarantorBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка регистрации");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
[HttpPost]
|
||||
public void UpdateData(GuarantorBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
115
LawFim/LawFirmRestApi/Controllers/HearingController.cs
Normal file
115
LawFim/LawFirmRestApi/Controllers/HearingController.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.BusinessLogicContracts;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LawFirmRestApi.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
79
LawFim/LawFirmRestApi/Controllers/LawyerController.cs
Normal file
79
LawFim/LawFirmRestApi/Controllers/LawyerController.cs
Normal file
@ -0,0 +1,79 @@
|
||||
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 LawyerController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILawyerLogic _logic;
|
||||
|
||||
public LawyerController(ILawyerLogic logic, ILogger<LawyerController>
|
||||
logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
|
||||
}
|
||||
[HttpGet]
|
||||
public List<LawyerViewModel>? GetLawyerList(int guarantorId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadList(new LawyerSearchModel { GuarantorId = guarantorId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка юристов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateLawyer(LawyerBindingModel model)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания юриста");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
[HttpPost]
|
||||
public void UpdateLawyer(LawyerBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления юриста");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void DeleteLawyer(LawyerBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления юриста");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user