2024-04-29 22:15:15 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using UniversityContracts.BindingModels;
|
2024-05-28 22:09:51 +04:00
|
|
|
|
using UniversityContracts.BusinessLogicContracts;
|
2024-04-29 22:15:15 +04:00
|
|
|
|
using UniversityContracts.BusinessLogicsContracts;
|
|
|
|
|
using UniversityContracts.SearchModels;
|
|
|
|
|
using UniversityContracts.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace UniversityRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class TeacherController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly ITeacherLogic _logic;
|
2024-05-28 22:09:51 +04:00
|
|
|
|
private readonly IReportLogic _reportLogic;
|
|
|
|
|
public TeacherController(ITeacherLogic logic, ILogger<TeacherController> logger, IReportLogic reportLogic)
|
2024-04-29 22:15:15 +04:00
|
|
|
|
{
|
|
|
|
|
_logic = logic;
|
|
|
|
|
_logger = logger;
|
2024-05-28 22:09:51 +04:00
|
|
|
|
_reportLogic = reportLogic;
|
2024-04-29 22:15:15 +04:00
|
|
|
|
}
|
2024-05-30 03:23:27 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public TeacherViewModel? GetTeacher(int userId, int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _logic.ReadElement(new TeacherSearchModel { UserId = userId, Id = id });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения teacher user {Id}", userId);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-29 22:15:15 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<TeacherViewModel>? GetTeachers(int userId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _logic.ReadList(new TeacherSearchModel { UserId = userId });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка преподавателей пользователя id={Id}", userId);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-28 17:08:06 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<TeacherViewModel>? GetAllTeachers()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _logic.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка преподавателей");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2024-04-29 22:15:15 +04:00
|
|
|
|
public void CreateTeacher(TeacherBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания преподавателя");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-30 03:23:27 +04:00
|
|
|
|
[HttpPost]
|
2024-04-29 22:15:15 +04:00
|
|
|
|
public void UpdateTeacher(TeacherBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления преподавателя");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-30 03:23:27 +04:00
|
|
|
|
[HttpPost]
|
2024-04-29 22:15:15 +04:00
|
|
|
|
public void DeleteTeacher(TeacherBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Delete(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления преподавателя");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-28 22:09:51 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2024-05-29 11:30:39 +04:00
|
|
|
|
public List<ReportTeacherViewModel>? GetTeachersReport(int userId)
|
2024-05-28 22:09:51 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-29 11:30:39 +04:00
|
|
|
|
return _reportLogic.GetTeachers(userId);
|
2024-05-28 22:09:51 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка планов обучения");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-29 11:30:39 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void LoadReportToWord(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SaveTeachersToWord(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void LoadReportToExcel(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SaveTeachersToExcel(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-29 22:15:15 +04:00
|
|
|
|
}
|
|
|
|
|
}
|