2024-04-29 19:06:11 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-05-29 17:43:10 +04:00
|
|
|
|
using UniversityBusinessLogic.MailWorker;
|
2024-04-29 19:06:11 +04:00
|
|
|
|
using UniversityContracts.BindingModels;
|
2024-05-28 21:40:18 +04:00
|
|
|
|
using UniversityContracts.BusinessLogicContracts;
|
2024-04-29 19:06:11 +04:00
|
|
|
|
using UniversityContracts.BusinessLogicsContracts;
|
|
|
|
|
using UniversityContracts.SearchModels;
|
|
|
|
|
using UniversityContracts.ViewModels;
|
2024-05-28 17:08:06 +04:00
|
|
|
|
using UniversityDatabaseImplement.Models;
|
2024-04-29 19:06:11 +04:00
|
|
|
|
|
|
|
|
|
namespace UniversityRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class PlanOfStudysController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IPlanOfStudyLogic _logic;
|
2024-05-28 21:40:18 +04:00
|
|
|
|
private readonly IReportLogic _reportLogic;
|
2024-05-29 17:43:10 +04:00
|
|
|
|
private readonly AbstractMailWorker _mailWorker;
|
|
|
|
|
public PlanOfStudysController(IPlanOfStudyLogic logic, ILogger<PlanOfStudysController> logger, IReportLogic reportLogic, AbstractMailWorker mailWorker)
|
2024-04-29 19:06:11 +04:00
|
|
|
|
{
|
|
|
|
|
_logic = logic;
|
|
|
|
|
_logger = logger;
|
2024-05-28 21:40:18 +04:00
|
|
|
|
_reportLogic = reportLogic;
|
2024-05-29 17:43:10 +04:00
|
|
|
|
_mailWorker = mailWorker;
|
2024-04-29 19:06:11 +04:00
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<PlanOfStudyViewModel>? GetPlanOfStudys(int userId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-27 01:11:57 +04:00
|
|
|
|
return _logic.ReadList(new PlanOfStudySearchModel { UserId = userId });
|
2024-04-29 19:06:11 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка планов обучения");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-28 17:08:06 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public PlanOfStudyViewModel? GetPlanOfStudy(int id, int userId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _logic.ReadElement(new PlanOfStudySearchModel { Id = id, UserId = userId });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка планов обучения");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-28 21:40:18 +04:00
|
|
|
|
[HttpGet]
|
2024-05-29 02:49:07 +04:00
|
|
|
|
public List<ReportPlanOfStudyViewModel>? GetPlanOfStudyAndDisciplines(int userId)
|
2024-05-28 21:40:18 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-29 02:49:07 +04:00
|
|
|
|
return _reportLogic.GetPlanOfStudyAndDisciplines(userId);
|
2024-05-28 21:40:18 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка планов обучения");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-29 19:26:11 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<ReportPlanOfStudyAndStudentViewModel>? GetPlanOfStudyAndStudents()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var report = _reportLogic.GetPlanOfStudyAndStudents();
|
|
|
|
|
return report;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка планов обучения");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-28 21:40:18 +04:00
|
|
|
|
[HttpPost]
|
2024-05-29 02:49:07 +04:00
|
|
|
|
public void LoadReportToWord(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SavePlanOfStudyToWord(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void LoadReportToExcel(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SavePlanOfStudyToExcel(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2024-05-29 19:26:11 +04:00
|
|
|
|
public void CreateReportToPDFFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SendPlanOfStudyToEmail(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2024-05-29 17:43:10 +04:00
|
|
|
|
public void SendPDFToMail(MailSendInfoBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_mailWorker.MailSendAsync(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка отправки письма");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2024-04-29 19:06:11 +04:00
|
|
|
|
public void CreatePlanOfStudy(PlanOfStudyBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания плана обучения");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 17:32:21 +04:00
|
|
|
|
[HttpPost]
|
2024-04-29 19:06:11 +04:00
|
|
|
|
public void UpdatePlanOfStudy(PlanOfStudyBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления плана обучения");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 17:32:21 +04:00
|
|
|
|
[HttpPost]
|
2024-04-29 19:06:11 +04:00
|
|
|
|
public void DeletePlanOfStudy(PlanOfStudyBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Delete(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления плана обучения");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-28 17:08:06 +04:00
|
|
|
|
}
|
2024-04-29 19:06:11 +04:00
|
|
|
|
}
|