Beispiel #1
0
        public async Task <IActionResult> SaveMultiplePageAnswers(Guid Id, int sequenceNo, int sectionNo, string pageId, string __redirectAction, string __formAction)
        {
            try
            {
                string __summaryLink = HttpContext.Request.Form["__summaryLink"];

                var page = await _qnaApiClient.GetPageBySectionNo(Id, sequenceNo, sectionNo, pageId);

                if (page.AllowMultipleAnswers)
                {
                    var answers         = GetAnswersFromForm(page);
                    var pageAddResponse = await _qnaApiClient.AddAnswersToMultipleAnswerPage(Id, page.SectionId.Value, page.PageId, answers);

                    if (pageAddResponse?.Success != null && pageAddResponse.Success)
                    {
                        if (__formAction == "Add")
                        {
                            return(RedirectToAction("Page", new
                            {
                                Id,
                                sequenceNo,
                                sectionNo,
                                pageId = pageAddResponse.Page.PageId,
                                __redirectAction,
                                __summaryLink
                            }));
                        }

                        if (__redirectAction == "Feedback")
                        {
                            return(RedirectToAction("Feedback", new { Id }));
                        }

                        var nextAction = pageAddResponse.Page.Next.SingleOrDefault(x => x.Action == "NextPage");

                        if (!string.IsNullOrEmpty(nextAction.Action))
                        {
                            return(RedirectToNextAction(Id, sequenceNo, sectionNo, __redirectAction, nextAction.Action, nextAction.ReturnId));
                        }
                    }
                    else if (page.PageOfAnswers?.Count > 0 && __formAction != "Add")
                    {
                        if (page.HasFeedback && page.HasNewFeedback && !page.AllFeedbackIsCompleted && __redirectAction == "Feedback")
                        {
                            page = StoreEnteredAnswers(answers, page);
                            SetResponseValidationErrors(pageAddResponse?.ValidationErrors, page);
                            if (!page.AllFeedbackIsCompleted || pageAddResponse?.ValidationErrors.Count > 0)
                            {
                                return(RedirectToAction("Page", new { Id, sequenceNo, sectionNo, pageId, __redirectAction, __summaryLink }));
                            }
                            return(RedirectToAction("Feedback", new { Id }));
                        }
                        else if (pageAddResponse.ValidationErrors?.Count == 0 || answers.All(x => x.Value == string.Empty || Regex.IsMatch(x.Value, "^[,]+$")))
                        {
                            var nextAction = page.Next.SingleOrDefault(x => x.Action == "NextPage");

                            if (!string.IsNullOrEmpty(nextAction.Action))
                            {
                                if (__redirectAction == "Feedback")
                                {
                                    foreach (var answer in answers)
                                    {
                                        if (page.Next.Exists(y => y.Conditions.Exists(x => x.QuestionId == answer.QuestionId || x.QuestionTag == answer.QuestionId)))
                                        {
                                            return(RedirectToNextAction(Id, sequenceNo, sectionNo, __redirectAction, nextAction.Action, nextAction.ReturnId, "Hide"));
                                        }
                                        break;
                                    }

                                    return(RedirectToAction("Feedback", new { Id }));
                                }

                                return(RedirectToNextAction(Id, sequenceNo, sectionNo, __redirectAction, nextAction.Action, nextAction.ReturnId));
                            }
                        }
                    }

                    page = StoreEnteredAnswers(answers, page);

                    SetResponseValidationErrors(pageAddResponse?.ValidationErrors, page);
                }
                else
                {
                    return(BadRequest("Page is not of a type of Multiple Answers"));
                }

                return(RedirectToAction("Page", new { Id, sequenceNo, sectionNo, pageId, __redirectAction, __summaryLink }));
            }
            catch (Exception ex)
            {
                if (ex.Message.Equals("Could not find the page", StringComparison.OrdinalIgnoreCase))
                {
                    return(RedirectToAction("Applications"));
                }
                throw ex;
            }
        }