PIbd23_Ivanova_Yakobchuk_Co.../LawCompany/LawCompanyRestApi/Controllers/ClientController.cs

98 lines
1.9 KiB
C#
Raw Normal View History

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;
}
}
}
}