예제 #1
0
 public User GetUser(int id)
 {
     using (var db = new SovaContext())
     {
         return(db.Users.FirstOrDefault(user => user.Id == id));
     }
 }
예제 #2
0
 internal static void FillTags(this Question question)
 {
     using (var db = new SovaContext())
     {
         question.Tags = db.QuestionTags.Include(qt => qt.Tag).Where(x => x.QuestionId == question.Id).Select(qt => qt.Tag).ToList();
     }
 }
예제 #3
0
 public Note GetNote(int noteId)
 {
     using (var db = new SovaContext())
     {
         return(db.Notes.FirstOrDefault(note => note.Id == noteId));
     }
 }
예제 #4
0
 public bool IsPostMarked(int id)
 {
     using (var db = new SovaContext())
     {
         return(db.Marked.Any(mp => mp.PostId == id));
     }
 }
예제 #5
0
 internal static void FillAnswers(this Question question)
 {
     using (var db = new SovaContext())
     {
         var answers = db.Answers.Where(x => x.QuestionId == question.Id).ToList();
         question.Answers = answers;
     }
 }
예제 #6
0
 internal static void FillComments(this Post post)
 {
     using (var db = new SovaContext())
     {
         var comments = db.Comments.Include(c => c.Owner).Where(x => x.ParentId == post.Id).ToList();
         post.Comments = comments;
     }
 }
예제 #7
0
 public Post GetPost(int id)
 {
     using (var db = new SovaContext())
     {
         return(db.Answers.Select(ans => (Post)ans).Concat(db.Questions.Select(que => (Post)que))
                .FirstOrDefault(post => post.Id == id));
     }
 }
예제 #8
0
        public List <RankedWord> GetWeightedWordList(string name, int page, int pageSize, out int totalResults)
        {
            using (var db = new SovaContext())
            {
                var returnPosts = db.RankedWord.FromSql("CALL weightedWordList({0})", name).Paginated(page, pageSize, out totalResults).ToList();

                return(returnPosts);
            }
        }
예제 #9
0
        public bool ClearHistory()
        {
            using (var db = new SovaContext())
            {
                db.Database.ExecuteSqlCommand("CALL clearHistory()");

                return(true);
            }
        }
예제 #10
0
 public Boolean UpdateNote(int noteId, string text)
 {
     using (var db = new SovaContext())
     {
         var result = db.Database.ExecuteSqlCommand("CALL updateNote({0}, {1})", noteId, text);
         Debug.WriteLine(result);
         return(result > 0);
     }
 }
예제 #11
0
 public Boolean DeleteNote(int noteId)
 {
     using (var db = new SovaContext())
     {
         var result = db.Database.ExecuteSqlCommand("CALL removeNote({0})", noteId);
         Debug.WriteLine(result);
         return(result > 0);
     }
 }
예제 #12
0
 public bool UnmarkPost(int id)
 {
     using (var db = new SovaContext())
     {
         var result = db.Database.ExecuteSqlCommand("CALL removeMarkedPost({0})", id);
         Debug.WriteLine(result);
         return(result > 0);
     }
 }
예제 #13
0
        public List <History> GetHistory(int page, int pageSize, out int totalResults)
        {
            using (var db = new SovaContext())
            {
                var history = db.History.Paginated(page, pageSize, out totalResults).ToList();

                return(history);
            }
        }
예제 #14
0
        public List <RankedWordPair> GetRelatedWords(string terms, int page, int pageSize, out int totalResults)
        {
            using (var db = new SovaContext())
            {
                var searchResult = db.RankedWordPair.FromSql("CALL co_occuring_words({0})", terms);

                var currentPage = searchResult.Paginated(page, pageSize, out totalResults).ToList();
                return(currentPage);
            }
        }
예제 #15
0
 public List <SearchQuestion> GetQuestionByTitle(string title, int page, int pageSize, out int totalResults)
 {
     using (var db = new SovaContext())
     {
         var returnPosts = db.SearchQuestions.FromSql("CALL bestmatch({0})", title).Paginated(page, pageSize, out totalResults).ToList();
         foreach (var post in returnPosts)
         {
             post.FillTags();
         }
         return(returnPosts);
     }
 }
예제 #16
0
 public List <RankedSearchQuestion> GetQuestionByTag(string tag, int page, int pageSize, out int totalResults)
 {
     using (var db = new SovaContext())
     {
         var returnPosts = db.RankedSearchQuestion.FromSql("CALL tagSearch({0})", tag).Paginated(page, pageSize, out totalResults).ToList();
         foreach (var post in returnPosts)
         {
             post.FillTags();
         }
         return(returnPosts);
     }
 }
예제 #17
0
 public List <Question> GetPostsHighestScore(int page, int pageSize, out int totalResults)
 {
     using (var db = new SovaContext()) {
         List <Question> returnQuestions = db.Questions
                                           .Include(x => x.Answers)
                                           .Include(x => x.Owner)
                                           .OrderByDescending(x => x.Score)
                                           .Paginated(page, pageSize, out totalResults)
                                           .ToList();
         returnQuestions.ForEach(post => post.FillTags());
         return(returnQuestions);
     }
 }
예제 #18
0
 public List <Note> GetNotes(int postId)
 {
     using (var db = new SovaContext())
     {
         if (db.Posts.Any(post => post.Id == postId))
         {
             return(db.Notes.Where(note => note.PostId == postId).ToList());
         }
         else
         {
             return(null);
         }
     }
 }
예제 #19
0
 public List <Note> GetNotes(int postId, int page, int pageSize, out int totalResults)
 {
     using (var db = new SovaContext())
     {
         if (db.Posts.Any(post => post.Id == postId))
         {
             return(db.Notes.Where(note => note.PostId == postId).Paginated(page, pageSize, out totalResults).ToList());
         }
         else
         {
             totalResults = 0;
             return(null);
         }
     }
 }
예제 #20
0
 public List <RankedSearchQuestion> SearchPostsOrderedByNewest(string title, int page, int pageSize, string orderBy, out int totalResults)
 {
     using (var db = new SovaContext())
     {
         var returnPosts = db.RankedSearchQuestion.FromSql("CALL bestmatch({0})", title)
                           .OrderByDescending(q => q.Created)
                           .Paginated(page, pageSize, out totalResults)
                           .ToList();
         foreach (var post in returnPosts)
         {
             post.FillTags();
         }
         return(returnPosts);
     }
 }
예제 #21
0
        public Note CreateNote(int postId, string text)
        {
            using (var db = new SovaContext())
            {
                try
                {
                    var result = db.Notes.FromSql("CALL createNote({0}, {1})", postId, text).FirstOrDefault();
                    return(result);
                }
                catch (MySqlException)
                {
                }

                return(null);
            }
        }
예제 #22
0
 public Question GetQuestionAllData(int id)
 {
     using (var db = new SovaContext())
     {
         var question = db.Questions.Include(q => q.Owner)
                        .Include(q => q.Comments).ThenInclude(c => c.Owner)
                        .Include(q => q.Answers).ThenInclude(a => a.Owner)
                        .Include(q => q.Answers).ThenInclude(a => a.Comments).ThenInclude(c => c.Owner)
                        .FirstOrDefault(x => x.Id == id);
         if (question == null)
         {
             return(null);
         }
         question.FillTags();
         return(question);
     }
 }
예제 #23
0
        public List <MarkedPost> GetMarkedPosts(int page, int pageSize, out int totalResults)
        {
            using (var db = new SovaContext())
            {
                var posts = db.Marked.Include(mp => mp.Post)
                            .ThenInclude(mp => mp.Answers)
                            .Include(mp => mp.Post)
                            .ThenInclude(mp => mp.Owner)
                            .Paginated(page, pageSize, out totalResults).ToList();

                foreach (var post in posts)
                {
                    post.Post.FillTags();
                }

                return(posts);
            }
        }
예제 #24
0
        public bool AddHistory(string searchWord)
        {
            if (searchWord == null)
            {
                return(false);
            }
            using (var db = new SovaContext())
            {
                try
                {
                    db.Database.ExecuteSqlCommand("CALL addHistory({0})", searchWord);

                    return(true);
                }
                catch (MySqlException)
                {
                    return(false);
                }
            }
        }
예제 #25
0
        public List <RankedSearchQuestion> SearchPosts(string terms, int page, int pageSize, string orderBy, out int totalResults)
        {
            using (var db = new SovaContext())
            {
                var searchResult = db.RankedSearchQuestion.FromSql("CALL bestmatch({0})", terms);
                switch (orderBy)
                {
                case "age":
                    searchResult = searchResult.OrderByDescending(item => item.Created);
                    break;

                case "score":
                    searchResult = searchResult.OrderByDescending(item => item.Score);
                    break;
                }
                var currentPage = searchResult.Paginated(page, pageSize, out totalResults).ToList();
                currentPage.ForEach(post => post.FillTags());
                return(currentPage);
            }
        }
예제 #26
0
        public Boolean MarkPost(int id)
        {
            using (var db = new SovaContext())
            {
                if (db.Marked.Any(mp => mp.PostId == id))
                {
                    return(true);
                }


                try
                {
                    db.Database.ExecuteSqlCommand("CALL setMarkedPost({0})", id);

                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }