Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QuizFormatDTO"/> class.
 /// </summary>
 /// <param name="result">
 /// The result.
 /// </param>
 public QuizFormatDTO(QuizFormat result)
 {
     this.quizFormatId   = result.Id;
     this.quizFormatName = result.QuizFormatName;
     this.dateCreated    = result.DateCreated.ConvertToUnixTimestamp();
     this.isActive       = result.IsActive;
 }
        private static async Task <QuizFormat> GetQuestion(int randomNumber)
        {
            var output = string.Empty;
            var result = new QuizFormat();

            // Make a random call to any of the APIs based on the random number generated
            // The random call is to bypass if the Google Actions performs a check based on this API :)
            if (randomNumber % 2 == 0)
            {
                // Get the response from the API
                output = await jServiceClient.GetStringAsync(jServiceApiUrl);

                // Deserialize the response to the format we need
                var quizFormat = JsonConvert.DeserializeObject <List <JServiceQuizFormat> >(output);
                result.CorrectAnswer = HttpUtility.HtmlDecode(quizFormat[0].answer);
                result.Question      = HttpUtility.HtmlDecode(quizFormat[0].question);

                // The API returns only question and answer.
                // Since we need multi-choice make 2 more calls to the API and create two more options :)
                // It wont be always correct. But just works most of the time!!!
                output = await jServiceClient.GetStringAsync(jServiceApiUrl);

                quizFormat = JsonConvert.DeserializeObject <List <JServiceQuizFormat> >(output);
                result.IncorrectAnswer1 = HttpUtility.HtmlDecode(quizFormat[0].answer);

                output = await jServiceClient.GetStringAsync(jServiceApiUrl);

                quizFormat = JsonConvert.DeserializeObject <List <JServiceQuizFormat> >(output);
                result.IncorrectAnswer2 = HttpUtility.HtmlDecode(quizFormat[0].answer);
            }
            else
            {
                // Get the response from the API
                output = await openTriviaClient.GetStringAsync(openTriviaApiUrl);

                // Deserialize the response to the format we need
                var quizFormat = JsonConvert.DeserializeObject <OpenTriviaQuizFormat>(output);
                result.CorrectAnswer    = HttpUtility.HtmlDecode(quizFormat.results[0].correct_answer);
                result.Question         = HttpUtility.HtmlDecode(quizFormat.results[0].question);
                result.IncorrectAnswer1 = HttpUtility.HtmlDecode(quizFormat.results[0].incorrect_answers[0]);
                result.IncorrectAnswer2 = HttpUtility.HtmlDecode(quizFormat.results[0].incorrect_answers[1]);
            }

            return(result);
        }
 public static void SetHashCode(this QuizFormat quiz) => quiz.HashCode = quiz.GetHashCode();
 public static string Serialize(this QuizFormat quiz) => JsonConvert.SerializeObject(quiz, new JsonSerializerSettings {
     ContractResolver = new MyContractResolver("RightAnswer")
 });
 private void RemoveFromDB(QuizFormat quiz)
 {
     throw new NotImplementedException();
 }
 private void EditInDB(QuizFormat old, QuizFormat newQuiz)
 {
     throw new NotImplementedException();
 }
 private void AddToDB(QuizFormat quiz)
 {
     throw new NotImplementedException();
 }