Case_accounting/CaseAccounting/CaseAccountingRestApi/Controllers/CaseController.cs

112 lines
1.7 KiB
C#
Raw Normal View History

2023-05-17 23:28:43 +04:00
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;
public CaseController(ICaseLogic logic)
{
_logic = logic;
}
[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(null);
}
catch (Exception)
{
throw;
}
}
/*[HttpGet]
public List<CaseViewModel>? GetMany(int userId, int page)
{
try
{
return _logic.ReadList(new CaseSearchModel { UserId = userId, PageNumber = page, PageSize = 10 });
}
catch (Exception)
{
throw;
}
}*/
/*[HttpGet]
public int GetNumberOfPages(int userId)
{
try
{
return _studentLogic.GetNumberOfPages(userId);
}
catch (Exception ex)
{
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;
}
}
}
}