public void Add(Photo photo, Stream binary, string mimeType, string name)
        {
            // get just the file name and ignore the path
            var file = name.Substring(name.LastIndexOf("\\", StringComparison.OrdinalIgnoreCase) + 1);

            var context = new PhotoAlbumDataContext();

            try
            {
                // add the photo to table storage
                context.AddObject(PhotoAlbumDataContext.PhotoTable, new PhotoRow(photo));
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("EntityAlreadyExists"))
                {
                    throw new PhotoNameAlreadyInUseException(photo.AlbumId, photo.Title);
                }
                else
                {
                    throw;
                }
            }

            // add the binary to blob storage
            var storage = this.storageAccount.CreateCloudBlobClient();
            var container = storage.GetContainerReference(photo.Owner.ToLowerInvariant());
            container.CreateIfNotExist();
            container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
            var blob = container.GetBlobReference(file);

            blob.Properties.ContentType = mimeType;
            blob.UploadFromStream(binary);

            // post a message to the queue so it can process tags and the sizing operations
            this.SendToQueue(
                Constants.PhotoQueue,
                string.Format(CultureInfo.InvariantCulture, "{0}|{1}|{2}|{3}", photo.Owner, photo.AlbumId, photo.PhotoId, file));
        }
        public void Delete(Photo photo)
        {
            var context = new PhotoAlbumDataContext();
            var photoRow = new PhotoRow(photo);

            context.AttachTo(PhotoAlbumDataContext.PhotoTable, photoRow, "*");
            context.DeleteObject(photoRow);
            context.SaveChanges();

            // tell the worker role to clean up blobs and tags
            this.SendToQueue(
                Constants.PhotoCleanupQueue,
                string.Format(CultureInfo.InvariantCulture, "{0}|{1}|{2}|{3}|{4}|{5}", photo.PhotoId, photo.Owner, photo.Url, photo.RawTags, photo.ThumbnailUrl, photo.AlbumId));
        }
        public void UpdatePhotoData(Photo photo)
        {
            var context = new PhotoAlbumDataContext();
            var photoRow = new PhotoRow(photo);

            // attach and update the photo row
            context.AttachTo(PhotoAlbumDataContext.PhotoTable, photoRow, "*");
            context.UpdateObject(photoRow);
            context.SaveChanges();
        }