Пример #1
0
        public async Task <ActionResult> SimpleScoreExercise(int submissionId, int exerciseScore, bool ignoreNewestSubmission = false, int?updateCheckingId = null)
        {
            var submission = solutionsRepo.FindSubmissionById(submissionId);
            var courseId   = submission.CourseId;
            var slideId    = submission.SlideId;
            var userId     = submission.UserId;

            if (!User.HasAccessFor(courseId, CourseRole.Instructor))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }

            if (!ignoreNewestSubmission && !updateCheckingId.HasValue)
            {
                var lastAcceptedSubmission = solutionsRepo.GetAllAcceptedSubmissionsByUser(courseId, slideId, userId).OrderByDescending(s => s.Timestamp).FirstOrDefault();
                if (lastAcceptedSubmission != null && lastAcceptedSubmission.Id != submission.Id)
                {
                    return(Json(
                               new {
                        status = "error",
                        error = "has_newest_submission",
                        submissionId = lastAcceptedSubmission.Id,
                        submissionDate = lastAcceptedSubmission.Timestamp.ToAgoPrettyString(true)
                    }));
                }
            }

            var manualScore = slideCheckingsRepo.GetManualScoreForSlide(courseId, slideId, userId);

            if (exerciseScore < manualScore && !updateCheckingId.HasValue)
            {
                return(Json(
                           new
                {
                    status = "error",
                    error = "has_greatest_score",
                    score = manualScore,
                    checkedQueueUrl = Url.Action("ManualExerciseCheckingQueue", "Admin", new { courseId, done = true, userId, slideId })
                }));
            }

            /* TODO: check if 0 <= exercisScore <= exercise.MaxReviewScore */

            await slideCheckingsRepo.RemoveWaitingManualExerciseCheckings(courseId, slideId, userId);

            ManualExerciseChecking checking;

            if (updateCheckingId.HasValue)
            {
                checking = slideCheckingsRepo.FindManualCheckingById <ManualExerciseChecking>(updateCheckingId.Value);
            }
            else
            {
                checking = await slideCheckingsRepo.AddManualExerciseChecking(courseId, slideId, userId, submission);
            }
            await slideCheckingsRepo.LockManualChecking(checking, User.Identity.GetUserId());

            await slideCheckingsRepo.MarkManualCheckingAsChecked(checking, exerciseScore);

            await visitsRepo.UpdateScoreForVisit(courseId, slideId, userId);

            return(Json(
                       new
            {
                status = "ok",
                score = exerciseScore.PluralizeInRussian(new RussianPluralizationOptions {
                    One = "балл", Two = "балла", Five = "баллов", Gender = Gender.Male, hideNumberOne = false, smallNumbersAreWords = false
                }),
                totalScore = visitsRepo.GetScore(slideId, userId),
                checkingId = checking.Id,
            }));
        }