/// <summary> /// Retrieves photos for the selected theme, user, or user's friends. /// </summary> /// <param name="hasThemeIdParam">Indicates photos should be scoped to a theme.</param> /// <param name="hasUserIdParam">Indicates photos should be scoped to a user.</param> /// <param name="isFriends">Indicates photos are to be retrieved for a user's friends. /// </param> /// <param name="userId">The PhotoHunt user id to retrieve photos or the user's friend's /// photos.</param> /// <param name="selectedTheme">The selected PhotoHunt theme.</param> /// <returns>A list of objects that can be returned as JSON.</returns> static public ArrayList GetPhotos(bool hasThemeIdParam, bool hasUserIdParam, bool isFriends, int userId, Theme selectedTheme) { // This will store JSONified representations of photo objects. ArrayList photos = new ArrayList(); if (hasThemeIdParam && hasUserIdParam) { // Return the photos for this user for this theme. PhotohuntContext db = new PhotohuntContext(); var query = from b in db.Photos where b.themeId.Equals(selectedTheme.id) && b.ownerUserId.Equals(userId) select b; if (isFriends) { query = from b in db.Photos where b.themeId.Equals(selectedTheme.id) && b.ownerUserId.Equals(userId) select b; } foreach (Photo photo in query) { photo.voted = !VotesHelper.CanVote(userId, photo.id); photos.Add(photo); } } else if (hasUserIdParam) { // Return this user's photos. PhotohuntContext db = new PhotohuntContext(); var query = from b in db.Photos where b.ownerUserId.Equals(userId) select b; foreach (Photo photo in query) { photos.Add(photo); } } else if (hasThemeIdParam) { // Return the photos for the current theme PhotohuntContext db = new PhotohuntContext(); var query = from b in db.Photos where b.themeId.Equals(selectedTheme.id) select b; foreach (Photo photo in query) { photos.Add(photo); } } return(photos); }
protected void Page_Load(object sender, EventArgs e) { try { int photoId = int.Parse(Request["photoId"]); VotesHelper voteObject = new VotesHelper(); voteObject.DoVote(Context, photoId); } catch (NullReferenceException nre) { System.Diagnostics.Debug.WriteLine("An error occurred: There was a request for a " + "photo that is not in the datastore." + nre.StackTrace); } catch (ArgumentNullException ane) { System.Diagnostics.Debug.WriteLine("An error occurred: There was a request for a " + "photo that is not in the datastore." + ane.StackTrace); } }