示例#1
0
        public static void Main(string[] args)
        {
            Application.Init();
            Application.Current.Width = Dim.Fill();
            Application.Top.Add(new MainWindow());
            Application.Run();

            return;

            // Converted from https://data.stackexchange.com/stackoverflow/query/785/how-many-upvotes-do-i-have-for-each-tag


            byte voteType = 2;
            int  userId   = 55;

            using (var db = new StackOverflowDbContext())
            {
                var query =
                    from t in db.Tags
                    join pt in db.PostTags on t.Id equals pt.TagId
                    join p in db.Posts on pt.PostId equals p.ParentId
                    join v in db.Votes on new { PostId = p.Id, VoteTypeId = voteType }
                equals new { v.PostId, v.VoteTypeId }
                where p.OwnerUserId == userId
                group t by t.TagName into g
                select new { TagName = g.Key, Upvotes = g.Count() };

                query = query.OrderBy(t => t.Upvotes);

                foreach (var item in query.ToList())
                {
                    Console.WriteLine($"{item.TagName} {item.Upvotes}");
                }
            }
        }
示例#2
0
 /**************************************
 *   Answer
 **************************************/
 public Answer GetAnswer(int id)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Answers.FirstOrDefault(a => a.Id == id));
     }
 }
示例#3
0
 public int GetNumbersOfUsers()
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Users.Count());
     }
 }
示例#4
0
 /**************************************
 *   User
 **************************************/
 public User FindUser(int id)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Users.FirstOrDefault(u => u.Id == id));
     }
 }
示例#5
0
 public int GetNumberOfSearchsWithSearchUserId(int searchUserId)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Searchs.Count(s => s.SearchUserId == searchUserId));
     }
 }
示例#6
0
 public SearchUser FindSearchUser(int id)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.SearchUsers.FirstOrDefault(su => su.Id == id));
     }
 }
示例#7
0
 /**************************************
 *   Tag
 **************************************/
 public Tag FindTag(int id)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Tags.FirstOrDefault(t => t.Id == id));
     }
 }
示例#8
0
 public int GetNumberOfAnnotationsWithAnswerIdSearchUserId(int answerId, int searchUserId)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Annotations.Where(a => a.SearchUserId == searchUserId).Count(a => a.PostId == answerId));
     }
 }
示例#9
0
 public Search FindSearch(int id)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Searchs.FirstOrDefault(s => s.Id == id));
     }
 }
示例#10
0
 public int GetNumberOfQuestions()
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Questions.Count());
     }
 }
示例#11
0
 public IEnumerable <Comment> GetComments()
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Comments.ToList());
     }
 }
示例#12
0
 public int GetNumberOfTags()
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Tags.Count());
     }
 }
示例#13
0
 /**************************************
 *   Comment
 **************************************/
 public Comment FindComment(int id)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Comments.FirstOrDefault(c => c.Id == id));
     }
 }
示例#14
0
 public int GetNumberOfAnswersWithQuestionId(int questionId)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Answers
                .Count(a => a.QuestionId == questionId));
     }
 }
示例#15
0
 public int GetNumberOfQuestionsSearchResults(string searchString)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Questions
                .Count(q => q.Body.Contains(searchString)));
     }
 }
示例#16
0
 public int GetNumberOfQuestionsWithTagId(int tagId)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Posts
                .Count(p => p.Tags.Any(t => t.Id == tagId)));
     }
 }
示例#17
0
 /**************************************
 *   Question
 **************************************/
 public Question GetQuestion(int id)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Questions
                .FirstOrDefault(q => q.Id == id));
     }
 }
示例#18
0
 public int GetNumberOfCommentsWithQuestionId(int questionId)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Comments
                .Count(c => c.PostId == questionId));
     }
 }
示例#19
0
 public Comment FindCommentOnQuestion(int commentId)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Comments
                .FirstOrDefault(c => c.Id == commentId));
     }
 }
示例#20
0
 public IEnumerable <SearchUser> GetSearchUsersByMacAdresse(string macAdresse)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.SearchUsers.Where(su => su.MacAdresse == macAdresse)
                .ToList());
     }
 }
示例#21
0
 public int GetNumberOfAnnotationsOnQuestions()
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Annotations
                .Count(a => db.Questions.Any(an => an.Id == a.PostId)));
     }
 }
示例#22
0
 public int GetNumberOfAnnotationsWithSearchUserId(int searchUserId)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Annotations
                .Count(a => a.SearchUserId == searchUserId));
     }
 }
示例#23
0
 public int GetNumberOfCommentsWithAnswerId(int answerId)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Comments
                .Count(c => c.PostId == answerId));
     }
 }
示例#24
0
 public int GetNumbersOfAnswersWithUserId(int userId)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Answers
                .Count(a => a.UserId == userId));
     }
 }
示例#25
0
 public int GetNumbersOfCommentsWithUserId(int userId)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Comments
                .Count(q => q.UserId == userId));
     }
 }
示例#26
0
 public int GetNumbersOfTagsWithQuestionId(int questionId)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Tags
                .Count(t => t.Posts.Any(p => p.Id == questionId)));
     }
 }
示例#27
0
 public IEnumerable <Question> GetAllQuestions()
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Questions
                .OrderBy(q => q.Id)
                .ToList());
     }
 }
示例#28
0
 public IEnumerable <Annotation> GetAllAnnotations()
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Annotations
                .OrderBy(a => a.Id)
                .ToList());
     }
 }
示例#29
0
 public IEnumerable <Annotation> GetAnnotations(string searchString)
 {
     using (var db = new StackOverflowDbContext())
     {
         return(db.Annotations
                .Where(a => a.Body.Contains(searchString))
                .ToList());
     }
 }
示例#30
0
 public void Insert(SearchUser searchUser)
 {
     using (var db = new StackOverflowDbContext())
     {
         searchUser.Id = db.SearchUsers.Max(a => a.Id) + 1;
         db.SearchUsers.Add(searchUser);
         db.SaveChanges();
     }
 }