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
            });
        }
Example #2
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);
            //}
        }