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;
|
2024-12-13 04:12:54 +04:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Security.Cryptography.Xml;
|
2024-12-09 02:10:45 +04:00
|
|
|
|
|
|
|
|
|
namespace CandidateReviewClientApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class AssessmentController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<AssessmentController> _logger;
|
|
|
|
|
|
|
|
|
|
public AssessmentController(ILogger<AssessmentController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2024-12-14 02:43:44 +04:00
|
|
|
|
public async Task<IActionResult> AddAssessmentCriterion(int resumeId, int[] criterion, int[] newValue, string comment)
|
2024-12-09 02:10:45 +04:00
|
|
|
|
{
|
2024-12-13 04:12:54 +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-14 02:43:44 +04:00
|
|
|
|
if (criterion == null || newValue == null || criterion.Length != newValue.Length)
|
2024-12-10 01:20:52 +04:00
|
|
|
|
{
|
2024-12-14 02:43:44 +04:00
|
|
|
|
throw new ArgumentException("Критерии или оценки заполнены некорректно.");
|
2024-12-10 01:20:52 +04:00
|
|
|
|
}
|
2024-12-09 02:10:45 +04:00
|
|
|
|
|
2024-12-13 04:12:54 +04:00
|
|
|
|
var userId = APIClient.User?.Id;
|
2024-12-10 01:20:52 +04:00
|
|
|
|
var assessmentModel = new AssessmentBindingModel
|
2024-12-09 02:10:45 +04:00
|
|
|
|
{
|
|
|
|
|
ResumeId = resumeId,
|
|
|
|
|
UserId = userId,
|
2024-12-14 02:43:44 +04:00
|
|
|
|
Comment = comment
|
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-14 02:43:44 +04:00
|
|
|
|
List<Tuple<int, int>> criterionsValues = new();
|
2024-12-13 04:12:54 +04:00
|
|
|
|
for (int i = 0; i < criterion.Length; i++)
|
|
|
|
|
{
|
2024-12-14 02:43:44 +04:00
|
|
|
|
criterionsValues.Add(Tuple.Create(criterion[i], newValue[i]));
|
|
|
|
|
}
|
|
|
|
|
foreach (var item in criterionsValues)
|
|
|
|
|
{
|
|
|
|
|
var assessmentCriterion = new AssessmentCriterionModel
|
|
|
|
|
{
|
|
|
|
|
AssessmentId = assessmentId,
|
|
|
|
|
CriterionId = item.Item1,
|
|
|
|
|
Value = item.Item2
|
|
|
|
|
};
|
|
|
|
|
APIClient.PostRequest("api/assessment/createCriterion", assessmentCriterion);
|
2024-12-13 04:12:54 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var user = APIClient.GetRequest<UserViewModel>($"api/user/profile?id={APIClient.User?.Id}");
|
|
|
|
|
|
|
|
|
|
APIClient.User?.Assessments.Add(new AssessmentViewModel
|
|
|
|
|
{
|
|
|
|
|
ResumeId = assessmentModel.ResumeId,
|
|
|
|
|
UserId = assessmentModel.UserId,
|
2024-12-14 02:43:44 +04:00
|
|
|
|
Comment = assessmentModel.Comment
|
2024-12-13 04:12:54 +04:00
|
|
|
|
});
|
|
|
|
|
var resume = APIClient.GetRequest<ResumeViewModel>($"api/resume/details?id={resumeId}");
|
|
|
|
|
if (resume != null)
|
|
|
|
|
{
|
|
|
|
|
resume?.Assessments.Add(new AssessmentViewModel
|
|
|
|
|
{
|
|
|
|
|
ResumeId = assessmentModel.ResumeId,
|
|
|
|
|
UserId = assessmentModel.UserId,
|
2024-12-14 02:43:44 +04:00
|
|
|
|
Comment = assessmentModel.Comment
|
2024-12-13 04:12:54 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Пользователь не найден");
|
|
|
|
|
}
|
2024-12-09 02:10:45 +04:00
|
|
|
|
return Redirect($"~/Resume/ResumeDetails/{resumeId}");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Error", new { errorMessage = $"{ex.Message}", returnUrl });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-13 04:12:54 +04:00
|
|
|
|
public IActionResult Delete(int id, int resumeId)
|
|
|
|
|
{
|
|
|
|
|
string returnUrl = HttpContext.Request.Headers["Referer"].ToString();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
APIClient.PostRequest($"api/assessment/delete", new AssessmentBindingModel { Id = id });
|
|
|
|
|
|
|
|
|
|
return Redirect($"~/Resume/ResumeDetails/{resumeId}") ;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Error", new { errorMessage = $"{ex.Message}", returnUrl });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-09 02:10:45 +04:00
|
|
|
|
[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 });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|