Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. PictureHelper.PictureViewCounter(PictureHelper.GetSinglePicture(userID,pic), (List<int>)Session["ViewedPictures"], pic);
  2.  
  3. public static Picture GetSinglePicture(int userID, int picture)
  4. {
  5. DBContext db = new DBContext();
  6.  
  7. return (from p in db.Pictures
  8. where userID == p.UserID && picture == p.Url
  9. select p).First();
  10. }
  11.  
  12. public static void PictureViewCounter(Picture picture, List<int> pictureArray, int pictureUrl)
  13. {
  14. PetscoveryDBContext db = new PetscoveryDBContext();
  15. if (pictureArray == null)
  16. {
  17. //Automatically +1 picture views
  18. picture.Views++;
  19. db.SaveChanges(); //does not save
  20. }
  21. else
  22. {
  23. int result = pictureArray.Find(pic => pic == pictureUrl);
  24. //if result == 0 increase picture views by 1
  25. picture.Views++;
  26. db.SaveChanges(); //does not save
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement