Exemple #1
0
        public IEnumerable <byte> ToBytes()
        {
            var bytes = new List <byte>();

            bytes.AddRange(Header.ToBytes());

            if (Questions != null && Questions.Any())
            {
                bytes.AddRange(Questions.SelectMany(qu => qu.ToBytes()));
            }
            if (Answers != null && Answers.Any())
            {
                bytes.AddRange(Answers.SelectMany(ans => ans.ToBytes()));
            }
            if (Authorities != null && Authorities.Any())
            {
                bytes.AddRange(Authorities.SelectMany(auth => auth.ToBytes()));
            }
            if (Additionals != null && Additionals.Any())
            {
                bytes.AddRange(Additionals.SelectMany(ads => ads.ToBytes()));
            }

            return(bytes);
        }
 public int?GetPossibleAnswerID(int questionId)
 {
     if (Answers.Any(a => a.QuestionID == questionId))
     {
         return(Answers.Where(a => a.QuestionID == questionId).First().QuestionPossibleAnswerID);
     }
     else
     {
         return(null);
     }
 }
 public string GetAnswerText(int questionId)
 {
     if (Answers.Any(a => a.QuestionID == questionId))
     {
         return(Answers.Where(a => a.QuestionID == questionId).First().Answer);
     }
     else
     {
         return(string.Empty);
     }
 }
Exemple #4
0
        private void SynchronizeAnswersCollections()
        {
            if (Answers.Any())
            {
                Answers.Clear();
            }

            foreach (var answer in Question.Answers)
            {
                Answers.Add(answer);
            }
        }
        // End Navigation Properties

        public string GetQuestionType()
        {
            if (Answers == null)
            {
                throw new System.Exception("Cannot call GetQuestionType() before loading navigation properties");
            }

            if (TrueFalseAnswer != null)
            {
                return("TrueOrFalse");
            }

            return(Answers.Any(a => a.ImageId != null) ? "ImageAnswers" : "TextAnswers");
        }
        public bool SubmitAnswer(Guid answerId)
        {
            AttemptCount++;

            if (AttemptCount >= MaxAttempts)
            {
                Status = QuestionStatus.Locked;
                return(false);
            }

            var result = Answers.Any(x => x.Id == answerId && x.IsCorrect);

            if (result)
            {
                Status = QuestionStatus.Correct;
            }

            return(result);
        }
Exemple #7
0
        private async void CreateTopic()
        {
            Tuple <bool, string> result;

            if (_prevArgs.TopicType != null)
            {
                result = await ForumTopicQueries.CreateNewTopic(Title, Message,
                                                                _prevArgs.TopicType.Value, _prevArgs.Id, Question,
                                                                Answers.Any(model => !string.IsNullOrEmpty(model.Answer))
                                                                ?Answers.Select(model => model.Answer).ToList()
                                                                    : null);
            }
            else
            {
                result = await ForumTopicQueries.CreateNewTopic(Title, Message,
                                                                _prevArgs.ForumType, _prevArgs.Id, Question,
                                                                Answers.Any(model => !string.IsNullOrEmpty(model.Answer))
                                                                ?Answers.Select(model => model.Answer).ToList()
                                                                    : null);
            }
            if (result.Item1)
            {
                ResourceLocator.TelemetryProvider.TelemetryTrackEvent(TelemetryTrackedEvents.CreatedTopic);
                if (result.Item2 != null)
                {
                    ViewModelLocator.GeneralMain.Navigate(PageIndex.PageForumIndex, new ForumsTopicNavigationArgs(result.Item2, null));
                }
                else
                {
                    ViewModelLocator.NavMgr.CurrentMainViewOnBackRequested();
                }

                Message = Title = string.Empty;
            }
            else
            {
                ResourceLocator.MessageDialogProvider.ShowMessageDialog("Something went wrong while creating your topic. Remember that you can post new topics every 5 minutes.", "Something went wrong!");
            }
        }
        public void Skip(int milliseconds)
        {
            _millisecondsCounter += milliseconds;

            if (CurrentParagraph.ShowMilliseconds < _millisecondsCounter)
            {
                _millisecondsCounter = 0;
                if (CurrentParagraphIsLast)
                {
                    if (!Answers.Any())
                    {
                        OnEnd?.Invoke();
                    }
                }
                else
                {
                    _paragraphIndex++;
                    CurrentParagraph.Impact?.On(_character);
                    OnChanded?.Invoke();
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Verifies that the provided answer string is correct and if so, if it qualifies for the bonus answer
        /// if there is one.
        /// </summary>
        /// <param name="answer">Answer string from user</param>
        /// <returns></returns>
        public AnswerResponse VerifyAnswer(string answer)
        {
            var response = new AnswerResponse
            {
                AnswerStatus = AnswerStatus.Incorrect,
                Points       = Points,
                BonusPoints  = BonusPoints
            };

            bool AnswerContains(string item) => answer.Contains(item, StringComparison.InvariantCultureIgnoreCase);

            try
            {
                if (BonusPoints.HasValue && BonusPoints.Value != 0)
                {
                    response.BonusPoints = BonusPoints;
                    if (BonusAll ?? false)
                    {
                        if (BonusAnswers.All(AnswerContains))
                        {
                            response.AnswerStatus = AnswerStatus.BonusCorrect;
                        }
                        else if (BonusAnswers.Any(AnswerContains))
                        {
                            response.AnswerStatus = AnswerStatus.PartiallyCorrect;
                        }
                    }
                    else if (BonusAnswers.Any(AnswerContains))
                    {
                        response.AnswerStatus = AnswerStatus.BonusCorrect;
                    }

                    return(response);
                }

                if (AnswersRequired.HasValue)
                {
                    if (Answers.All(AnswerContains))
                    {
                        response.AnswerStatus = AnswerStatus.NormalCorrect;
                    }
                    else if (Answers.Any(AnswerContains))
                    {
                        response.AnswerStatus = AnswerStatus.PartiallyCorrect;
                    }
                }
                else if (Answers.Count(AnswerContains) >= AnswersRequired)
                {
                    response.AnswerStatus = AnswerStatus.NormalCorrect;
                }
                else if (Answers.Count(AnswerContains) > 0)
                {
                    response.AnswerStatus = AnswerStatus.PartiallyCorrect;
                }
            }
            catch (Exception e) // Handling any errors is the responsibility of the consumer
            {
                response.AnswerStatus = AnswerStatus.Error;
                response.Exception    = e;
            }

            return(response);
        }
Exemple #10
0
 private bool ValidatePoll() => !string.IsNullOrWhiteSpace(Title) &&
 EndDate > DateTime.Now &&
 Answers.Any() &&
 User != null;
Exemple #11
0
 public override bool IsAnswered()
 {
     return(Answers.Any(x => x.Selected));
 }
Exemple #12
0
    public bool IsAnswerCorrect(string answer)
    {
        Func <string, bool> check = GetCheckingFunction(answer);

        return(Answers.Any(check));
    }