public ActionResult AddOrUpdateRate(string professorCode, string rateIndex, string countOfType, string groupId = null, string collegeId = null
                                            , string termId = null)
        {
            //var scoreBase = _indicatorService.Get(g => g.CountOfType == countOfType).Scores.OrderBy(o => o.Point)
            //    .ToList().ElementAt(Convert.ToInt32(rateIndex) - 1);
            var scoreBase = _indicatorService.Get(g => g.CountOfType == countOfType).Scores.FirstOrDefault(f => f.Point == Convert.ToInt32(rateIndex));
            var score     = new Model.Models.Score();

            Mapper.Map(scoreBase, score);
            var pCode         = Convert.ToInt32(professorCode);
            var tid           = Convert.ToInt32(termId);
            var term          = _termService.Get(g => g.Id == tid);
            var professorBase = _professorService.Get(g => g.ProfessorCode == pCode && g.Term.Id == tid);
            //var currentterm = GetCurrentTerm();
            var currentScore = Convert.ToInt32(scoreBase.Point * scoreBase.Indicator.Ratio.Point);

            var professor = new Model.Models.Professor();

            Mapper.Map(professorBase, professor);

            if (string.IsNullOrEmpty(groupId))
            {
                var groups = professor.EducationalClasses.Select(s => s.EducationalGroup).Distinct().ToList();
                if (string.IsNullOrEmpty(collegeId))
                {
                    foreach (var group in groups)
                    {
                        var existing = _professorScoreService.Get(g => g.Professor.Id == professor.Id &&
                                                                  g.Term.Id == term.Id &&
                                                                  g.Score.Indicator.CountOfType == countOfType &&
                                                                  g.EducationalGroup.Id == group.Id);
                        var newPs = new Model.Models.ProfessorScore
                        {
                            Professor        = professor,
                            Score            = score,
                            Term             = term,
                            CurrentScore     = currentScore,
                            EducationalGroup = group
                        };
                        if (existing == null)
                        {
                            _professorScoreService.Add(newPs);
                        }
                        else
                        {
                            newPs.Id = existing.Id;
                            _professorScoreService.Update(newPs);
                        }
                    }
                }
                else
                {
                    foreach (var group in groups)
                    {
                        if (group.College.Id == Convert.ToInt32(collegeId))
                        {
                            var existing = _professorScoreService.Get(g => g.Professor.Id == professor.Id &&
                                                                      g.Term.Id == term.Id &&
                                                                      g.Score.Indicator.CountOfType == countOfType &&
                                                                      g.EducationalGroup.Id == group.Id);
                            var newPs = new Model.Models.ProfessorScore
                            {
                                Professor        = professor,
                                Score            = score,
                                Term             = term,
                                CurrentScore     = currentScore,
                                EducationalGroup = group
                            };
                            if (existing == null)
                            {
                                _professorScoreService.Add(newPs);
                            }
                            else
                            {
                                newPs.Id = existing.Id;
                                _professorScoreService.Update(newPs);
                            }
                        }
                    }
                }
            }
            else
            {
                var gCode    = Convert.ToInt32(groupId);
                var group    = _educationalGroupService.Get(g => g.EducationalGroupCode == gCode && g.Term.Id == term.Id);
                var existing = _professorScoreService.Get(g => g.Professor.Id == professor.Id &&
                                                          g.Term.Id == term.Id &&
                                                          g.Score.Indicator.CountOfType == countOfType &&
                                                          g.EducationalGroup.Id == group.Id);
                var newPs = new Model.Models.ProfessorScore
                {
                    Professor        = professor,
                    Score            = score,
                    Term             = term,
                    CurrentScore     = currentScore,
                    EducationalGroup = group
                };
                if (existing == null)
                {
                    _professorScoreService.Add(newPs);
                }
                else
                {
                    newPs.Id = existing.Id;
                    _professorScoreService.Update(newPs);
                }
            }
            return(new JsonResult {
                Data = currentScore
            });
        }
Beispiel #2
0
        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
        }
Beispiel #3
0
        public void UpdateClassSessions(int classCode, int onlineHeld, int presentHeld, int other, string termId = null, bool manualUpdate = false)
        {
            Term currentTerm = null;

            if (string.IsNullOrEmpty(termId))
            {
                currentTerm = GetCurrentTerm();
            }
            else
            {
                var tid = Convert.ToInt32(termId);
                currentTerm = _termService.Get(g => g.Id == tid);
            }
            var obj = _educationalClassService.Get(g => g.CodeClass == classCode && g.Term.Id == currentTerm.Id);

            if ((manualUpdate && onlineHeld >= 0) || (!manualUpdate && onlineHeld > 0))
            {
                obj.OnlineHeldingCount = onlineHeld;
            }
            if ((manualUpdate && presentHeld >= 0) || (!manualUpdate && presentHeld > 0))
            {
                obj.PersentHeldingCount = presentHeld;
            }
            if ((manualUpdate && other >= 0) || (!manualUpdate && other > 0))
            {
                obj.OthersHeldingCount = other;
            }
            _educationalClassService.Update(obj);


            //var classes = _educationalClassService.GetMany(g => g.Professor.Id == obj.Professor.Id && g.Term.Id == currentTerm.Id && g.EducationalGroup.Id == obj.EducationalGroup.Id);
            //obj.Professor.OnlineSession = classes.Sum(s => s.OnlineHeldingCount);
            //obj.Professor.InPersonSession = classes.Sum(s => s.PersentHeldingCount);
            //obj.Professor.OthersSession = classes.Sum(s => s.OthersHeldingCount);
            //_professorService.Update(obj.Professor);

            var indicatorCountOfTypet = "p" + (int)IndicatorProfessorName.تعداد_جلسات_برگزار_شده_کلاس;
            var profAllScores         = _professorScoreService.GetMany(g =>
                                                                       g.Professor.Id == obj.Professor.Id &&
                                                                       g.Term.Id == currentTerm.Id &&
                                                                       g.Score.Indicator.CountOfType == indicatorCountOfTypet);

            Model.Models.ProfessorScore profScore = new Model.Models.ProfessorScore();
            if (profAllScores.Count() > 0)
            {
                profScore = profAllScores.Where(w => w.EducationalGroup.Id == obj.EducationalGroup.Id).FirstOrDefault();
            }

            //var totalCount = (obj.Professor.OnlineSession + obj.Professor.InPersonSession + obj.Professor.OthersSession) / classes.Count();
            //var score = _scoreService.Get(g => g.MinValue <= totalCount && g.MaxValue >= totalCount && g.Indicator.CountOfType == indicatorCountOfTypet);


            var listOfCountClass = new List <decimal>();


            var listOfClass = _educationalClassService.GetMany(x => x.Professor.Id == obj.Professor.Id &&
                                                               x.EducationalGroup.Id == obj.EducationalGroup.Id &&
                                                               x.Term.Id == currentTerm.Id &&
                                                               x.IsActive == true).ToList();

            var indicator7 = _indicatorService
                             .Get(y => y.CountOfType == ("p" + (int)IndicatorProfessorName.تعداد_جلسات_برگزار_شده_کلاس));
            var scores7 = indicator7.Scores;

            foreach (var c in listOfClass)
            {
                if (obj.HoldingExamDate == null)
                {
                    listOfCountClass.Add(((scores7.FirstOrDefault(p => p.Point == 80).MinValue.Value) + 1));
                }
                else
                {
                    listOfCountClass.Add(((obj.OnlineHeldingCount ?? 0) + (obj.PersentHeldingCount ?? 0) + (obj.OthersHeldingCount ?? 0)));
                }
            }
            var avg = Math.Round(listOfCountClass.Average(), 0);
            var s   = scores7
                      .FirstOrDefault(p => p.MinValue <= avg &&
                                      p.MaxValue >= avg
                                      );

            if (s != null)
            {
                if (profScore != null && profScore.Id > 0)
                {
                    profScore.Score = s;
                    var point = s.Point * indicator7.Ratio.Point;
                    if (point != null)
                    {
                        profScore.CurrentScore = (int)point;
                    }
                    _professorScoreService.Update(profScore);
                }
                else
                {
                    var point = s.Point * indicator7.Ratio.Point;
                    if (point != null)
                    {
                        var sPoint = (int)point;
                        _professorScoreService.Add(new Model.Models.ProfessorScore
                        {
                            EducationalGroup = obj.EducationalGroup,
                            Professor        = obj.Professor,
                            Term             = currentTerm,
                            Score            = s,
                            CurrentScore     = (int)point
                        });
                    }
                }
            }

            //var scores = _professorScoreService.GetMany(g =>
            //g.Professor.Id == obj.Professor.Id
            //&& g.Term.Id == currentTerm.Id
            //&& g.Score.Indicator.CountOfType == indicatorCountOfTypet).ToList();
            //foreach (var item in scores)
            //{
            //    item.CurrentScore = currentScore;
            //    _professorScoreService.Update(item);
            //}
        }