2024-12-09 02:10:45 +04:00
|
|
|
|
using CandidateReviewClientApp.Models;
|
|
|
|
|
using CandidateReviewContracts.BindingModels;
|
2024-12-10 01:20:52 +04:00
|
|
|
|
using CandidateReviewContracts.SearchModels;
|
2024-12-09 02:10:45 +04:00
|
|
|
|
using CandidateReviewContracts.ViewModels;
|
|
|
|
|
using CandidateReviewDataModels.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
namespace CandidateReviewClientApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class AssessmentController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<AssessmentController> _logger;
|
|
|
|
|
|
|
|
|
|
public AssessmentController(ILogger<AssessmentController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-12 01:54:07 +04:00
|
|
|
|
|
|
|
|
|
|
2024-12-09 02:10:45 +04:00
|
|
|
|
[HttpPost]
|
2024-12-10 01:20:52 +04:00
|
|
|
|
public async Task<IActionResult> AddAssessmentCriterion(int resumeId, int[] criterion, int[] value, string comment)
|
2024-12-09 02:10:45 +04:00
|
|
|
|
{
|
|
|
|
|
string returnUrl = HttpContext.Request.Headers["Referer"].ToString();
|
2024-12-10 01:20:52 +04:00
|
|
|
|
|
2024-12-09 02:10:45 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
2024-12-10 01:20:52 +04:00
|
|
|
|
if (APIClient.User == null)
|
2024-12-09 02:10:45 +04:00
|
|
|
|
{
|
2024-12-10 01:20:52 +04:00
|
|
|
|
throw new Exception("Необходима авторизация");
|
2024-12-09 02:10:45 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-10 01:20:52 +04:00
|
|
|
|
if (criterion == null || value == null || criterion.Length != value.Length)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Массивы критериев и оценок должны быть не null и одинаковой длины.");
|
|
|
|
|
}
|
2024-12-09 02:10:45 +04:00
|
|
|
|
|
2024-12-10 01:20:52 +04:00
|
|
|
|
var userId = APIClient.User?.Id;
|
|
|
|
|
var assessmentData = new Dictionary<int, (ICriterionModel, int)>();
|
2024-12-09 02:10:45 +04:00
|
|
|
|
|
2024-12-10 01:20:52 +04:00
|
|
|
|
var assessmentModel = new AssessmentBindingModel
|
2024-12-09 02:10:45 +04:00
|
|
|
|
{
|
|
|
|
|
ResumeId = resumeId,
|
|
|
|
|
UserId = userId,
|
|
|
|
|
Comment = comment,
|
2024-12-12 01:54:07 +04:00
|
|
|
|
AssessmentCriterions = criterion.Select((t, i) => new KeyValuePair<int, (ICriterionModel, int)>
|
|
|
|
|
(t, (new CriterionViewModel { Id = t }, value[i]))).ToDictionary(kv => kv.Key, kv => kv.Value)
|
2024-12-10 01:20:52 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2024-12-12 01:54:07 +04:00
|
|
|
|
int assessmentId = await APIClient.PostRequestAsync("api/assessment/create", assessmentModel);
|
2024-12-09 02:10:45 +04:00
|
|
|
|
|
|
|
|
|
return Redirect($"~/Resume/ResumeDetails/{resumeId}");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Error", new { errorMessage = $"{ex.Message}", returnUrl });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
public IActionResult Error(string errorMessage, string returnUrl)
|
|
|
|
|
{
|
|
|
|
|
ViewBag.ErrorMessage = errorMessage ?? "Произошла непредвиденная ошибка.";
|
|
|
|
|
ViewBag.ReturnUrl = returnUrl;
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|