Exemple #1
0
        public Behaviour GetNextPage(Dictionary <string, dynamic> viewModel)
        {
            var conditionValidator = new ConditionValidator();

            if (Behaviours.Count == 1)
            {
                return(Behaviours.FirstOrDefault());
            }

            foreach (var behaviour in Behaviours.OrderByDescending(_ => _.Conditions.Count))
            {
                var isConditionTrue = false;

                foreach (var condition in behaviour.Conditions)
                {
                    isConditionTrue = conditionValidator.IsValid(condition, viewModel);

                    if (!isConditionTrue)
                    {
                        break;
                    }
                }

                if (isConditionTrue || !behaviour.Conditions.Any())
                {
                    return(behaviour);
                }
            }

            var conditionValuesForDebug = Behaviours.OrderByDescending(_ => _.Conditions.Count)
                                          .Where(_ => _.Conditions != null)
                                          .SelectMany(_ => _.Conditions)
                                          .Where(_ => !string.IsNullOrEmpty(_.QuestionId))
                                          .Select(_ => _.QuestionId)
                                          .Distinct()
                                          .Select(_ => $"QuestionId: {_} with answer {(viewModel.ContainsKey(_) ? viewModel[_] : "'null'")}")
                                          .Aggregate((curr, acc) => $"{acc} {curr}");

            throw new ApplicationException($"Page::GetNextPage, There was a problem whilst processing behaviors for page '{PageSlug}', Behaviour Answers and conditions: {conditionValuesForDebug}");
        }