2023-05-17 16:47:38 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-05-18 04:35:12 +04:00
|
|
|
|
using UniversityContracts.BindingModels;
|
|
|
|
|
using UniversityContracts.BusinessLogicContracts;
|
|
|
|
|
using UniversityContracts.SearchModels;
|
|
|
|
|
using UniversityContracts.ViewModels;
|
2023-05-17 16:47:38 +04:00
|
|
|
|
|
|
|
|
|
namespace UniversityRestAPI.Controllers
|
|
|
|
|
{
|
2023-05-18 04:35:12 +04:00
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class DocumentController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly IDocumentLogic _documentLogic;
|
2023-05-18 14:36:57 +04:00
|
|
|
|
private readonly IEducationGroupLogic _edGroupLogic;
|
2023-05-18 04:35:12 +04:00
|
|
|
|
|
2023-05-18 14:36:57 +04:00
|
|
|
|
public DocumentController(IDocumentLogic documentLogic,
|
|
|
|
|
IEducationGroupLogic edGroupLogic)
|
2023-05-18 04:35:12 +04:00
|
|
|
|
{
|
|
|
|
|
_documentLogic = documentLogic;
|
2023-05-18 14:36:57 +04:00
|
|
|
|
_edGroupLogic = edGroupLogic;
|
2023-05-18 04:35:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public DocumentViewModel? Get(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _documentLogic.ReadElement(new DocumentSearchModel { Id = id });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<DocumentViewModel>? GetAllByUser(int userId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _documentLogic.ReadList(new DocumentSearchModel { UserId = userId });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<DocumentViewModel>? GetMany(int userId, int page)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _documentLogic.ReadList(new DocumentSearchModel { UserId = userId, PageNumber = page, PageSize = 10 });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-18 14:36:57 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<EducationGroupViewModel>? GetAllGroups()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _edGroupLogic.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-18 04:35:12 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public int GetNumberOfPages(int userId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _documentLogic.GetNumberOfPages(userId);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Create(DocumentBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_documentLogic.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Update(DocumentBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_documentLogic.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Delete(DocumentBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_documentLogic.Delete(new() { Id = model.Id });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-17 16:47:38 +04:00
|
|
|
|
}
|