Example #1
0
 public List <UpVote> GetUpvotes()
 {
     using (var context = new HackerNewsDatabaseDataContext(@"Data Source=.\sqlexpress;Initial Catalog=HackerNews;Integrated Security=True"))
     {
         return(context.UpVotes.ToList());
     }
 }
Example #2
0
 public void AddUpVote(UpVote Upvote)
 {
     using (var context = new HackerNewsDatabaseDataContext(@"Data Source=.\sqlexpress;Initial Catalog=HackerNews;Integrated Security=True"))
     {
         context.UpVotes.InsertOnSubmit(Upvote);
         context.SubmitChanges();
     }
 }
Example #3
0
 public void AddLink(Link Link)
 {
     using (var context = new HackerNewsDatabaseDataContext(@"Data Source=.\sqlexpress;Initial Catalog=HackerNews;Integrated Security=True"))
     {
         context.Links.InsertOnSubmit(Link);
         context.SubmitChanges();
     }
 }
Example #4
0
 public int GetUpvoteAmount(int linkId)
 {
     using (var context = new HackerNewsDatabaseDataContext(@"Data Source=.\sqlexpress;Initial Catalog=HackerNews;Integrated Security=True"))
     {
         int amount = context.UpVotes.Count(u => u.LinkId == linkId);
         return(amount);
     }
 }
Example #5
0
 public User GetUserId(string userName)
 {
     using (var context = new HackerNewsDatabaseDataContext(@"Data Source=.\sqlexpress;Initial Catalog=HackerNews;Integrated Security=True"))
     {
         User user = context.Users.FirstOrDefault(u => u.UserName == userName);
         return(user);
     }
 }
Example #6
0
        public IEnumerable <Link> GetAllLinksByUser(int userId)
        {
            using (var context = new HackerNewsDatabaseDataContext(@"Data Source=.\sqlexpress;Initial Catalog=HackerNews;Integrated Security=True"))
            {
                var loadOptions = new DataLoadOptions();
                loadOptions.LoadWith <Link>(l => l.User);
                loadOptions.LoadWith <Link>(l => l.UpVotes);
                context.LoadOptions = loadOptions;

                return(context.Links.Where(l => l.UserId == userId).ToList());
            }
        }