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}"); } } }
/************************************** * Answer **************************************/ public Answer GetAnswer(int id) { using (var db = new StackOverflowDbContext()) { return(db.Answers.FirstOrDefault(a => a.Id == id)); } }
public int GetNumbersOfUsers() { using (var db = new StackOverflowDbContext()) { return(db.Users.Count()); } }
/************************************** * User **************************************/ public User FindUser(int id) { using (var db = new StackOverflowDbContext()) { return(db.Users.FirstOrDefault(u => u.Id == id)); } }
public int GetNumberOfSearchsWithSearchUserId(int searchUserId) { using (var db = new StackOverflowDbContext()) { return(db.Searchs.Count(s => s.SearchUserId == searchUserId)); } }
public SearchUser FindSearchUser(int id) { using (var db = new StackOverflowDbContext()) { return(db.SearchUsers.FirstOrDefault(su => su.Id == id)); } }
/************************************** * Tag **************************************/ public Tag FindTag(int id) { using (var db = new StackOverflowDbContext()) { return(db.Tags.FirstOrDefault(t => t.Id == id)); } }
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)); } }
public Search FindSearch(int id) { using (var db = new StackOverflowDbContext()) { return(db.Searchs.FirstOrDefault(s => s.Id == id)); } }
public int GetNumberOfQuestions() { using (var db = new StackOverflowDbContext()) { return(db.Questions.Count()); } }
public IEnumerable <Comment> GetComments() { using (var db = new StackOverflowDbContext()) { return(db.Comments.ToList()); } }
public int GetNumberOfTags() { using (var db = new StackOverflowDbContext()) { return(db.Tags.Count()); } }
/************************************** * Comment **************************************/ public Comment FindComment(int id) { using (var db = new StackOverflowDbContext()) { return(db.Comments.FirstOrDefault(c => c.Id == id)); } }
public int GetNumberOfAnswersWithQuestionId(int questionId) { using (var db = new StackOverflowDbContext()) { return(db.Answers .Count(a => a.QuestionId == questionId)); } }
public int GetNumberOfQuestionsSearchResults(string searchString) { using (var db = new StackOverflowDbContext()) { return(db.Questions .Count(q => q.Body.Contains(searchString))); } }
public int GetNumberOfQuestionsWithTagId(int tagId) { using (var db = new StackOverflowDbContext()) { return(db.Posts .Count(p => p.Tags.Any(t => t.Id == tagId))); } }
/************************************** * Question **************************************/ public Question GetQuestion(int id) { using (var db = new StackOverflowDbContext()) { return(db.Questions .FirstOrDefault(q => q.Id == id)); } }
public int GetNumberOfCommentsWithQuestionId(int questionId) { using (var db = new StackOverflowDbContext()) { return(db.Comments .Count(c => c.PostId == questionId)); } }
public Comment FindCommentOnQuestion(int commentId) { using (var db = new StackOverflowDbContext()) { return(db.Comments .FirstOrDefault(c => c.Id == commentId)); } }
public IEnumerable <SearchUser> GetSearchUsersByMacAdresse(string macAdresse) { using (var db = new StackOverflowDbContext()) { return(db.SearchUsers.Where(su => su.MacAdresse == macAdresse) .ToList()); } }
public int GetNumberOfAnnotationsOnQuestions() { using (var db = new StackOverflowDbContext()) { return(db.Annotations .Count(a => db.Questions.Any(an => an.Id == a.PostId))); } }
public int GetNumberOfAnnotationsWithSearchUserId(int searchUserId) { using (var db = new StackOverflowDbContext()) { return(db.Annotations .Count(a => a.SearchUserId == searchUserId)); } }
public int GetNumberOfCommentsWithAnswerId(int answerId) { using (var db = new StackOverflowDbContext()) { return(db.Comments .Count(c => c.PostId == answerId)); } }
public int GetNumbersOfAnswersWithUserId(int userId) { using (var db = new StackOverflowDbContext()) { return(db.Answers .Count(a => a.UserId == userId)); } }
public int GetNumbersOfCommentsWithUserId(int userId) { using (var db = new StackOverflowDbContext()) { return(db.Comments .Count(q => q.UserId == userId)); } }
public int GetNumbersOfTagsWithQuestionId(int questionId) { using (var db = new StackOverflowDbContext()) { return(db.Tags .Count(t => t.Posts.Any(p => p.Id == questionId))); } }
public IEnumerable <Question> GetAllQuestions() { using (var db = new StackOverflowDbContext()) { return(db.Questions .OrderBy(q => q.Id) .ToList()); } }
public IEnumerable <Annotation> GetAllAnnotations() { using (var db = new StackOverflowDbContext()) { return(db.Annotations .OrderBy(a => a.Id) .ToList()); } }
public IEnumerable <Annotation> GetAnnotations(string searchString) { using (var db = new StackOverflowDbContext()) { return(db.Annotations .Where(a => a.Body.Contains(searchString)) .ToList()); } }
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(); } }