Exemple #1
0
 public AnswerModel Create(Answer answer)
 {
     return new AnswerModel
     {
         Url = _urlHelper.Link("AnswerApi", new { id = answer.Id }),
         Body = answer.Body,
         Score = answer.Score,
         CreationDate = answer.CreationDate,
         Owner = answer.Owner,
         ParentId = answer.ParentId
     };
 }
Exemple #2
0
 public static void Setup(int testItems)
 {
     SetTestRepo();
     for(int i=0;i<testItems;i++){
         Answer item=new Answer();
         _testRepo._items.Add(item);
     }
 }
        private void SeedTypes(DatabaseContext context)
        {
            var question = new Question()
            {
                CreationDate = DateTime.Now,
                Title        = "Uusim küsimus",
                Description  = "Mis küll selle küsimusega võiks mõelda?",
                Public       = true
            };

            context.Questions.Add(question);
            context.SaveChanges();

            var answer = new Answer()
            {
                Question     = question,
                CreationDate = DateTime.Now,
                Title        = "Uusim"
            };
            var answer2 = new Answer()
            {
                Question     = question,
                CreationDate = DateTime.Now,
                Title        = "Vanim"
            };

            context.Answers.Add(answer);
            context.SaveChanges();
            context.Answers.Add(answer2);
            context.SaveChanges();


            var blog = new Blog()
            {
                Title = "Tiitel",
                Body  = "pikkteksttegelteiole",
            };

            context.Blogs.Add(blog);
            context.SaveChanges();

            var comment = new Comment()
            {
                Blog = blog,
                User = "******",
                Body = "Sitt blogi sul"
            };

            context.Comments.Add(comment);
            context.SaveChanges();

            var comment2 = new Comment()
            {
                Blog = blog,
                Body = "Meie oleme anan[[msed , djontaplikesiondesign"
            };

            context.Comments.Add(comment2);
            context.SaveChanges();

            //    public int CommentId { get; set; }
            //[MaxLength(100)]
            //public string User { get; set; } = "Anonymous";
            //[MaxLength(3000), MinLength(1)]
            //public string Body { get; set; }
            //public int BlogId { get; set; }
            //public virtual Blog Blog { get; set; }
        }
Exemple #4
0
 public static void Setup(Answer item)
 {
     SetTestRepo();
     _testRepo._items.Add(item);
 }
Exemple #5
0
 public void AddChosenAnswer(Answer answer)
 {
     _provider.AddChosenAnswer(answer);
 }
 /// <summary>
 /// Create a new Answer object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="questionId">Initial value of the QuestionId property.</param>
 /// <param name="answerId">Initial value of the AnswerId property.</param>
 /// <param name="answer1">Initial value of the Answer1 property.</param>
 public static Answer CreateAnswer(global::System.Int32 id, global::System.Int32 questionId, global::System.Int32 answerId, global::System.String answer1)
 {
     Answer answer = new Answer();
     answer.Id = id;
     answer.QuestionId = questionId;
     answer.AnswerId = answerId;
     answer.Answer1 = answer1;
     return answer;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Answers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAnswers(Answer answer)
 {
     base.AddObject("Answers", answer);
 }
Exemple #8
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;
         }
     }
 }