public ActionResult AddScoreInSession(string id, string name, string minValue, string maxValue, string point)
        {
            var score = new Model.Models.Score();

            if (id != null)
            {
                score.Id = Convert.ToInt32(id);
            }
            if (name != null)
            {
                score.Name = name;
            }
            if (minValue != null)
            {
                score.MinValue = Convert.ToInt32(minValue);
            }
            if (maxValue != null)
            {
                score.MaxValue = Convert.ToInt32(maxValue);
            }
            //if (upperBound != null)
            //    score.UpperBound = Convert.ToInt32(upperBound);
            //if (lowerBound != null)
            //    score.LowerBound = Convert.ToInt32(lowerBound);
            if (point != null && point != "0")
            {
                score.Point = Convert.ToInt32(point);
            }

            (Session["ScoreList"] as List <Model.Models.Score>)?.Add(score);
            return(Json(new { }));
        }
        public ActionResult AddScoreGroupIndicator(int indexer = 1, bool hasLimit = true)
        {
            var score = new Model.Models.Score();

            //if (indexer == 1)
            //{

            //    ViewBag.indexr = indexer;
            //    return PartialView(score);
            //}
            //else
            //{
            ViewBag.indexr   = indexer;
            ViewBag.hasLimit = hasLimit;
            return(PartialView("AddScoreRow", score));
            //}
        }
        public ActionResult AddOrUpdateInTimePresent(string groupData, string rateIndex, string countOfType, 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 groupCode = Convert.ToInt32(groupData);
            var tid       = Convert.ToInt32(termId);
            var groupBase = _educationalGroupService.Get(g => g.EducationalGroupCode == groupCode && g.Term.Id == tid);
            //var currentterm = GetCurrentTerm();
            var term         = _termService.Get(g => g.Id == tid);
            var currentScore = Convert.ToInt32(scoreBase.Point * scoreBase.Indicator.Ratio.Point);
            var group        = new Model.Models.EducationalGroup();

            Mapper.Map(groupBase, group);
            var existing = _educationalGroupScoreService.Get(g => g.EducationalGroup.Id == group.Id &&
                                                             g.Term.Id == term.Id &&
                                                             g.Score.Indicator.CountOfType == countOfType);

            var newGS = new Model.Models.EducationalGroupScore
            {
                EducationalGroup = group,
                Score            = score,
                Term             = term,
                CurrentScore     = currentScore
            };

            if (existing == null)
            {
                _educationalGroupScoreService.Add(newGS);
            }
            else
            {
                newGS.Id = existing.Id;
                _educationalGroupScoreService.Update(newGS);
            }
            group.InTimePresentCurriculum = score.Point.ToString();
            _educationalGroupService.Update(group);
            return(new JsonResult {
                Data = currentScore
            });
        }
        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
            });
        }