2024-04-29 22:15:15 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-05-30 00:31:58 +04:00
|
|
|
|
using UniversityBusinessLogic.MailWorker;
|
2024-04-29 22:15:15 +04:00
|
|
|
|
using UniversityContracts.BindingModels;
|
2024-05-29 23:23:53 +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]
|
2024-05-27 23:53:45 +04:00
|
|
|
|
public class DisciplineController : Controller
|
2024-04-29 22:15:15 +04:00
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IDisciplineLogic _logic;
|
2024-05-29 23:23:53 +04:00
|
|
|
|
private readonly IReportLogic _reportLogic;
|
2024-05-30 00:31:58 +04:00
|
|
|
|
private readonly AbstractMailWorker _mailWorker;
|
|
|
|
|
public DisciplineController(IDisciplineLogic logic, ILogger<DisciplineController> logger, IReportLogic reportLogic, AbstractMailWorker mailWorker)
|
2024-04-29 22:15:15 +04:00
|
|
|
|
{
|
|
|
|
|
_logic = logic;
|
|
|
|
|
_logger = logger;
|
2024-05-29 23:23:53 +04:00
|
|
|
|
_reportLogic = reportLogic;
|
2024-05-30 00:31:58 +04:00
|
|
|
|
_mailWorker = mailWorker;
|
2024-04-29 22:15:15 +04:00
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<DisciplineViewModel>? GetDisciplines(int userId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _logic.ReadList(new DisciplineSearchModel { UserId = userId });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка дисциплин");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2024-05-29 23:23:53 +04:00
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
2024-05-30 00:09:06 +04:00
|
|
|
|
public List<ReportDisciplineViewModel> GetReportDisciplines(DateOnly dateFrom, DateOnly dateTo)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _reportLogic.GetDisciplines(new ReportDateRangeBindingModel { DateFrom = dateFrom, DateTo = dateTo });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка дисциплин");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2024-05-29 23:23:53 +04:00
|
|
|
|
public List<ReportDisciplineViewModel> GetReportDisciplines()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _reportLogic.GetDisciplines(new ReportDateRangeBindingModel { DateFrom = DateOnly.MinValue, DateTo = DateOnly.MaxValue });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка дисциплин");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2024-04-29 22:15:15 +04:00
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateDiscipline(DisciplineBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания дисциплины");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPut]
|
|
|
|
|
public void UpdateDiscipline(DisciplineBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления дисциплины");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpDelete]
|
|
|
|
|
public void DeleteDiscipline(DisciplineBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Delete(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления дисциплины");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-30 00:31:58 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2024-05-30 01:19:26 +04:00
|
|
|
|
public void CreateReportToPDFFile(ReportDateRangeBindingModel model, DateOnly dateFrom, DateOnly dateTo)
|
2024-05-30 00:31:58 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
2024-05-30 01:19:26 +04:00
|
|
|
|
model.DateTo = dateTo;
|
|
|
|
|
model.DateFrom = dateFrom;
|
2024-05-30 00:31:58 +04:00
|
|
|
|
_reportLogic.SendDisciplinesToEmail(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void SendPDFToMail(MailSendInfoBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_mailWorker.MailSendAsync(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка отправки письма");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-29 22:15:15 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|