98 lines
1.9 KiB
C#
98 lines
1.9 KiB
C#
using LawCompanyContracts.BindingModels;
|
|
using LawCompanyContracts.BusinessLogicContracts;
|
|
using LawCompanyContracts.SearchModels;
|
|
using LawCompanyContracts.ViewModels;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Diagnostics;
|
|
|
|
namespace LawCompanyRestApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class ClientController : Controller
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IClientLogic _logic;
|
|
|
|
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
|
|
{
|
|
_logger = logger;
|
|
_logic = logic;
|
|
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<ClientViewModel>? GetClientList(int executorId)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadList(new ClientSearchModel { ExecutorId = executorId });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения списка продуктов");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public ClientViewModel? GetClientById(int id)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadElement(new ClientSearchModel { Id = id });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения данных клиента");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
[HttpPost]
|
|
public void CreateClient(ClientBindingModel model)
|
|
{
|
|
|
|
try
|
|
{
|
|
_logic.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка создания заказа");
|
|
throw;
|
|
}
|
|
|
|
}
|
|
|
|
[HttpPost]
|
|
public void UpdateClient(ClientBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка создания заказа");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void DeleteClient(ClientBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Delete(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка создания заказа");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|