163 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;
namespace UniversityRestAPI.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class StudentController : Controller
{
private readonly IStudentLogic _studentLogic;
public StudentController(IStudentLogic studentLogic)
{
_studentLogic = studentLogic;
}
[HttpGet]
public StudentViewModel? Get(int id)
{
try
{
return _studentLogic.ReadElement(new StudentSearchModel { Id = id });
}
catch (Exception ex)
{
throw;
}
}
2023-05-19 21:25:56 +04:00
[HttpGet]
public List<StudentViewModel>? GetAll()
{
try
{
return _studentLogic.ReadList(null);
}
catch (Exception ex)
{
throw;
}
}
[HttpGet]
2023-05-17 16:47:38 +04:00
public List<StudentViewModel>? GetAllByUser(int userId)
{
try
{
return _studentLogic.ReadList(new StudentSearchModel { UserId = userId });
2023-05-17 16:47:38 +04:00
}
catch (Exception ex)
{
throw;
}
}
[HttpGet]
public List<StudentViewModel>? GetAllByUserAndEducationStatus(int userId, int educationstatus)
{
try
{
return _studentLogic.ReadList(new StudentSearchModel { UserId = userId, EducationStatusId = educationstatus });
}
catch (Exception ex)
{
2023-06-21 21:38:05 +04:00
throw;
}
}
[HttpGet]
public List<StudentViewModel>? GetAllByUserAndStream(int userId, int streamId)
{
try
{
return _studentLogic.ReadList(new StudentSearchModel { UserId = userId});
}
catch (Exception ex)
{
throw;
}
}
[HttpGet]
2023-05-17 16:47:38 +04:00
public List<StudentViewModel>? GetMany(int userId, int page)
{
try
{
return _studentLogic.ReadList(new StudentSearchModel { UserId = userId, PageNumber = page, PageSize = 10 });
}
catch (Exception ex)
{
throw;
}
}
[HttpGet]
public int GetNumberOfPages(int userId)
{
try
{
return _studentLogic.GetNumberOfPages(userId);
}
catch (Exception ex)
{
throw;
}
}
[HttpPost]
public void Create(StudentBindingModel model)
{
try
{
_studentLogic.Create(model);
}
catch (Exception ex)
{
throw;
}
}
[HttpPost]
public void Update(StudentBindingModel model)
{
try
{
_studentLogic.Update(model);
}
catch (Exception ex)
{
throw;
}
}
[HttpPost]
public void Delete(StudentBindingModel model)
{
try
{
_studentLogic.Delete(new() { Id = model.Id });
}
catch (Exception ex)
{
throw;
}
}
2023-06-22 00:20:17 +04:00
[HttpGet]
public List<StudentViewModel> GetStudentsFromStream(int streamId ) {
try
{
return _studentLogic.GetStudentsFromStream(streamId);
}
catch (Exception ex)
{
throw;
}
}
2023-05-17 16:47:38 +04:00
}
}