2024-12-09 02:10:45 +04:00
|
|
|
|
using CandidateReviewClientApp.Models;
|
|
|
|
|
using CandidateReviewContracts.BindingModels;
|
|
|
|
|
using CandidateReviewContracts.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
namespace CandidateReviewClientApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class ResumeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<ResumeController> _logger;
|
|
|
|
|
|
|
|
|
|
public ResumeController(ILogger<ResumeController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IActionResult> ResumeDetails(int? id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resume = await APIClient.GetRequestAsync<ResumeViewModel?>($"api/resume/details?id={id}");
|
|
|
|
|
if (resume == null || !id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2024-12-12 01:54:07 +04:00
|
|
|
|
|
|
|
|
|
var resumeAssessments = APIClient.GetRequest<List<AssessmentViewModel>>($"api/assessment/listByResumeId?id={id}");
|
|
|
|
|
var userAssessment = resumeAssessments?.FirstOrDefault(a => a.UserId == APIClient.User.Id);
|
2024-12-09 02:10:45 +04:00
|
|
|
|
var criterions = APIClient.GetRequest<List<CriterionViewModel>>($"api/criterion/list");
|
2024-12-12 01:54:07 +04:00
|
|
|
|
resume.Assessments = resumeAssessments ?? new List<AssessmentViewModel>();
|
2024-12-14 02:43:44 +04:00
|
|
|
|
|
|
|
|
|
var assessmentCriterions = new List<AssessmentCriterionViewModel>();
|
|
|
|
|
if (resumeAssessments != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in resumeAssessments)
|
|
|
|
|
{
|
|
|
|
|
assessmentCriterions.AddRange(APIClient.GetRequest<List<AssessmentCriterionViewModel>>($"api/assessment/assessmentCriterions?assessmentId={item.Id}"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userAC = new List<AssessmentCriterionViewModel>();
|
|
|
|
|
if (userAssessment != null)
|
|
|
|
|
{
|
|
|
|
|
userAC.AddRange(APIClient.GetRequest<List<AssessmentCriterionViewModel>>($"api/assessment/assessmentCriterions?assessmentId={userAssessment.Id}"));
|
|
|
|
|
}
|
|
|
|
|
ViewBag.UserAssessmentCriterions = userAC;
|
|
|
|
|
ViewBag.OtherAssessmentCriterions = assessmentCriterions;
|
2024-12-12 01:54:07 +04:00
|
|
|
|
ViewBag.UserAssessment = userAssessment;
|
2024-12-09 02:10:45 +04:00
|
|
|
|
ViewBag.Criterions = criterions;
|
2024-12-12 01:54:07 +04:00
|
|
|
|
|
2024-12-09 02:10:45 +04:00
|
|
|
|
return View(resume);
|
2024-12-12 01:54:07 +04:00
|
|
|
|
}
|
2024-12-09 02:10:45 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IActionResult> EditResume(int? id, int? vacancyId)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Enter", "Home");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResumeViewModel model;
|
|
|
|
|
if (id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
model = await APIClient.GetRequestAsync<ResumeViewModel>($"api/resume/details?id={id}");
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
model = new ResumeViewModel { UserId = APIClient.User.Id, VacancyId = vacancyId ?? 0 };
|
|
|
|
|
}
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult EditResume(ResumeBindingModel model, bool isDraft)
|
|
|
|
|
{
|
|
|
|
|
string returnUrl = HttpContext.Request.Headers["Referer"].ToString();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Доступно только авторизованным пользователям");
|
|
|
|
|
}
|
|
|
|
|
if (model.Id != 0)
|
|
|
|
|
{
|
|
|
|
|
if (isDraft)
|
|
|
|
|
{
|
|
|
|
|
model.Status = CandidateReviewDataModels.Enums.ResumeStatusEnum.Черновик;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
model.Status = CandidateReviewDataModels.Enums.ResumeStatusEnum.Обрабатывается;
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/resume/update", model);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
model.UserId = APIClient.User.Id;
|
|
|
|
|
if (isDraft)
|
|
|
|
|
{
|
|
|
|
|
model.Status = CandidateReviewDataModels.Enums.ResumeStatusEnum.Черновик;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
model.Status = CandidateReviewDataModels.Enums.ResumeStatusEnum.Обрабатывается;
|
|
|
|
|
}
|
|
|
|
|
var vacancy = APIClient.GetRequest<VacancyViewModel>($"api/vacancy/details?id={model.VacancyId}");
|
|
|
|
|
var resume = APIClient.GetRequest<ResumeViewModel>($"api/resume/check?userId={model.UserId}&vacancyId={model.VacancyId}");
|
|
|
|
|
if (resume == null)
|
|
|
|
|
{
|
|
|
|
|
APIClient.PostRequest("api/resume/create", model);
|
|
|
|
|
if (APIClient.User != null)
|
|
|
|
|
{
|
|
|
|
|
APIClient.User?.Resumes.Add(new ResumeViewModel
|
|
|
|
|
{
|
2024-12-13 04:12:54 +04:00
|
|
|
|
Id = model.Id,
|
|
|
|
|
Description = model.Description,
|
|
|
|
|
Education = model.Education,
|
|
|
|
|
Experience = model.Experience,
|
|
|
|
|
Skills = model.Skills,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
Title = model.Title,
|
|
|
|
|
UserId = model.UserId,
|
|
|
|
|
VacancyId = model.VacancyId
|
2024-12-09 02:10:45 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Пользователь не найден");
|
|
|
|
|
}
|
|
|
|
|
if (vacancy != null)
|
|
|
|
|
{
|
|
|
|
|
vacancy.Resumes.Add(new ResumeViewModel
|
|
|
|
|
{
|
2024-12-13 04:12:54 +04:00
|
|
|
|
Id = model.Id,
|
|
|
|
|
Description = model.Description,
|
|
|
|
|
Education = model.Education,
|
|
|
|
|
Experience = model.Experience,
|
|
|
|
|
Skills = model.Skills,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
Title = model.Title,
|
|
|
|
|
UserId = model.UserId,
|
|
|
|
|
VacancyId = model.VacancyId
|
2024-12-09 02:10:45 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вакансия не найдена");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы уже создавали резюме на эту вакансию!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Redirect($"~/User/UserProfile/{model.UserId}");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Error", new { errorMessage = $"{ex.Message}", returnUrl });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Delete(int id)
|
|
|
|
|
{
|
|
|
|
|
string returnUrl = HttpContext.Request.Headers["Referer"].ToString();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
APIClient.PostRequest($"api/resume/delete", new ResumeBindingModel { Id = id });
|
|
|
|
|
return Redirect("~/User/UserProfile");
|
|
|
|
|
}
|
|
|
|
|
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 });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|