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

83 lines
1.6 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;
}
}
[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;
}
}
}
}