Files
PIbd-23_Dyakonov_Radaev_Cou…/University/UniversityRestApi/Controllers/CertificationController.cs

95 lines
2.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.AspNetCore.Mvc;
using UniversityBusinessLogic.BusinessLogics;
using UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicsContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.ViewModels;
namespace UniversityRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class CertificationController : Controller
{
private readonly ILogger _logger;
private readonly ICertificationLogic _certificationLogic;
public CertificationController(ILogger<CertificationController> logger, ICertificationLogic certification)
{
_logger = logger;
_certificationLogic = certification;
}
[HttpGet]
public CertificationViewModel? GetCertification(int CertificationId)
{
try
{
return _certificationLogic.ReadElement(new CertificationSearchModel
{
Id = CertificationId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения аттестации по id={Id}", CertificationId);
throw;
}
}
[HttpGet]
public List<CertificationViewModel>? GetCertificationList(int? secretaryId = null)
{
try
{
return !secretaryId.HasValue ? _certificationLogic.ReadList(null) : _certificationLogic.ReadList(new CertificationSearchModel { SecretaryId = secretaryId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка аттестации");
throw;
}
}
[HttpPost]
public bool CreateCertification(CertificationBindingModel model)
{
try
{
return _certificationLogic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось создать аттестацию");
throw;
}
}
[HttpPost]
public bool UpdateCertification(CertificationBindingModel model)
{
try
{
return _certificationLogic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось обновить аттестацию");
throw;
}
}
[HttpPost]
public bool DeleteCertification(CertificationBindingModel model)
{
try
{
return _certificationLogic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления аттестации");
throw;
}
}
}
}