コード例 #1
0
        public async Task <IActionResult> OnPostAddStudentAsync(string studentId)
        {
            CourseClass = await CourseClasses.FindAsync(Id);

            if (CourseClass == null)
            {
                return(NotFound());
            }

            var student = await Students.FindAsync(studentId);

            if (student == null)
            {
                return(NotFound());
            }

            if (await IsStudentInClass(student))
            {
                return(BadRequest());
            }

            student.StudentCourseClasses.Add(
                new StudentCourseClass()
            {
                Class   = CourseClass,
                Student = student
            });

            Students.Update(student);
            await Context.SaveChangesAsync();

            return(RedirectToPage(new { id = Id }));
        }
コード例 #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var question = await SurveyQuestions.FindAsync(Id);

            question.Required = Question.Required;
            switch (question.Type)
            {
            case SurveyQuestion.SurveyQuestionTypes.Qualitative:
                ((SurveyQuestionQualitative)question).Prompt = ((SurveyQuestionQualitative)Question).Prompt;
                break;

            case SurveyQuestion.SurveyQuestionTypes.Rate:
                ((SurveyQuestionRate)question).Category     = ((SurveyQuestionRate)Question).Category;
                ((SurveyQuestionRate)question).Example      = ((SurveyQuestionRate)Question).Example;
                ((SurveyQuestionRate)question).Explaination = ((SurveyQuestionRate)Question).Explaination;
                ((SurveyQuestionRate)question).Range        = ((SurveyQuestionRate)Question).Range;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var id = question.CourseClassId;

            SurveyQuestions.Update(question);
            await Context.SaveChangesAsync();

            return(RedirectToPage("/Questions/Index", new { id }));
        }
コード例 #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            ModelState.Clear();

            if (string.IsNullOrEmpty(Assignment.Name))
            {
                ModelState.AddModelError("Assignment.Name", "Assignment's name is required.");
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var assignment = await Assignments.FindAsync(Id);

            if (assignment == null)
            {
                return(NotFound());
            }

            assignment.Name = Assignment.Name;

            Assignments.Update(assignment);
            await Context.SaveChangesAsync();

            return(RedirectToPage("/Assignments/Index",
                                  new { id = assignment.CourseClassId }));
        }
コード例 #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            Assignment = await PreAssignments.FindAsync(Id);

            if (Assignment == null)
            {
                return(NotFound());
            }

            Context.Entry(Assignment).Reference(x => x.PreAssignmentReport).Load();

            if (Assignment.PreAssignmentReport.Type == PreAssignmentReport.PreAssignmentReportTypes.Success)
            {
                Context.Entry(Assignment).Reference(x => x.Solution).Query()
                .Include(x => x.MethodDeclarations).Load();
                Context.Entry(Assignment).Reference(x => x.CourseClass).Query().Load();
                Context.Entry(Assignment).Reference(x => x.TestProject).Query()
                .Include(x => x.UnitTests).Load();

                var assignment = new Assignment()
                {
                    CourseClass = Assignment.CourseClass,
                    Filename    = Assignment.Filename,
                    Name        = Assignment.Name,
                    Solution    = Assignment.Solution,
                    TestProject = Assignment.TestProject,
                };
                Assignments.Add(assignment);
                PreAssignments.Remove(Assignment);
                await Context.SaveChangesAsync();

                return(RedirectToPage("/Assignments/Details", new { assignment.Id }));
            }
            else
            {
                Assignment.PreAssignmentReport = new PreAssignmentPendingReport();
                PreAssignments.Update(Assignment);
                await Context.SaveChangesAsync();

                BackgroundJob.Enqueue(() => EngineService.RunPreAssignment(Id));
            }

            return(RedirectToPage(new { Id }));
        }
コード例 #5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Students.Add(Student);
            await Context.SaveChangesAsync();

            return(RedirectToPage("/Students/Index"));
        }
コード例 #6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            CourseClasses.Add(CourseClass);
            await Context.SaveChangesAsync();

            return(RedirectToPage("/CourseClasses/Index"));
        }
コード例 #7
0
        public async Task <IActionResult> OnPostAsync()
        {
            CourseClass = await CourseClasses.FindAsync(Id);

            if (CourseClass == null)
            {
                return(NotFound());
            }

            CourseClasses.Remove(CourseClass);
            await Context.SaveChangesAsync();

            return(RedirectToPage("/CourseClasses/Index"));
        }
コード例 #8
0
        public async Task <IActionResult> OnPostAsync()
        {
            Student = await Students.FindAsync(Id);

            if (Student == null)
            {
                return(NotFound());
            }

            Students.Remove(Student);
            await Context.SaveChangesAsync();

            return(RedirectToPage("/Students/Index"));
        }
コード例 #9
0
        public async Task <IActionResult> OnPostAsync()
        {
            Question = await SurveyQuestions.FindAsync(Id);

            if (Question == null)
            {
                return(NotFound());
            }

            var id = Question.CourseClassId;

            // TODO: Remove Survey Answers Related
            SurveyQuestions.Remove(Question);
            await Context.SaveChangesAsync();

            return(RedirectToPage("/Questions/Index", new { id }));
        }
コード例 #10
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var student = await Students.FindAsync(Student.Id);

            if (student == null)
            {
                return(NotFound());
            }

            student.Name  = Student.Name;
            student.Email = Student.Email;
            Students.Update(student);
            await Context.SaveChangesAsync();

            return(RedirectToPage("/Students/Index"));
        }
コード例 #11
0
        public async Task <IActionResult> OnPostCreateAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var course = await CourseClasses.FindAsync(Id);

            if (course == null)
            {
                return(NotFound());
            }

            Context.Entry(course).Collection(x => x.PreAssignments).Load();

            PreAssignment.PreAssignmentReport = new PreAssignmentPendingReport();

            var testProject = FileHelper.ProcessFormFile(TestProjectFiles, ModelState);
            var solution    = FileHelper.ProcessFormFile(SolutionFiles, ModelState);

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            PreAssignment.TestProject.Files = testProject;
            PreAssignment.Solution.Files    = solution;

            course.PreAssignments.Add(PreAssignment);
            CourseClasses.Update(course);
            await Context.SaveChangesAsync();

            var id = PreAssignment.Id;

            EngineService.RunPreAssignment(id);

            return(RedirectToPage("/PendingAssignments/Index", new { Id }));
        }
コード例 #12
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var course = await CourseClasses.FindAsync(Id);

            if (course == null)
            {
                return(NotFound());
            }

            course.Name   = CourseClass.Name;
            course.Term   = CourseClass.Term;
            course.Course = CourseClass.Course;

            CourseClasses.Update(course);
            await Context.SaveChangesAsync();

            return(RedirectToPage("/CourseClasses/Index"));
        }
コード例 #13
0
        public async Task <IActionResult> OnPostAsync()
        {
            CourseClass = await CourseClasses.FindAsync(Id);

            if (CourseClass == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Context.Entry(CourseClass)
            .Collection(x => x.SurveyQuestions)
            .Load();

            CourseClass.SurveyQuestions.Add(Question);
            CourseClasses.Update(CourseClass);
            await Context.SaveChangesAsync();

            return(RedirectToPage("/Questions/Index", new { Id }));
        }
コード例 #14
0
        public async Task Delete(MarkovModel markovModel)
        {
            Context.Entry(markovModel).Collection(x => x.States).Query()
            .Include(x => x.Snapshots)
            .Include(x => x.Transitions).Load();

            foreach (var state in markovModel.States)
            {
                foreach (var transition in state.Transitions)
                {
                    Context.Remove(transition);
                }

                foreach (var snapshot in state.Snapshots)
                {
                    Context.Remove(snapshot);
                }

                Context.Remove(state);
            }

            Context.Remove(markovModel);
            await Context.SaveChangesAsync();
        }
コード例 #15
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            for (var i = 0; i < SurveyResponses.Count; i++)
            {
                SurveyResponses[i].Question = await SurveyQuestionsSet.FindAsync(SurveyResponses[i].Question.Id);

                if (SurveyResponses[i].Question == null)
                {
                    return(NotFound());
                }
                switch (SurveyResponses[i].Question.Type)
                {
                case SurveyQuestion.SurveyQuestionTypes.Qualitative:
                    ValidateQuestion((SurveyAnswerQualitative)SurveyResponses[i].Answer,
                                     (SurveyQuestionQualitative)SurveyResponses[i].Question, i);
                    break;

                case SurveyQuestion.SurveyQuestionTypes.Rate:
                    ValidateQuestion((SurveyAnswerRate)SurveyResponses[i].Answer,
                                     (SurveyQuestionRate)SurveyResponses[i].Question, i);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var survey = await Surveys.FindAsync(Id);

            if (survey == null || survey.IsCompleted)
            {
                return(NotFound());
            }

            Context.Entry(survey).Reference(x => x.Student).Load();

            if (!survey.Student.Email.Equals(User.Identity.Name))
            {
                return(RedirectToPage("/Account/AccessDenied"));
            }

            Context.Entry(survey).Collection(x => x.SurveyResponses).Load();
            foreach (var response in SurveyResponses)
            {
                survey.SurveyResponses.Add(response);
            }
            survey.IsCompleted = true;
            Surveys.Update(survey);
            await Context.SaveChangesAsync();

            return(RedirectToPage("/Surveys/Details", new { Id }));
        }