public bool Upvote(int id)
 {
     //Upvote an animal
       using (var context = new WildscreenAnimalsAPI_dbEntities())
       {
     var image = context.AnimalImages.Where(x => x.Id == id).FirstOrDefault();
     image.Upvotes++;
     context.SaveChanges();
       }
       return true;
 }
        static void Main(string[] args)
        {
            //open DB
              using (var context = new WildscreenAnimalsAPI_dbEntities())
              {
            var animals = context.Animals.ToList();//Get all animals
            var allAnimalImages = context.AnimalImages.ToList();

            foreach (var animal in animals)
            {
              //Do a flickr search on the animal
              var json = SendRequest(string.Format(flickrSearchUrl, flickrKey, WebUtility.UrlEncode(animal.Name)));
              var searchResult = JsonConvert.DeserializeObject<FlickrSearchResponse>(json);
              //Loop through flikr images returned in the resuts and get image urls for them
              if(searchResult.photos != null && searchResult.photos.photo.Count > 0)
              {
            foreach(var fPhoto in searchResult.photos.photo)
            {
              var photo = new AnimalImage()
              {
                Animal_Id = animal.Id,
                CreatedOn = DateTime.Now,
                Downvotes = 0,
                Upvotes = 0,
                SourceSystem = "Flickr",
                ImageUrl = string.Format(flickrImageUrl,fPhoto.farm,fPhoto.server,fPhoto.id,fPhoto.secret),
                Name = fPhoto.title
              };
              if(!allAnimalImages.Any(x => x.ImageUrl == photo.ImageUrl))
                context.AnimalImages.Add(photo);
            }//foreach
              }//if
              //Create an image record
            }
            //Save
            context.SaveChanges();
              } //close db
        }