示例#1
0
        public void SetAnswer(FlashCard card, bool isCheckNeeded)
        {
            if (isCheckNeeded)
            {
                if (IsCorrectFlashCard(card) == false)
                {
                    throw new ArgumentException();
                }
            }

            var answers = card.AnswerHtmlText
                          .Split(new string[] { "<div>", "</div>" }, StringSplitOptions.RemoveEmptyEntries);

            Answers = Options
                      .Where(option =>
            {
                if (option.HtmlText != string.Empty)
                {
                    return(answers.Contains(option.HtmlText));
                }
                else
                {
                    return(option.ImageUrl == card.AnswerImageUrl);
                }
            })
                      .ToList();
        }
示例#2
0
        public bool IsCorrectFlashCard(FlashCard card)
        {
            if (card.QuestionHtmlText != HtmlText)
            {
                return(false);
            }

            var answers = card.AnswerHtmlText
                          .Split(new string[] { "<div>", "</div>" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var answer in answers)
            {
                if (Options
                    .Where(option =>
                {
                    if (option.HtmlText != string.Empty)
                    {
                        return(option.HtmlText == answer);
                    }
                    else
                    {
                        return(option.ImageUrl == card.AnswerImageUrl);
                    }
                })
                    .Count() != 1)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#3
0
        private static FlashCard ParseFlashCard(JToken json)
        {
            var flashCard = new FlashCard();

            flashCard.Id = json["id"].Value <int>();
            flashCard.QuestionHtmlText = json["question"]["text"].ToString();
            flashCard.QuestionImageUrl = json["question"]["image"]?.ToString();
            flashCard.AnswerHtmlText   = json["answer"]?["text"].ToString();
            flashCard.AnswerImageUrl   = json["answer"]?["image"]?.ToString();

            return(flashCard);
        }