Exemplo n.º 1
0
 public QuestionModel Create(Question question )
 {
     return new QuestionModel
     {
         Url = _urlHelper.Link("QuestionByIdApi", new { id = question.Id }),
         Body = question.Body,
         Title = question.Title,
         Score = question.Score,
         CreationDate = question.CreationDate,
         Owner = question.Owner
     };
 }
Exemplo n.º 2
0
 public static void Setup(int testItems)
 {
     SetTestRepo();
     for(int i=0;i<testItems;i++){
         Question item=new Question();
         _testRepo._items.Add(item);
     }
 }
Exemplo n.º 3
0
 public static void Setup(Question item)
 {
     SetTestRepo();
     _testRepo._items.Add(item);
 }
 /// <summary>
 /// Create a new Question object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="questionText">Initial value of the QuestionText property.</param>
 public static Question CreateQuestion(global::System.Int32 id, global::System.String questionText)
 {
     Question question = new Question();
     question.Id = id;
     question.QuestionText = questionText;
     return question;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Questions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToQuestions(Question question)
 {
     base.AddObject("Questions", question);
 }
Exemplo n.º 6
0
 public Test GetAllTestById(int testId)
 {
     using (SqlConnection connection = new SqlConnection(_connectionString))
     {
         var command = connection.CreateCommand();
         command.CommandType = CommandType.StoredProcedure;
         command.CommandText = "dbo.GetAllTestById";
         command.Parameters.AddWithValue("@id", testId);
         connection.Open();
         try
         {
             var  reader = command.ExecuteReader();
             Test test   = null;
             Dictionary <int, Question> questions = new Dictionary <int, Question>();
             while (reader.Read())
             {
                 if (test == null)
                 {
                     test = new Test()
                     {
                         ID          = (int)reader["testId"],
                         Description = reader["description"] as string,
                         Time        = (int)reader["time"],
                         Category    = new Category()
                         {
                             ID = (int)reader["id_Category"]
                         },
                         Subject = new Subject()
                         {
                             ID = (int)reader["id_Subject"]
                         }
                     };
                 }
                 Question questionFromRequest = new Question()
                 {
                     ID    = (int)reader["idQuestion"],
                     Text  = reader["textQuestion"] as string,
                     Image = reader["imageQuestion"] == DBNull.Value ? null : Convert.FromBase64String((string)reader["imageQuestion"])
                 };
                 Answer answer = new Answer()
                 {
                     ID         = (int)reader["idAnswer"],
                     AnswerText = reader["textAnswer"] as string,
                     IsCorrect  = (bool)reader["IsCorrectAnswer"]
                 };
                 if (questions.TryGetValue((int)reader["idQuestion"], out Question question))
                 {
                     question.Answers.Add(answer);
                 }
                 else
                 {
                     questions.Add((int)reader["idQuestion"], questionFromRequest);
                     questionFromRequest.Answers.Add(answer);
                 }
             }
             test.Questions = questions.Select(kvp => kvp.Value).ToList();;
             return(test);
         }
         catch (SqlException e)
         {
             _log.Error(e.Message);
             throw e;
         }
     }
 }