Esempio n. 1
0
 public Question GetQuestionForId(int questionId)
 {
     using (var context = new StackOverflowContext(_connectionString))
     {
         return(context.Questions.FirstOrDefault(q => q.Id == questionId));
     }
 }
Esempio n. 2
0
 public List <Question> GetQuestions()
 {
     using (var context = new StackOverflowContext(_connectionString))
     {
         return(context.Questions.OrderByDescending(q => q.DatePosted).ToList());
     }
 }
 public void PostLike(Like like)
 {
     using (var context = new StackOverflowContext(_connectionString))
     {
         context.Likes.Add(like);
         context.SaveChanges();
     }
 }
 public void PostAnswer(Answer answer)
 {
     using (var context = new StackOverflowContext(_connectionString))
     {
         context.Answers.Add(answer);
         context.SaveChanges();
     }
 }
 public void PostQuestion(Question question)
 {
     using (var context = new StackOverflowContext(_connectionString))
     {
         context.Questions.Add(question);
         context.SaveChanges();
     }
 }
Esempio n. 6
0
 public List <Answer> GetAnswersForId(int questionId)
 {
     using (var context = new StackOverflowContext(_connectionString))
     {
         List <Answer> answers = context.Answers.Where(a => a.QuestionId == questionId).ToList();
         return(answers);
     }
 }
Esempio n. 7
0
 public bool GetUserLiked(int questionId, int userId)
 {
     using (var context = new StackOverflowContext(_connectionString))
     {
         bool userLiked = context.Likes.Any(l => l.QuestionId == questionId && l.UserId == userId);
         return(userLiked);
     }
 }
Esempio n. 8
0
 public int GetNumberOfLikes(int questionId)
 {
     using (var context = new StackOverflowContext(_connectionString))
     {
         int numberOfLikes = context.Likes.Where(l => l.QuestionId == questionId).ToList().Count();
         return(numberOfLikes);
     }
 }
 public void AddUser(User user)
 {
     user.Password = BCrypt.Net.BCrypt.HashPassword(user.Password);
     using (var context = new StackOverflowContext(_connectionString))
     {
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
Esempio n. 10
0
        public int GetIdForEmail(string email)
        {
            int id = 0;

            using (var context = new StackOverflowContext(_connectionString))
            {
                id = context.Users.FirstOrDefault(u => u.Email == email).Id;
            }
            return(id);
        }
Esempio n. 11
0
        public string GetPasswordForEmail(string email)
        {
            string password = "";

            using (var context = new StackOverflowContext(_connectionString))
            {
                password = context.Users.FirstOrDefault(u => u.Email == email).Password;
            }
            return(password);
        }
Esempio n. 12
0
        public List <Tag> GetTagsForId(int questionId)
        {
            using (var context = new StackOverflowContext(_connectionString))
            {
                List <Tag> tags = context.Tags.FromSql(@"SELECT T.Id, T.Name FROM Tags T
						JOIN QuestionsTags QT
						ON T.Id=QT.TagId
						WHERE QuestionId=@questionId"                        ,
                                                       new SqlParameter("@questionid", questionId)).ToList();
                return(tags);
            }
        }
 public UnitOfWork()
 {
     _context = new StackOverflowContext();
 }