[ActionName("View")] // Be carefull, the term "View" has a special meaning in ASP.NET MVC. There is the method View() in the base Controller class.
        public async Task <ActionResult> ViewExercise(int id)
        {
            var exercises = await ExerciseUtils.GetExerciseWithReviews("dbo.exeGetExerciseWithReviews", new { UserId = this.GetUserId(), Id = id, });

            // We got a few rows of the same Exercise, joined with different Reviews. Group them into a single Exercise.
            var reviews = exercises
                          .SelectMany(i => i.Reviews)
                          .Where(i => i is ReviewDto) // Otherwise an absent review is deserialized by Dapper as null. i.e [null].
                          .OrderBy(i => i.RequestTime)
                          .ToList();                  // ToList() is needed, otherwise a mistical StackOverflow occurs within IIS.
            // Use the first Exercise as a single instance. Make it the common parent of all Reviews.
            var exercise = exercises.First();

            exercise.Reviews = reviews;

            ViewBag.ExerciseParam = exercise;
            ViewBag.cardIdParam   = exercise.CardId.GetValueOrDefault();
            if (exercise.CardId.HasValue)
            {
                ViewBag.cardParam = await ExerciseUtils.GetCardWithItems(exercise.CardId.Value);
            }

            switch (exercise.ArtifactType)
            {
            case ArtifactType.Jpeg:
                return(View("ViewPhoto"));

            case ArtifactType.Mp3:
                return(View("ViewRecording"));

            default:
                return(HttpNotFound(exercise.ArtifactType));
            }
        }
Exemple #2
0
        public async Task <ActionResult> Edit(int id)
        {
            var exercise = (await ExerciseUtils.GetExerciseWithReviews("exeGetReview", new { UserId = this.GetUserId(), Id = id, })).Single();

            ViewBag.ExerciseParam = exercise;
            ViewBag.cardIdParam   = exercise.CardId.GetValueOrDefault();
            if (exercise.CardId.HasValue)
            {
                ViewBag.cardParam = await ExerciseUtils.GetCardWithItems(exercise.CardId.Value);
            }

            switch (exercise.ArtifactType)
            {
            case ArtifactType.Jpeg:
                return(View("EditWriting"));

            case ArtifactType.Mp3:
                return(View("EditRecording"));

            default:
                return(HttpNotFound(exercise.ArtifactType));
            }
        }