diff --git a/CandidateReviewBusinessLogic/BusinessLogic/AssessmentLogic.cs b/CandidateReviewBusinessLogic/BusinessLogic/AssessmentLogic.cs index 1ba42d6..91307f3 100644 --- a/CandidateReviewBusinessLogic/BusinessLogic/AssessmentLogic.cs +++ b/CandidateReviewBusinessLogic/BusinessLogic/AssessmentLogic.cs @@ -5,7 +5,7 @@ using CandidateReviewContracts.StoragesContracts; using CandidateReviewContracts.ViewModels; using CandidateReviewDataModels.Models; using Microsoft.Extensions.Logging; -using System.Text.RegularExpressions; +using System.Collections.Generic; namespace CandidateReviewBusinessLogic.BusinessLogic { @@ -13,43 +13,15 @@ namespace CandidateReviewBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IAssessmentStorage _assessmentStorage; - public AssessmentLogic(ILogger logger, IAssessmentStorage assessmentStorage) + private readonly IUserStorage _userStorage; + private readonly ICriterionStorage _criterionStorage; + + public AssessmentLogic(ILogger logger, IAssessmentStorage assessmentStorage, IUserStorage userStorage, ICriterionStorage criterionStorage) { _logger = logger; _assessmentStorage = assessmentStorage; - } - - public bool AddCriterionToAssessment(AssessmentSearchModel model, ICriterionModel criterion, int value) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - - if (criterion == null) - { - throw new ArgumentNullException(nameof(criterion)); - } - - var element = _assessmentStorage.GetElement(model); - - if (element == null) - { - return false; - } - - element.AssessmentCriterions[element.Id] = (criterion, value); - - _assessmentStorage.Update(new AssessmentBindingModel - { - Id = element.Id, - UserId = element.UserId, - ResumeId = element.ResumeId, - Comment = element.Comment, - AssessmentCriterions = element.AssessmentCriterions - }); - - return true; + _userStorage = userStorage; + _criterionStorage = criterionStorage; } public int? Create(AssessmentBindingModel model) @@ -95,13 +67,40 @@ namespace CandidateReviewBusinessLogic.BusinessLogic public List? ReadList(AssessmentSearchModel? model) { var list = model == null ? _assessmentStorage.GetFullList() : _assessmentStorage.GetFilteredList(model); - if (list == null) + List result = new(); + + foreach (var elem in list) + { + var user = _userStorage.GetElement(new UserSearchModel { Id = elem.UserId }); + var assessmentCriterions = _assessmentStorage.GetAssessmentCriterions(elem.Id); + + var assessmentViewModel = new AssessmentViewModel + { + Id = elem.Id, + ResumeId = elem.ResumeId, + UserId = elem.UserId, + UserName = user.Name + " " + user.Name, + Comment = elem.Comment, + AssessmentCriterions = assessmentCriterions.Select(ac => new AssessmentCriterionViewModel + { + AssessmentId = ac.AssessmentId, + CriterionId = ac.CriterionId, + Value = ac.Value, + CriterionName = _criterionStorage.GetElement(new CriterionSearchModel { Id = ac.CriterionId })?.Name + }).ToList() + }; + + result.Add(assessmentViewModel); + } + + if (result == null) { _logger.LogWarning("ReadList return null list"); return null; } - _logger.LogInformation("ReadList. Count: {Count}", list.Count); - return list; + + _logger.LogInformation("ReadList. Count: {Count}", result.Count); + return result; } public bool Update(AssessmentBindingModel model) diff --git a/CandidateReviewBusinessLogic/BusinessLogic/ResumeLogic.cs b/CandidateReviewBusinessLogic/BusinessLogic/ResumeLogic.cs index f24aa55..0bdcafc 100644 --- a/CandidateReviewBusinessLogic/BusinessLogic/ResumeLogic.cs +++ b/CandidateReviewBusinessLogic/BusinessLogic/ResumeLogic.cs @@ -4,6 +4,7 @@ using CandidateReviewContracts.SearchModels; using CandidateReviewContracts.StoragesContracts; using CandidateReviewContracts.ViewModels; using Microsoft.Extensions.Logging; +using System.Xml.Linq; namespace CandidateReviewBusinessLogic.BusinessLogic { @@ -84,6 +85,7 @@ namespace CandidateReviewBusinessLogic.BusinessLogic Status = element.Status, Assessments = assessmentViewModels }; + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); return resumeViewModel; } @@ -96,8 +98,39 @@ namespace CandidateReviewBusinessLogic.BusinessLogic _logger.LogWarning("ReadList return null list"); return null; } + List result = new(); + foreach (var element in list) + { + var assessments = _assessmentStorage.GetFilteredList(new AssessmentSearchModel { UserId = element.Id }); + var assessmentViewModels = assessments?.Select(a => new AssessmentViewModel + { + Id = a.Id, + ResumeId = a.ResumeId, + UserId = a.UserId, + Comment = a.Comment, + AssessmentCriterions = a.AssessmentCriterions + }).ToList() ?? new List(); + + var resumeViewModel = new ResumeViewModel + { + Id = element.Id, + VacancyId = element.VacancyId, + VacancyName = _vacancyStorage.GetElement(new VacancySearchModel { Id = element.VacancyId }).JobTitle, + UserId = element.UserId, + UserName = _userStorage.GetElement(new UserSearchModel { Id = element.UserId }).Name + " " + _userStorage.GetElement(new UserSearchModel { Id = element.UserId }).Surname, + Title = element.Title, + Experience = element.Experience, + Education = element.Education, + PhotoFilePath = element.PhotoFilePath, + Description = element.Description, + Skills = element.Skills, + Status = element.Status, + Assessments = assessmentViewModels + }; + result.Add(resumeViewModel); + } _logger.LogInformation("ReadList. Count: {Count}", list.Count); - return list; + return result; } public bool Update(ResumeBindingModel model) diff --git a/CandidateReviewBusinessLogic/BusinessLogic/UserLogic.cs b/CandidateReviewBusinessLogic/BusinessLogic/UserLogic.cs index f4656d5..a3ddea4 100644 --- a/CandidateReviewBusinessLogic/BusinessLogic/UserLogic.cs +++ b/CandidateReviewBusinessLogic/BusinessLogic/UserLogic.cs @@ -71,6 +71,7 @@ namespace CandidateReviewBusinessLogic.BusinessLogic { Id = r.Id, VacancyId = r.VacancyId, + UserName = element.Name + " " + element.Surname, VacancyName = _vacancyStorage.GetElement(new VacancySearchModel { Id = r.VacancyId }).JobTitle, UserId = r.UserId, Title = r.Title, diff --git a/CandidateReviewBusinessLogic/BusinessLogic/VacancyLogic.cs b/CandidateReviewBusinessLogic/BusinessLogic/VacancyLogic.cs index 88f2d2c..d843b3f 100644 --- a/CandidateReviewBusinessLogic/BusinessLogic/VacancyLogic.cs +++ b/CandidateReviewBusinessLogic/BusinessLogic/VacancyLogic.cs @@ -14,13 +14,15 @@ namespace CandidateReviewBusinessLogic.BusinessLogic private readonly IVacancyStorage _vacancyStorage; private readonly IResumeStorage _resumeStorage; private readonly ICompanyStorage _companyStorage; + private readonly IUserStorage _userStorage; - public VacancyLogic(ILogger logger, IVacancyStorage vacancyStorage, IResumeStorage resumeStorage, ICompanyStorage companyStorage) + public VacancyLogic(ILogger logger, IVacancyStorage vacancyStorage, IResumeStorage resumeStorage, ICompanyStorage companyStorage, IUserStorage userStorage) { _logger = logger; _vacancyStorage = vacancyStorage; _resumeStorage = resumeStorage; _companyStorage = companyStorage; + _userStorage = userStorage; } public bool Create(VacancyBindingModel model) { @@ -63,7 +65,7 @@ namespace CandidateReviewBusinessLogic.BusinessLogic Id = r.Id, VacancyId = r.VacancyId, VacancyName = _vacancyStorage.GetElement(new VacancySearchModel { Id = r.VacancyId }).JobTitle, - UserName = r.UserName, + UserName = _userStorage.GetElement(new UserSearchModel { Id = r.UserId}).Name + " " + _userStorage.GetElement(new UserSearchModel { Id = r.UserId }).Surname, UserId = r.UserId, Title = r.Title, Experience = r.Experience, diff --git a/CandidateReviewBusinessLogic/CandidateReviewBusinessLogic.csproj b/CandidateReviewBusinessLogic/CandidateReviewBusinessLogic.csproj index bd4d62e..d7cb571 100644 --- a/CandidateReviewBusinessLogic/CandidateReviewBusinessLogic.csproj +++ b/CandidateReviewBusinessLogic/CandidateReviewBusinessLogic.csproj @@ -12,6 +12,7 @@ + diff --git a/CandidateReviewClientApp/Controllers/AssessmentController.cs b/CandidateReviewClientApp/Controllers/AssessmentController.cs index f97989c..4fa8dcb 100644 --- a/CandidateReviewClientApp/Controllers/AssessmentController.cs +++ b/CandidateReviewClientApp/Controllers/AssessmentController.cs @@ -17,6 +17,8 @@ namespace CandidateReviewClientApp.Controllers _logger = logger; } + + [HttpPost] public async Task AddAssessmentCriterion(int resumeId, int[] criterion, int[] value, string comment) { @@ -42,29 +44,12 @@ namespace CandidateReviewClientApp.Controllers ResumeId = resumeId, UserId = userId, Comment = comment, - AssessmentCriterions = new Dictionary() + AssessmentCriterions = criterion.Select((t, i) => new KeyValuePair + (t, (new CriterionViewModel { Id = t }, value[i]))).ToDictionary(kv => kv.Key, kv => kv.Value) }; - var assessmentId = await APIClient.PostRequestAsync("api/assessment/create", assessmentModel); - for (int i = 0; i < criterion.Length; i++) - { - if (value[i] < 1 || value[i] > 5) - { - throw new ArgumentException($"Оценка для критерия {criterion[i]} должна быть от 1 до 5."); - } - - if (assessmentData.ContainsKey(assessmentId)) - { - assessmentData[assessmentId] = (new CriterionViewModel { Id = criterion[i] }, value[i]); - } - else - { - assessmentData.Add(assessmentId, (new CriterionViewModel { Id = criterion[i] }, value[i])); - } - } - - APIClient.PostRequest("api/assessment/AddCriterionToAssessment", assessmentData); + int assessmentId = await APIClient.PostRequestAsync("api/assessment/create", assessmentModel); return Redirect($"~/Resume/ResumeDetails/{resumeId}"); } diff --git a/CandidateReviewClientApp/Controllers/ResumeController.cs b/CandidateReviewClientApp/Controllers/ResumeController.cs index 31d86ec..1378462 100644 --- a/CandidateReviewClientApp/Controllers/ResumeController.cs +++ b/CandidateReviewClientApp/Controllers/ResumeController.cs @@ -28,12 +28,16 @@ namespace CandidateReviewClientApp.Controllers { return View(); } - var assessments = APIClient.GetRequest>($"api/assessment/listByResumeId?id={id}"); + + var resumeAssessments = APIClient.GetRequest>($"api/assessment/listByResumeId?id={id}"); + var userAssessment = resumeAssessments?.FirstOrDefault(a => a.UserId == APIClient.User.Id); var criterions = APIClient.GetRequest>($"api/criterion/list"); - resume.Assessments = assessments; + resume.Assessments = resumeAssessments ?? new List(); + ViewBag.UserAssessment = userAssessment; ViewBag.Criterions = criterions; + return View(resume); - } + } [HttpGet] public async Task EditResume(int? id, int? vacancyId) diff --git a/CandidateReviewClientApp/Views/Company/CompanyProfile.cshtml b/CandidateReviewClientApp/Views/Company/CompanyProfile.cshtml index 19f96dd..e623865 100644 --- a/CandidateReviewClientApp/Views/Company/CompanyProfile.cshtml +++ b/CandidateReviewClientApp/Views/Company/CompanyProfile.cshtml @@ -8,43 +8,53 @@
-
- Логотип компании -
+
+ Логотип компании +
@Model.Name
-

@(Model.Description == null ? "Описание отсутствует" : Model.Description)

- @(Model.Website != null ? "Официальный сайт" : "Веб-сайт отсутствует") @(Model.Website != null ? "" : "disabled") +

@((Model.Description ?? "Описание отсутствует"))

+ + @(Model.Website != null ? "Официальный сайт" : "Веб-сайт отсутствует") +
+
-
+

Информация о компании

- Редактировать + Редактировать
Адрес:
-
@(Model.Address?.ToString() ?? "Адрес не указан")
+
@((Model.Address?.ToString() ?? "Адрес не указан"))
Контакты:
-
@(Model.Contacts?.ToString() ?? "Контакты не указаны")
+
@((Model.Contacts?.ToString() ?? "Контакты не указаны"))
-
+
@if (Model.Vacancies != null && Model.Vacancies.Any()) { @await Html.PartialAsync("_VacanciesTable", Model.Vacancies.Take(5)) - @if (Model.Vacancies.Count() > 5) + @if (Model.Vacancies.Count() > 5) { } @@ -59,11 +69,12 @@ }
-
-
+ +
@if (Model.Employees != null && Model.Employees.Any()) @@ -83,16 +94,17 @@ @employee.Surname @employee.Name - @employee.Email - - + + Просмотр - - + + + Редактировать - - + + + Удалить @@ -106,6 +118,7 @@ }
+
diff --git a/CandidateReviewClientApp/Views/Home/Index.cshtml b/CandidateReviewClientApp/Views/Home/Index.cshtml index 9b1f853..a220f38 100644 --- a/CandidateReviewClientApp/Views/Home/Index.cshtml +++ b/CandidateReviewClientApp/Views/Home/Index.cshtml @@ -8,44 +8,39 @@
-

Создать профиль своей компании

-

Здесь вы можете создать и настроить профиль вашей компании, указать основные данные. Профиль вашей компании будет виден кандидатам, что поможет вам привлечь их внимание к вакансиям, которые вы предлагаете.

+

Создать профиль компании

Подобрать кандидатов на вакансию

-

Используйте наш удобный инструмент для подбора кандидатов на вакансию. Вы можете просмотреть параметры возможных кандидатов. Это упростит процесс поиска подходящих кандидатов для ваших вакансий и даст вам больше шансов найти именно того, кто вам нужен.

Найти подходящую вакансию

-

Если вы ищете работу, здесь вы можете просмотреть все доступные вакансии. Мы стремимся помочь вам найти именно то рабочее место, которое соответствует вашим ожиданиям и интересам.

Оценить кандидатов на вакансию

-

После просмотра резюме у вас есть возможность оценить кандидатов и оставить свои комментарии. Вы можете выставить оценки по различным критериям и добавить свои заметки. Это поможет в дальнейшем процессе выбора и предоставляет общую картину по каждому кандидату, что значительно упрощает принятие решения.

-
diff --git a/CandidateReviewClientApp/Views/Resume/ResumeDetails.cshtml b/CandidateReviewClientApp/Views/Resume/ResumeDetails.cshtml index f73f58a..feb204d 100644 --- a/CandidateReviewClientApp/Views/Resume/ResumeDetails.cshtml +++ b/CandidateReviewClientApp/Views/Resume/ResumeDetails.cshtml @@ -1,6 +1,7 @@ @using CandidateReviewDataModels.Models @using Microsoft.AspNetCore.Mvc.TagHelpers @using CandidateReviewContracts.ViewModels +@using Newtonsoft.Json @model ResumeViewModel @{ @@ -64,36 +65,100 @@

Оценка резюме

- + - @if (ViewBag.Criterions != null) - { - foreach (var criterion in ViewBag.Criterions) +
+
+ @if (Model.Assessments.Any()) + { + foreach (var assessment in Model.Assessments) + { + // Если это пользовательская оценка, пропускаем её, так как она будет отображена отдельно. + if (ViewBag.UserAssessment is AssessmentViewModel currentUserAssessment && assessment.UserId == currentUserAssessment.UserId) + { + continue; + } + +

Оценка пользователя: @assessment.UserName

+ @foreach (var criterion in assessment.AssessmentCriterions) + { +
+
+ +
+
+ +
+
+ } +

Комментарий: @assessment.Comment

+ } + } + else + { +

Это резюме еще никто не оценивал. Станьте первыми!

+ } +
+ + @if (ViewBag.UserAssessment is AssessmentViewModel userAssessment) { -
-
- -
-
- - -
+
+

Ваша оценка

+ @foreach (var criterion in userAssessment.AssessmentCriterions) + { +
+
+ +
+
+ +
+
+ } +

Комментарий: @userAssessment.Comment

} - } - else - { -

Нет доступных критериев.

- } + else + { +
+
+
+ +
+
+ +
+
+ +
+
+
-
-
- - -
+ + +
+
+ + +
+
+ + + }
- -
@@ -103,7 +168,49 @@
diff --git a/CandidateReviewClientApp/Views/Shared/_VacanciesTable.cshtml b/CandidateReviewClientApp/Views/Shared/_VacanciesTable.cshtml index 49eba73..7d26726 100644 --- a/CandidateReviewClientApp/Views/Shared/_VacanciesTable.cshtml +++ b/CandidateReviewClientApp/Views/Shared/_VacanciesTable.cshtml @@ -17,13 +17,13 @@ @vacancy.JobType @vacancy.Status - + - + - + diff --git a/CandidateReviewClientApp/Views/User/UserProfile.cshtml b/CandidateReviewClientApp/Views/User/UserProfile.cshtml index 154b5fd..1059739 100644 --- a/CandidateReviewClientApp/Views/User/UserProfile.cshtml +++ b/CandidateReviewClientApp/Views/User/UserProfile.cshtml @@ -9,8 +9,9 @@
-
- Аватар пользователя +
+ Аватар пользователя
@(string.IsNullOrEmpty(@Model?.Surname) ? "" : @Model?.Surname) @Model?.Name @(string.IsNullOrEmpty(@Model?.LastName) ? "" : @Model?.LastName) @@ -41,9 +42,10 @@ @if (userRole) {
-
-
+
+

Мои резюме

+ Создать резюме
@if (Model.Resumes != null && Model.Resumes.Any()) @@ -91,3 +93,77 @@
+ + +@section Scripts { + +} diff --git a/CandidateReviewClientApp/Views/Vacancy/SearchVacancies.cshtml b/CandidateReviewClientApp/Views/Vacancy/SearchVacancies.cshtml index a9eea30..3e6dbc0 100644 --- a/CandidateReviewClientApp/Views/Vacancy/SearchVacancies.cshtml +++ b/CandidateReviewClientApp/Views/Vacancy/SearchVacancies.cshtml @@ -8,27 +8,29 @@
-

Поиск вакансий

+

Поиск вакансий

+
-
- - +
+ +
@if (Model != null) { -

Результаты поиска:

+

Результаты поиска:

+ @if (Model.Any(v => v != null)) { - - +
+ - + @@ -40,8 +42,8 @@ } @@ -50,17 +52,80 @@ } else { -

Вакансий не найдено.

+

Вакансий не найдено.

} } else { -

Произошла ошибка при получении данных.

+

Произошла ошибка при получении данных.

} + + - diff --git a/CandidateReviewContracts/BusinessLogicsContracts/IAssessmentLogic.cs b/CandidateReviewContracts/BusinessLogicsContracts/IAssessmentLogic.cs index bd04b45..a77edcc 100644 --- a/CandidateReviewContracts/BusinessLogicsContracts/IAssessmentLogic.cs +++ b/CandidateReviewContracts/BusinessLogicsContracts/IAssessmentLogic.cs @@ -1,7 +1,6 @@ using CandidateReviewContracts.BindingModels; using CandidateReviewContracts.SearchModels; using CandidateReviewContracts.ViewModels; -using CandidateReviewDataModels.Models; namespace CandidateReviewContracts.BusinessLogicsContracts { @@ -10,7 +9,6 @@ namespace CandidateReviewContracts.BusinessLogicsContracts List? ReadList(AssessmentSearchModel? model); AssessmentViewModel? ReadElement(AssessmentSearchModel model); int? Create(AssessmentBindingModel model); - bool AddCriterionToAssessment(AssessmentSearchModel model, ICriterionModel criterion, int value); bool Update(AssessmentBindingModel model); bool Delete(AssessmentBindingModel model); } diff --git a/CandidateReviewContracts/SearchModels/AssessmentSearchModel.cs b/CandidateReviewContracts/SearchModels/AssessmentSearchModel.cs index fbf0963..9ed5d41 100644 --- a/CandidateReviewContracts/SearchModels/AssessmentSearchModel.cs +++ b/CandidateReviewContracts/SearchModels/AssessmentSearchModel.cs @@ -1,4 +1,6 @@ -namespace CandidateReviewContracts.SearchModels +using CandidateReviewDataModels.Models; + +namespace CandidateReviewContracts.SearchModels { public class AssessmentSearchModel { @@ -8,5 +10,7 @@ public int? ResumeId { get; set; } public int? Id { get; set; } + + public Dictionary AssessmentCriterions = new(); } } diff --git a/CandidateReviewContracts/StoragesContracts/IAssessmentStorage.cs b/CandidateReviewContracts/StoragesContracts/IAssessmentStorage.cs index 525f924..3db51fd 100644 --- a/CandidateReviewContracts/StoragesContracts/IAssessmentStorage.cs +++ b/CandidateReviewContracts/StoragesContracts/IAssessmentStorage.cs @@ -8,6 +8,7 @@ namespace CandidateReviewContracts.StoragesContracts { List GetFullList(); List GetFilteredList(AssessmentSearchModel model); + List? GetAssessmentCriterions(int? assessmentId); AssessmentViewModel? GetElement(AssessmentSearchModel model); int? Insert(AssessmentBindingModel model); AssessmentViewModel? Update(AssessmentBindingModel model); diff --git a/CandidateReviewContracts/ViewModels/AssessmentCriterionViewModel.cs b/CandidateReviewContracts/ViewModels/AssessmentCriterionViewModel.cs new file mode 100644 index 0000000..76ad759 --- /dev/null +++ b/CandidateReviewContracts/ViewModels/AssessmentCriterionViewModel.cs @@ -0,0 +1,17 @@ +using CandidateReviewDataModels.Models; + +namespace CandidateReviewContracts.ViewModels +{ + public class AssessmentCriterionViewModel : IAssessmentCriterionModel + { + public int AssessmentId { get; set; } + + public int CriterionId { get; set; } + + public string CriterionName { get; set; } = string.Empty; + + public int Value { get; set; } + + public int Id { get; set; } + } +} diff --git a/CandidateReviewContracts/ViewModels/AssessmentViewModel.cs b/CandidateReviewContracts/ViewModels/AssessmentViewModel.cs index 627d58e..24b46d9 100644 --- a/CandidateReviewContracts/ViewModels/AssessmentViewModel.cs +++ b/CandidateReviewContracts/ViewModels/AssessmentViewModel.cs @@ -6,12 +6,14 @@ namespace CandidateReviewContracts.ViewModels { public int? UserId { get; set; } + public string? UserName { get; set; } + public string? Comment { get; set; } public int Id { get; set; } public int? ResumeId { get; set; } - public Dictionary AssessmentCriterions { get; set; } = new(); + public List AssessmentCriterions { get; set; } = new(); } } diff --git a/CandidateReviewDataModels/Models/IAssessmentCriterionModel.cs b/CandidateReviewDataModels/Models/IAssessmentCriterionModel.cs new file mode 100644 index 0000000..61d3dce --- /dev/null +++ b/CandidateReviewDataModels/Models/IAssessmentCriterionModel.cs @@ -0,0 +1,9 @@ +namespace CandidateReviewDataModels.Models +{ + public interface IAssessmentCriterionModel : IId + { + int AssessmentId { get; } + int CriterionId { get; } + int Value { get; } + } +} diff --git a/CandidateReviewDatabaseImplement/Implements/AssessmentStorage.cs b/CandidateReviewDatabaseImplement/Implements/AssessmentStorage.cs index fc47e0e..8fa9982 100644 --- a/CandidateReviewDatabaseImplement/Implements/AssessmentStorage.cs +++ b/CandidateReviewDatabaseImplement/Implements/AssessmentStorage.cs @@ -3,6 +3,7 @@ using CandidateReviewContracts.SearchModels; using CandidateReviewContracts.StoragesContracts; using CandidateReviewContracts.ViewModels; using CandidateReviewDatabaseImplement.Models; +using CandidateReviewDataModels.Models; using Microsoft.EntityFrameworkCore; namespace CandidateReviewDatabaseImplement.Implements @@ -38,23 +39,42 @@ namespace CandidateReviewDatabaseImplement.Implements return null; } using var context = new CandidateReviewDatabase(); - if (model.ResumeId.HasValue) + if (model.ResumeId.HasValue && model.UserId.HasValue) + { + return context.Assessments + .FirstOrDefault(x => x.ResumeId == model.ResumeId && x.UserId == model.UserId) + ?.GetViewModel; + } + else if (model.ResumeId.HasValue) { return context.Assessments .FirstOrDefault(x => x.ResumeId == model.ResumeId) ?.GetViewModel; } - - if (model.UserId.HasValue) + else if (model.UserId.HasValue) { return context.Assessments .FirstOrDefault(x => x.UserId == model.UserId) ?.GetViewModel; } - return context.Assessments - .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) - ?.GetViewModel; + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; + } + + public List? GetAssessmentCriterions(int? assessmentId) + { + if (!assessmentId.HasValue) + { + return null; + } + using var context = new CandidateReviewDatabase(); + + return context.AssessmentCriterions + .Where(x => x.AssessmentId == assessmentId) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(AssessmentSearchModel model) @@ -102,16 +122,27 @@ namespace CandidateReviewDatabaseImplement.Implements public int? Insert(AssessmentBindingModel model) { using var context = new CandidateReviewDatabase(); - var newAssessment = Assessment.Create(context, model); - if (newAssessment == null) + var newAssessment = new Assessment { - return null; - } + ResumeId = model.ResumeId, + UserId = model.UserId, + Comment = model.Comment + }; context.Assessments.Add(newAssessment); context.SaveChanges(); + /*var criterionsToAdd = model.AssessmentCriterions.Select(x => new AssessmentCriterion + { + AssessmentId = newAssessment.Id, + Criterion = context.Criterions.First(y => y.Id == x.Key), + Value = x.Value.Item2 + }).ToList(); + + context.AssessmentCriterions.AddRange(criterionsToAdd); + context.SaveChanges();*/ + return newAssessment.Id; } diff --git a/CandidateReviewDatabaseImplement/Models/Assessment.cs b/CandidateReviewDatabaseImplement/Models/Assessment.cs index 8795938..4fbaafe 100644 --- a/CandidateReviewDatabaseImplement/Models/Assessment.cs +++ b/CandidateReviewDatabaseImplement/Models/Assessment.cs @@ -43,19 +43,18 @@ namespace CandidateReviewDatabaseImplement.Models { return null; } - return new Assessment() + + var assessment = new Assessment { Id = model.Id, ResumeId = model.ResumeId, UserId = model.UserId, Comment = model.Comment, - Criterions = model.AssessmentCriterions.Select(x => new AssessmentCriterion() - { - Criterion = context.Criterions.First(y => y.Id == x.Key), - Value = x.Value.Item2 - }).ToList() }; + + return assessment; } + public void Update(AssessmentBindingModel model) { if (model == null) @@ -66,12 +65,24 @@ namespace CandidateReviewDatabaseImplement.Models UserId = model.UserId; Comment = model.Comment; } + + private List GetAssessmentCriterionsAsViewModel() + { + return AssessmentCriterions.Select(ac => new AssessmentCriterionViewModel + { + CriterionId = ac.Key, + Value = ac.Value.Item2, + }).ToList(); + } + + public AssessmentViewModel GetViewModel => new() { Id = Id, ResumeId = ResumeId, UserId = UserId, - Comment = Comment + Comment = Comment, + AssessmentCriterions = GetAssessmentCriterionsAsViewModel() }; public void UpdateCriterions(CandidateReviewDatabase context, AssessmentBindingModel model) diff --git a/CandidateReviewDatabaseImplement/Models/AssessmentCriterion.cs b/CandidateReviewDatabaseImplement/Models/AssessmentCriterion.cs index 105d3e0..c47a395 100644 --- a/CandidateReviewDatabaseImplement/Models/AssessmentCriterion.cs +++ b/CandidateReviewDatabaseImplement/Models/AssessmentCriterion.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using CandidateReviewContracts.ViewModels; +using System.ComponentModel.DataAnnotations; namespace CandidateReviewDatabaseImplement.Models { @@ -13,5 +14,13 @@ namespace CandidateReviewDatabaseImplement.Models public int Value { get; set; } public virtual Assessment Assessment { get; set; } = new(); public virtual Criterion Criterion { get; set; } = new(); + + public AssessmentCriterionViewModel GetViewModel => new() + { + Id = Id, + AssessmentId = AssessmentId, + CriterionId = CriterionId, + Value = Value + }; } } diff --git a/CandidateReviewRestApi/Controllers/AssessmentController.cs b/CandidateReviewRestApi/Controllers/AssessmentController.cs index a12bbb1..e28666f 100644 --- a/CandidateReviewRestApi/Controllers/AssessmentController.cs +++ b/CandidateReviewRestApi/Controllers/AssessmentController.cs @@ -25,30 +25,13 @@ namespace CandidateReviewRestApi.Controllers try { return _logic.ReadElement(new AssessmentSearchModel - { - Id = id - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения оценки"); - throw; - } - } - - [HttpGet] - public List? ListByUserId(int id) - { - try - { - return _logic.ReadList(new AssessmentSearchModel { UserId = id }); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения оценок"); + _logger.LogError(ex, "Ошибка получения оценки"); throw; } } @@ -71,12 +54,12 @@ namespace CandidateReviewRestApi.Controllers } [HttpPost] - public int? Create(AssessmentBindingModel model) + public IActionResult Create(AssessmentBindingModel model) { try { int? id = _logic.Create(model); - return id; + return Ok(new AssessmentBindingModel { Id = (int)id }); } catch (Exception ex) { @@ -84,53 +67,6 @@ namespace CandidateReviewRestApi.Controllers throw; } } - [HttpPost] - public void AddCriterionToAssessment(Dictionary 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)
Название вакансии Тип работы Зарплата ТэгиДействияДействия
@vacancy.Salary @vacancy.Tags - Просмотр - Составить резюме + Просмотр + Составить резюме