164 lines
4.6 KiB
C#
164 lines
4.6 KiB
C#
using CandidateReviewContracts.BindingModels;
|
|
using CandidateReviewContracts.BusinessLogicsContracts;
|
|
using CandidateReviewContracts.SearchModels;
|
|
using CandidateReviewContracts.ViewModels;
|
|
using CandidateReviewDataModels.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CandidateReviewRestApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class AssessmentController : Controller
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IAssessmentLogic _logic;
|
|
public AssessmentController(IAssessmentLogic logic, ILogger<AssessmentController> logger)
|
|
{
|
|
_logger = logger;
|
|
_logic = logic;
|
|
}
|
|
|
|
[HttpGet]
|
|
public AssessmentViewModel? Details(int id)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadElement(new AssessmentSearchModel
|
|
{
|
|
Id = id
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения оценки");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<AssessmentViewModel>? ListByUserId(int id)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadList(new AssessmentSearchModel
|
|
{
|
|
UserId = id
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения оценок");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<AssessmentViewModel>? ListByResumeId(int id)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadList(new AssessmentSearchModel
|
|
{
|
|
ResumeId = id
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения оценок");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public int? Create(AssessmentBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
int? id = _logic.Create(model);
|
|
return id;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка создания оценки");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost]
|
|
public void AddCriterionToAssessment(Dictionary<int, (ICriterionModel, int)> model)
|
|
{
|
|
if (model == null || model.Count == 0)
|
|
{
|
|
throw new ArgumentException("Модель данных не должна быть пустой.", nameof(model));
|
|
}
|
|
|
|
try
|
|
{
|
|
foreach (var kvp in model)
|
|
{
|
|
var id = kvp.Key;
|
|
var (criterion, value) = kvp.Value;
|
|
|
|
if (criterion == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!model.ContainsKey(id))
|
|
{
|
|
model.Add(id, (criterion, value));
|
|
}
|
|
else
|
|
{
|
|
model[id] = (criterion, value);
|
|
}
|
|
|
|
var success = _logic.AddCriterionToAssessment(
|
|
new AssessmentSearchModel { Id = id },
|
|
criterion,
|
|
value
|
|
);
|
|
|
|
if (!success)
|
|
{
|
|
throw new Exception("Ошибка добавления критерия.");
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка добавления критериев.");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Update(AssessmentBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка обновления оценки");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Delete(AssessmentBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Delete(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка удаления оценки");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|