PIbd-21_Pyatakov_KM_Markov_.../UniversityRestAPI/Controllers/EducationStatusController.cs

125 lines
3.1 KiB
C#
Raw Normal View History

2023-05-17 16:47:38 +04:00
using Microsoft.AspNetCore.Mvc;
using UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.ViewModels;
2023-05-17 16:47:38 +04:00
namespace UniversityRestAPI.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class EducationStatusController : Controller
{
private readonly IEducationStatusLogic _educationStatusLogic;
public EducationStatusController(IEducationStatusLogic educationStatusLogic)
{
_educationStatusLogic = educationStatusLogic;
}
[HttpGet]
public EducationStatusViewModel? Get(int id)
{
try
{
return _educationStatusLogic.ReadElement(new EducationStatusSearchModel { Id = id });
}
catch (Exception ex)
{
throw;
}
}
[HttpGet]
public List<EducationStatusViewModel>? GetAllByUser(int userId)
{
try
{
return _educationStatusLogic.ReadList(new EducationStatusSearchModel { UserId = userId });
}
catch (Exception ex)
{
throw;
}
}
[HttpGet]
public List<EducationStatusViewModel>? GetMany(int userId, int page)
{
try
{
return _educationStatusLogic.ReadList(new EducationStatusSearchModel { UserId = userId, PageNumber = page, PageSize = 10 });
}
catch (Exception ex)
{
throw;
}
}
[HttpGet]
public int GetNumberOfPages(int userId)
{
try
{
return _educationStatusLogic.GetNumberOfPages(userId);
}
catch (Exception ex)
{
throw;
}
}
[HttpGet]
public List<EducationStatusStudentsCountViewModel> GetEducationStatusStudents()
{
try
{
return _educationStatusLogic.GetEducationStatusStudents();
}
catch (Exception ex)
{
throw;
}
}
[HttpPost]
public void Create(EducationStatusBindingModel model)
{
try
{
_educationStatusLogic.Create(model);
}
catch (Exception ex)
{
throw;
}
}
[HttpPost]
public void Update(EducationStatusBindingModel model)
{
try
{
_educationStatusLogic.Update(model);
}
catch (Exception ex)
{
throw;
}
}
[HttpPost]
public void Delete(EducationStatusBindingModel model)
{
try
{
_educationStatusLogic.Delete(new() { Id = model.Id });
}
catch (Exception ex)
{
throw;
}
}
}
2023-05-17 16:47:38 +04:00
}