public async Task <HandlerResponse <SetPageAnswersResponse> > Handle(SubmitPageOfFilesRequest request, CancellationToken cancellationToken)
        {
            var section = await _dataContext.ApplicationSections.SingleOrDefaultAsync(sec => sec.Id == request.SectionId && sec.ApplicationId == request.ApplicationId);

            var validationErrorResponse = ValidateRequest(request, section);

            if (validationErrorResponse != null)
            {
                return(validationErrorResponse);
            }

            await SaveAnswersIntoPage(section, request, cancellationToken);

            var application = await _dataContext.Applications.SingleOrDefaultAsync(app => app.Id == request.ApplicationId);

            UpdateApplicationData(request, application, section);

            var nextAction           = GetNextActionForPage(section, application, request.PageId);
            var checkboxListAllNexts = GetCheckboxListMatchingNextActionsForPage(section, application, request.PageId);

            SetStatusOfNextPagesBasedOnDeemedNextActions(section, request.PageId, nextAction, checkboxListAllNexts);

            await _dataContext.SaveChangesAsync(cancellationToken);

            return(new HandlerResponse <SetPageAnswersResponse>(new SetPageAnswersResponse(nextAction.Action, nextAction.ReturnId)));
        }
        private HandlerResponse <SetPageAnswersResponse> ValidateRequest(SubmitPageOfFilesRequest request, ApplicationSection section)
        {
            var page = section?.QnAData?.Pages.SingleOrDefault(p => p.PageId == request.PageId);

            if (page is null)
            {
                return(new HandlerResponse <SetPageAnswersResponse>(success: false, message: "Cannot find requested page."));
            }
            else if (request.Files is null)
            {
                return(new HandlerResponse <SetPageAnswersResponse>(success: false, message: "No files specified."));
            }
            else if (request.Files.Any(f => f.Name is null))
            {
                return(new HandlerResponse <SetPageAnswersResponse>(success: false, message: "All files must specify which question they are related to."));
            }