public async Task GetCandidateById_WithCorrectInputData_ShouldReturnCandidate() { this.SeedTestData(this.DbContext); CandidateServiceModel expected = this.DbContext.Candidates.First().To <CandidateServiceModel>(); CandidateServiceModel actual = await this.CandidatesServiceMock.GetCandidateById(expected.Id); Assert.True( expected.FirstName == actual.FirstName, "CandidatesService GetCandidateById() not works properly!"); Assert.True( expected.MiddleName == actual.MiddleName, "CandidatesService GetCandidateById() not works properly!"); Assert.True( expected.LastName == actual.LastName, "CandidatesService GetCandidateById() not works properly!"); Assert.True( expected.UCN == actual.UCN, "CandidatesService GetCandidateById() not works properly!"); Assert.True( expected.Mother.FullName == actual.Mother.FullName, "CandidatesService GetCandidateById() not works properly!"); Assert.True( expected.Father.FullName == actual.Father.FullName, "CandidatesService GetCandidateById() not works properly!"); }
public async Task <IActionResult> Profile(int id) { CandidateServiceModel candidate = await this.candidatesService.GetCandidateById(id); if (candidate == null || candidate.User.UserName != this.User.Identity.Name) { return(this.View("_AccessDenied")); } var procedureStatus = (await this.adminService.GetLastProcedure()).Status.ToString(); CandidateProfileViewModel model = new CandidateProfileViewModel(); model.CandidateId = id; model.CandidateName = candidate.FirstName; model.CandidateStatus = candidate.Status.ToString(); model.ProcedureStatus = procedureStatus; int basicScores = candidate.BasicScores; int totalScores = 0; foreach (var schApp in candidate.Applications) { var schoolName = (await this.schoolsService.GetSchoolDetailsById(schApp.SchoolId)).Name; int additionalScoresForApplication = schApp.AdditionalScoresForSchool; totalScores = basicScores + additionalScoresForApplication; model.ScoresByApplications.Add(schoolName, totalScores); } var sortedApplications = model.ScoresByApplications.OrderByDescending(x => x.Value); model.ScoresByApplications = sortedApplications.ToDictionary(x => x.Key, y => y.Value); model.CandidateName = candidate.FullName; return(this.View(model)); }
public async Task <IActionResult> Criteria(int id) { CandidateServiceModel candidate = await this.candidatesService.GetCandidateById(id); if (candidate == null || candidate.User.UserName != this.User.Identity.Name) { return(this.View("_AccessDenied")); } ScoresByCriteriasOnCandidateViewModel model = new ScoresByCriteriasOnCandidateViewModel(); model.CandidateId = id; model.ScoresByCriteria = new List <ScoreByCriteriaOnCandidateViewModel>(); var schoolsCriteria = new List <ScoreByCriteriaOnCandidateViewModel>(); var basicCriteria = new List <ScoreByCriteriaOnCandidateViewModel>(); IEnumerable <CriteriaForCandidateServiceModel> criteriasOfCandidate = await this.criteriasService.GetCriteriasAndScoresByCandidateId(id); IEnumerable <CriteriaServiceModel> allcriterias = await this.criteriasService.GetAllCriterias(); foreach (var criteriaOfCandidate in criteriasOfCandidate) { ScoreByCriteriaOnCandidateViewModel criteriaModel = new ScoreByCriteriaOnCandidateViewModel(); if (criteriaOfCandidate.Sch == 0) { criteriaModel.CriteriaDisplayName = criteriaOfCandidate.Criteria.DisplayName; criteriaModel.CriteriaScores = criteriaOfCandidate.Criteria.Scores; basicCriteria.Add(criteriaModel); } else if (criteriaOfCandidate.Sch != 0) { var appIds = this.candidatesService.GetCandidateApplications(candidate.Id); foreach (var appId in appIds) { if (appId == criteriaOfCandidate.Sch) { criteriaModel.CriteriaDisplayName = criteriaOfCandidate.Criteria.DisplayName; criteriaModel.CriteriaScores = criteriaOfCandidate.Criteria.Scores; criteriaModel.SchoolName = (await this.schoolsService.GetSchoolDetailsById(criteriaOfCandidate.Sch)).Name; schoolsCriteria.Add(criteriaModel); } } } } model.ScoresByCriteria.AddRange(basicCriteria); schoolsCriteria.Distinct(); model.ScoresByCriteria.AddRange(schoolsCriteria); model.CandidateName = candidate.FullName; return(this.View(model)); }
public async Task <IActionResult> Edit(int id, EditCandidateInputModel input) { if (!this.ModelState.IsValid) { var motherFullName = await this.parentsService .GetParentFullNameByRole(this.User, ParentRole.Майка); var motherList = new List <string> { $"{motherFullName}", ParentRole.Друг.ToString(), ParentRole.Няма.ToString(), }; var fatherFullName = await this.parentsService .GetParentFullNameByRole(this.User, ParentRole.Баща); var fatherList = new List <string> { $"{fatherFullName}", ParentRole.Друг.ToString(), ParentRole.Няма.ToString(), }; this.ViewData["Mother"] = motherList; this.ViewData["Father"] = fatherList; return(this.View(input)); } ClaimsPrincipal userIdentity = this.User; CandidateServiceModel candidatToEdit = input.To <CandidateServiceModel>(); int motherId = await this.parentsService.GetParentIdByFullName(userIdentity, input.MotherFullName); int fatherId = await this.parentsService.GetParentIdByFullName(userIdentity, input.FatherFullName); candidatToEdit.MotherId = motherId; candidatToEdit.FatherId = fatherId; await this.candidatesService.Edit(id, userIdentity, candidatToEdit); return(this.Redirect("/")); }
public async Task <IActionResult> AddApplications(int id) { CandidateServiceModel candidate = await this.candidatesService.GetCandidateById(id); if (candidate == null || candidate.User.UserName != this.User.Identity.Name) { return(this.View("_AccessDenied")); } IQueryable <SchoolServiceModel> allSchools = null; if (candidate.MotherId == 1 || candidate.MotherId == 2 || candidate.FatherId == 1 || candidate.FatherId == 2) { allSchools = this.schoolsService .GetAllSchools(); } else { allSchools = this.schoolsService .GetAllSchools() .Where(x => x.District.Id == candidate.Mother.Address.PermanentDistrictId || x.District.Id == candidate.Mother.Address.CurrentDistrictId || x.District.Id == candidate.Father.Address.PermanentDistrictId || x.District.Id == candidate.Father.Address.CurrentDistrictId || x.District.Id == candidate.Mother.WorkDistrictId || x.District.Id == candidate.Father.WorkDistrictId); } this.ViewData["AllSchools"] = allSchools .Select(p => new AddSchoolApplicationsViewModel { Id = p.Id, Name = p.Name, DistrictName = p.District.Name }) .ToList(); AddApplicationsInputModel model = new AddApplicationsInputModel(); model.CandidateId = candidate.Id; model.CandidateName = candidate.FullName; return(this.View("AddApplications", model)); }
public async Task <bool> Edit(int id, ClaimsPrincipal userIdentity, CandidateServiceModel candidateServiceModel) { Candidate candidateToEdit = await this.candidatesRepository.All() .FirstOrDefaultAsync(p => p.Id == id); if (candidateToEdit == null) { throw new ArgumentNullException(string.Format(GlobalConstants.NullReferenceCandidateId, id)); } var userId = this.userManager.GetUserId(userIdentity); candidateToEdit.UserId = userId; candidateToEdit.UCN = candidateToEdit.UCN; candidateToEdit.Desease = candidateServiceModel.Desease; candidateToEdit.SEN = candidateServiceModel.SEN; candidateToEdit.Immunization = candidateServiceModel.Immunization; candidateToEdit.KinderGarten = candidateServiceModel.KinderGarten; candidateToEdit.FirstName = candidateServiceModel.FirstName; candidateToEdit.MiddleName = candidateServiceModel.MiddleName; candidateToEdit.LastName = candidateServiceModel.LastName; candidateToEdit.FatherId = candidateServiceModel.FatherId; candidateToEdit.MotherId = candidateServiceModel.MotherId; this.candidatesRepository.Update(candidateToEdit); var result = await this.candidatesRepository.SaveChangesAsync(); await this.criteriasService.DeleteCriteriasByCandidateId(candidateToEdit.Id); int basicScores = await this.calculatorService.CalculateBasicScoresByCriteria(id); candidateToEdit.BasicScores = basicScores; this.candidatesRepository.Update(candidateToEdit); result = await this.candidatesRepository.SaveChangesAsync(); return(result > 0); }
public async Task <bool> Create(ClaimsPrincipal userIdentity, CandidateServiceModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var userId = this.userManager.GetUserId(userIdentity); Candidate candidate = new Candidate { FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, UCN = model.UCN, UserId = userId, MotherId = model.MotherId, FatherId = model.FatherId, Desease = model.Desease, SEN = model.SEN, Immunization = model.Immunization, KinderGarten = model.KinderGarten, }; await this.candidatesRepository.AddAsync(candidate); var result = await this.candidatesRepository.SaveChangesAsync(); int candidateId = candidate.Id; int basicScores = await this.calculatorService.CalculateBasicScoresByCriteria(candidateId); candidate.BasicScores = basicScores; this.candidatesRepository.Update(candidate); result = await this.candidatesRepository.SaveChangesAsync(); return(result > 0); }
public async Task <IActionResult> Create(CreateCandidateInputModel input) { if (!this.ModelState.IsValid) { var motherFullName = await this.parentsService .GetParentFullNameByRole(this.User, ParentRole.Майка); var motherList = new List <string> { $"{motherFullName}", ParentRole.Друг.ToString(), ParentRole.Няма.ToString(), }; var fatherFullName = await this.parentsService .GetParentFullNameByRole(this.User, ParentRole.Баща); var fatherList = new List <string> { $"{fatherFullName}", ParentRole.Друг.ToString(), ParentRole.Няма.ToString(), }; this.ViewData["Mother"] = motherList; this.ViewData["Father"] = fatherList; return(this.View(input)); } ClaimsPrincipal userIdentity = this.User; var parents = this.parentsService.GetParentsWithOtherAndNull(userIdentity); ParentServiceModel motherServiceModel = await parents.Where(p => p.FullName.TrimEnd().Equals(input.MotherFullName)).FirstOrDefaultAsync(); ParentServiceModel fatherServiceModel = await parents.Where(p => p.FullName.TrimEnd().Equals(input.FatherFullName)).FirstOrDefaultAsync(); CandidateServiceModel model = input.To <CandidateServiceModel>(); model.MotherId = motherServiceModel.Id; model.FatherId = fatherServiceModel.Id; await this.candidatesService.Create(userIdentity, model); var candidatesOfMother = this.candidatesService.GetCandidatesOfParent(userIdentity, model.MotherId).ToList(); var candidatesOfFather = this.candidatesService.GetCandidatesOfParent(userIdentity, model.FatherId).ToList(); if (candidatesOfFather.Count >= GlobalConstants.ChildrenInFamily) { foreach (var candidate in candidatesOfFather) { await this.calculatorService.EditBasicScoresByCriteria(candidate.Id); } } if (candidatesOfMother.Count >= GlobalConstants.ChildrenInFamily) { foreach (var candidate in candidatesOfMother) { await this.calculatorService.EditBasicScoresByCriteria(candidate.Id); } } return(this.Redirect("/")); }