Exemple #1
0
        public ActionResult StartWhatIfGrade(Guid courseId)
        {
            var courseDomainModel = new CourseDomainModel();
            var iModel            = Courses.GetCourse(courseId);

            if (iModel.GetType() == typeof(ErrorDomainModel))
            {
                return(GradeTrackerError(iModel, null));
            }
            else
            {
                courseDomainModel = (CourseDomainModel)iModel;
            }

            var courseWhatIfViewModel = new CourseWhatIfViewModel {
                Id = courseDomainModel.Id, Name = courseDomainModel.Name
            };

            var evaluationDomainModels = Evaluations.GetEvaluationsForCourse(courseId);

            if (evaluationDomainModels.Count > 0 && evaluationDomainModels.First().GetType() == typeof(ErrorDomainModel))
            {
                return(GradeTrackerError(evaluationDomainModels.First(), null));
            }

            courseWhatIfViewModel.EvaluationList = ConvertToListOfViewModels(evaluationDomainModels);

            var scoresList = new List <ScoreViewModel>();

            foreach (var eval in courseWhatIfViewModel.EvaluationList)
            {
                courseWhatIfViewModel.WhatIfs.Add(new EvaluationWhatIfViewModel {
                    EvaluationId = eval.Id.ToString()
                });

                var scoresDomainModel = Scores.GetScoresForEvaluation(eval.Id);

                var scoresPulled = EvaluationController.GetListViewModelFromDomainModels(scoresDomainModel);

                courseWhatIfViewModel.ScoreList.AddRange(scoresPulled);

                var countOfScoresPulled = scoresPulled.Count;
                var countOfScoresNeeded = eval.NumberOfScores;

                if (countOfScoresPulled != countOfScoresNeeded)
                {
                    var scoresToFill = countOfScoresNeeded - countOfScoresPulled;

                    while (scoresToFill > 0)
                    {
                        courseWhatIfViewModel.ScoreList.Add(new ScoreViewModel {
                            EvaluationId = eval.Id, PointsPossible = eval.PointValuePerScore
                        });
                        scoresToFill--;
                    }
                }
            }

            return(View("WhatIfEntryView", courseWhatIfViewModel));
        }
Exemple #2
0
        public ActionResult GetWhatIfGrade(CourseWhatIfInputViewModel whatIfModel)
        {
            var course          = (CourseDomainModel)Courses.GetCourse(Guid.Parse(whatIfModel.CourseId));
            var evalsFromCourse = Evaluations.GetEvaluationsForCourse(Guid.Parse(whatIfModel.CourseId));
            var castedModels    = new List <EvaluationDomainModel>();

            foreach (var eval in evalsFromCourse)
            {
                if (eval.GetType() == typeof(EvaluationDomainModel))
                {
                    castedModels.Add((EvaluationDomainModel)eval);
                }
            }

            var whatIfDomainModels = new List <EvaluationDomainModel>();

            foreach (var eval in whatIfModel.Evaluations)
            {
                whatIfDomainModels.Add(new EvaluationDomainModel
                {
                    Id                  = Guid.Parse(eval.EvaluationId),
                    PointsEarned        = eval.PointsEarned,
                    TotalPointsPossible = eval.PointsPossible
                });
            }

            var domainModelsWithWhatIfScores = from storedEval in castedModels
                                               join whatIfEval in whatIfDomainModels
                                               on storedEval.Id equals whatIfEval.Id
                                               select new EvaluationDomainModel
            {
                Id                  = storedEval.Id,
                Name                = storedEval.Name,
                PointsEarned        = whatIfEval.PointsEarned,
                TotalPointsPossible = whatIfEval.TotalPointsPossible,
                Weight              = storedEval.Weight
            };

            // send the results of the query TO the Courses.CalcWhatIfGrade()
            var whatIfGradeDomainModel = Courses.CalcWhatIfGrade(domainModelsWithWhatIfScores);

            var whatIfGradeViewModel = new CourseWhatIfResultViewModel
            {
                CourseId    = course.Id,
                CourseName  = course.Name,
                WhatIfGrade = whatIfGradeDomainModel.WhatIfGrade,
                Evaluations = whatIfGradeDomainModel.WhatIfEvaluations.Select(eval => new EvaluationWhatIfResultViewModel
                {
                    EvaluationId   = eval.EvaluationId,
                    EvaluationName = eval.EvaluationName,
                    WhatIfGrade    = eval.WhatIfGrade
                }).ToList()
            };

            // return it to the new view (I guess, and also need to do that)

            return(PartialView("_whatIfResultPartial", whatIfGradeViewModel));
        }
Exemple #3
0
        public ActionResult ViewCourse(Guid courseId)
        {
            var courseDomainModel = new CourseDomainModel();
            var iModel            = Courses.GetCourse(courseId);

            if (iModel.GetType() == typeof(ErrorDomainModel))
            {
                return(GradeTrackerError(iModel, null));
            }
            else
            {
                courseDomainModel = (CourseDomainModel)iModel;
            }

            var courseViewModel = new CourseViewModel(courseDomainModel);

            var evaluationDomainModels = Evaluations.GetEvaluationsForCourse(courseId);

            if (evaluationDomainModels.Count > 0 && evaluationDomainModels.First().GetType() == typeof(ErrorDomainModel))
            {
                return(GradeTrackerError(evaluationDomainModels.First(), null));
            }

            var semesterModel = Semesters.GetSemester(courseDomainModel.SemesterId);

            if (semesterModel.GetType() == typeof(ErrorDomainModel))
            {
                return(GradeTrackerError(semesterModel, null));
            }

            courseViewModel.Semester    = GetSemesterViewModel(semesterModel);
            courseViewModel.Evaluations = ConvertToListViewModel(evaluationDomainModels);
            courseViewModel.SetLastModified();

            return(View(courseViewModel));
        }