CourseWork/University/UniversityRestApi/Controllers/PlanOfStudysController.cs

101 lines
2.8 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 UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicsContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
namespace UniversityRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class PlanOfStudysController : Controller
{
private readonly ILogger _logger;
private readonly IPlanOfStudyLogic _logic;
public PlanOfStudysController(IPlanOfStudyLogic logic, ILogger<PlanOfStudysController> logger)
{
_logic = logic;
_logger = logger;
}
[HttpGet]
public List<PlanOfStudyViewModel>? GetPlanOfStudys(int userId)
{
try
{
return _logic.ReadList(new PlanOfStudySearchModel { UserId = userId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка планов обучения");
throw;
}
}
[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;
}
}
[HttpPost]
public void CreatePlanOfStudy(PlanOfStudyBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания плана обучения");
throw;
}
}
[HttpPost]
public void UpdatePlanOfStudy(PlanOfStudyBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления плана обучения");
throw;
}
}
[HttpPost]
public void DeletePlanOfStudy(PlanOfStudyBindingModel model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления плана обучения");
throw;
}
}
[HttpPost]
public void LinkTeacherToPlanOfStudy(int planOfStudyId, int teacherId)
{
try
{
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при связывании преподавателя с планом обучения");
throw;
}
}
}
}