PIbd23_Ivanova_Yakobchuk_Co.../LawCompany/LawCompanyRestApi/Controllers/CaseController.cs

119 lines
2.3 KiB
C#

using LawCompanyContracts.BindingModels;
using LawCompanyContracts.BusinessLogicContracts;
using LawCompanyContracts.SearchModels;
using LawCompanyContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.Design;
namespace LawCompanyRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class CaseController : Controller
{
private readonly ILogger _logger;
private readonly ICaseLogic _logic;
private readonly IClientLogic _clientlogic;
public CaseController(ICaseLogic logic, ILogger<CaseController> logger, IClientLogic clientlogic)
{
_logger = logger;
_logic = logic;
_clientlogic = clientlogic;
}
[HttpGet]
public List<CaseViewModel>? GetCaseList(int executorId)
{
try
{
return _logic.ReadList(new CaseSearchModel
{
ExecutorId = executorId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка продуктов");
throw;
}
}
[HttpGet("{id}")]
public CaseViewModel? GetCase(int id)
{
try
{
return _logic.ReadElement(new CaseSearchModel { Id = id, });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка продуктов");
throw;
}
}
[HttpPost]
public void CreateCase(CaseBindingModel model)
{
try
{
_logic.CreateCase(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания заказа");
throw;
}
}
[HttpPost]
public void UpdateCase(CaseBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания заказа");
throw;
}
}
[HttpPost]
public void DeleteCase(CaseBindingModel model)
{
try
{
_logic.DeleteCase(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания заказа");
throw;
}
}
[HttpGet]
public List<ClientViewModel>? GetClientListToCase(int caseId)
{
try
{
return _clientlogic.ReadCaseElementList(new CaseSearchModel
{
Id = caseId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка продуктов");
throw;
}
}
}
}