public void SetUniversityLevel(string id, string scoreId) { var indicator = _indicatorService.Get(g => g.CountOfType == "p" + (int)IndicatorProfessorName.رتبه_دانشگاه_محل_تحصیل); var scores = indicator.Scores.ToList(); var universityId = Convert.ToInt32(id); var university = _mappingService.Get(g => g.TypeId == universityId && g.MappingType.Id == 4); var uniLevel = _universityLevelMappingService.Get(g => g.UniversityId == universityId); var _scoreId = Convert.ToInt32(scoreId); var score = scores.FirstOrDefault(w => w.Id == _scoreId); if (uniLevel == null && score != null) { _universityLevelMappingService.Add(new UniversityLevelMapping { CreationDate = DateTime.Now, LastModifiedDate = DateTime.Now, IsActive = true, Score = new Model.Models.Score { Id = score.Id, }, UniversityId = universityId, UniversityName = university.TypeName }); } else if (uniLevel != null && score == null) { _universityLevelMappingService.Delete(uniLevel); } else { uniLevel.Score = new Model.Models.Score { Id = score.Id, }; _universityLevelMappingService.Update(uniLevel); } //-- Set Professor Scores Begin var currentTerm = _termService.Get(g => g.IsCurrentTerm); var professors = _professorService.GetMany(g => g.UniversityStudyPlace != null && g.UniversityStudyPlace != 0 && g.UniversityStudyPlace == universityId && g.Term.Id == currentTerm.Id && g.IsActive == true).ToList(); foreach (var professor in professors) { var professorScores = _professorScoreService.GetMany(g => g.Professor.Id == professor.Id && g.Term.Id == currentTerm.Id).ToList(); var professorScoresIndicator = professorScores.Where(w => scores.Select(s => s.Id).Contains(w.Score.Id)); //var professorScore = _professorScoreService.GetMany(g => scores.Select(s => s.Id).Contains(g.Score.Id) && g.Professor.Id == professor.Id).ToList(); if (professorScoresIndicator.Count() > 0) { foreach (var ps in professorScoresIndicator) { ps.Score.Id = score.Id; _professorScoreService.Update(ps); } } else { foreach (var group in _educationalClassService.GetMany(g => g.Professor.Id == professor.Id).Select(s => s.EducationalGroup)) { _professorScoreService.Add(new ProfessorScore { EducationalGroup = group, Professor = professor, Score = score, Term = currentTerm, CurrentScore = Convert.ToInt32(score.Point * indicator.Ratio.Point) }); } } } //-- Set Professor Scores End }