Esempio n. 1
0
        public void AddQuestion(Question question, List <String> tagList)
        {
            using (var context = new QuestionAnswerContext(_conn))
            {
                question.Date = DateTime.Now;

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

                foreach (String t in tagList)
                {
                    var tag = CheckTagExists(t);

                    if (tag == null)
                    {
                        Tag newtag = new Tag {
                            Name = t
                        };
                        AddTag(newtag);

                        tag = newtag;//used to add to questiontags
                    }

                    context.QuestionTags.Add(new QuestionTags
                    {
                        QuestionId = question.Id,
                        TagId      = tag.Id
                    });
                    context.SaveChanges();
                }
            }
        }
Esempio n. 2
0
 public void AddTag(Tag t)
 {
     using (var context = new QuestionAnswerContext(_conn))
     {
         context.Tags.Add(t);
         context.SaveChanges();
     }
 }
Esempio n. 3
0
 public void AddAnswer(Answer answer)
 {
     using (var context = new QuestionAnswerContext(_conn))
     {
         answer.Date = DateTime.Now;
         context.Add(answer);
         context.SaveChanges();
     }
 }
Esempio n. 4
0
 public void AddLikeAnswer(int answerId, int userId)
 {
     using (var context = new QuestionAnswerContext(_conn))
     {
         context.UserAnswerLikes.Add(new UserAnswerLikes
         {
             AnswerId = answerId,
             UserId   = userId
         });
         context.SaveChanges();
     }
 }
Esempio n. 5
0
        public void AddUser(User u)
        {
            using (var context = new QuestionAnswerContext(_conn))
            {
                //first check if the email already exists for a user
                var user = GetUserByEmail(u.Email);

                if (user is null)
                {
                    u.PasswordHash = BCrypt.Net.BCrypt.HashPassword(u.PasswordHash);
                    BCrypt.Net.BCrypt.HashPassword(u.PasswordHash);

                    context.Users.Add(u);
                    context.SaveChanges();
                }
            }
        }
Esempio n. 6
0
        public void AddLikeQuestion(int questionId, int userId)
        {
            using (var context = new QuestionAnswerContext(_conn))
            {
                var question = GetQuestionById(questionId);

                context.UserQuestionLikes.Add(new UserQuestionLikes
                {
                    QuestionId = questionId,
                    UserId     = userId
                });


                context.SaveChanges();

                //return (question.UserQuestionLikes.Count());
            }
        }