102 lines
1.7 KiB
C#
102 lines
1.7 KiB
C#
using CaseAccountingBusinessLogic.BusinessLogics;
|
|
using CaseAccountingContracts.BindingModels;
|
|
using CaseAccountingContracts.BusinessLogicContracts;
|
|
using CaseAccountingContracts.SearchModels;
|
|
using CaseAccountingContracts.ViewModels;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CaseAccountingRestApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class CaseController : Controller
|
|
{
|
|
private readonly ICaseLogic _logic;
|
|
private readonly ISpecializationLogic _specializationLogic;
|
|
|
|
public CaseController(ICaseLogic logic, ISpecializationLogic specializationLogic)
|
|
{
|
|
_logic = logic;
|
|
_specializationLogic = specializationLogic;
|
|
}
|
|
|
|
[HttpGet]
|
|
public CaseViewModel? Get(int id)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadElement(new CaseSearchModel { Id = id });
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<CaseViewModel>? GetAllByUser(int userId)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadList(new CaseSearchModel { UserId = userId });
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<SpecializationViewModel>? GetAllSpecializations()
|
|
{
|
|
try
|
|
{
|
|
return _specializationLogic.ReadList(null);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Create(CaseBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Create(model);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Update(CaseBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Update(model);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Delete(CaseBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Delete(new() { Id = model.Id });
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|