code_junkie

Updating the view count of a webpage in a database

Nov 13th, 2011
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. /// <summary>
  2. /// Updates the view count of a post.
  3. /// </summary>
  4. /// <param name="postId">The Id of the post to update</param>
  5. public bool UpdateViewCount(int postId)
  6. {
  7. Repository repository = new Repository();
  8. Post p = repository.Posts.Where(p => p.Id == postId).SingleOrDefault();
  9. if (p != null)
  10. {
  11. p.Views++;
  12. }
  13. repository.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
  14. }
  15.  
  16. UPDATE table SET views=views+1 WHERE myId=12;
  17.  
  18. _db.ExecuteCommand("UPDATE posts SET views=views+1 WHERE id={0}", postId);
Add Comment
Please, Sign In to add comment