125 lines
2.9 KiB
C#
125 lines
2.9 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using UniversityContracts.BindingModels;
|
|
using UniversityContracts.BusinessLogicContracts;
|
|
using UniversityContracts.SearchModels;
|
|
using UniversityContracts.ViewModels;
|
|
|
|
namespace UniversityRestAPI.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class DisciplineController : Controller
|
|
{
|
|
private readonly IDisciplineLogic _edGroupLogic;
|
|
|
|
public DisciplineController(IDisciplineLogic edGroupLogic)
|
|
{
|
|
_edGroupLogic = edGroupLogic;
|
|
}
|
|
|
|
[HttpGet]
|
|
public DisciplineViewModel? Get(int id)
|
|
{
|
|
try
|
|
{
|
|
return _edGroupLogic.ReadElement(new DisciplineSearchModel { Id = id });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<DisciplineViewModel>? GetAllByUser(int userId)
|
|
{
|
|
try
|
|
{
|
|
return _edGroupLogic.ReadList(new DisciplineSearchModel { UserId = userId });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<DisciplineViewModel>? GetMany(int userId, int page)
|
|
{
|
|
try
|
|
{
|
|
return _edGroupLogic.ReadList(new DisciplineSearchModel { UserId = userId, PageNumber = page, PageSize = 10 });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<DisciplineViewModel>? GetAllGroups()
|
|
{
|
|
try
|
|
{
|
|
return _edGroupLogic.ReadList(null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public int GetNumberOfPages(int userId)
|
|
{
|
|
try
|
|
{
|
|
return _edGroupLogic.GetNumberOfPages(userId);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Create(DisciplineBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_edGroupLogic.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Update(DisciplineBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_edGroupLogic.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Delete(DisciplineBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_edGroupLogic.Delete(new() { Id = model.Id });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|