public List <UpVote> GetUpvotes() { using (var context = new HackerNewsDatabaseDataContext(@"Data Source=.\sqlexpress;Initial Catalog=HackerNews;Integrated Security=True")) { return(context.UpVotes.ToList()); } }
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(); } }
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(); } }
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); } }
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); } }
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()); } }