public ActionResult Create(PhotoViewModel photoViewModel, HttpPostedFileBase file, bool Public, FormCollection collection)
        {
            if (this.ModelState.IsValid)
            {
                photoViewModel.PartitionKey = Public ? "Public" : this.User.Identity.Name;
                var photo = this.FromViewModel(photoViewModel);

                if (file != null)
                {
                    //Save file stream to Blob Storage
                    var blob = this.GetBlobContainer().GetBlockBlobReference(file.FileName);
                    blob.Properties.ContentType = file.ContentType;
                    var image = new System.Drawing.Bitmap(file.InputStream);
                    if (image != null)
                    {
                        blob.Metadata.Add("Width", image.Width.ToString());
                        blob.Metadata.Add("Height", image.Height.ToString());
                    }

                    blob.UploadFromStream(file.InputStream);
                    photo.BlobReference = file.FileName;
                }
                else
                {
                    this.ModelState.AddModelError("File", new ArgumentNullException("file"));
                    return this.View(photoViewModel);
                }

                //Save information to Table Storage
                var token = Public ? this.PublicTableSas : this.AuthenticatedTableSas;
                if (!this.User.Identity.IsAuthenticated)
                {
                    token = this.PublicTableSas;
                    photo.PartitionKey = "Public";
                }

                CloudTableClient cloudTableClient = new CloudTableClient(this.UriTable, new StorageCredentials(token));
                var photoContext = new PhotoDataServiceContext(cloudTableClient);

                photoContext.AddPhoto(photo);

                try
                {
                    //Send create notification
                    var msg = new CloudQueueMessage(string.Format("Photo Uploaded,{0}", photo.BlobReference));
                    this.GetCloudQueue().AddMessage(msg);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Trace.TraceInformation("Error", "Couldn't send notification");
                }

                return this.RedirectToAction("Index");
            }

            return this.View();
        }
        public ActionResult Create(PhotoViewModel photoViewModel, HttpPostedFileBase file, bool Public, FormCollection collection)
        {
            if (this.ModelState.IsValid)
            {
                photoViewModel.PartitionKey = Public ? "Public" : this.User.Identity.Name;
                var photo = this.FromViewModel(photoViewModel);

                if (file != null)
                {
                    //Save file stream to Blob Storage
                    var blob = this.GetBlobContainer().GetBlockBlobReference(file.FileName);
                    blob.Properties.ContentType = file.ContentType;
                    blob.UploadFromStream(file.InputStream);
                    photo.BlobReference = file.FileName;
                }
                else
                {
                    this.ModelState.AddModelError("File", new ArgumentNullException("file"));
                    return this.View(photoViewModel);
                }

                //Save information to Table Storage
                var token = Public ? this.PublicTableSas : this.AuthenticatedTableSas;
                if (!this.User.Identity.IsAuthenticated)
                {
                    token = this.PublicTableSas;
                    photo.PartitionKey = "Public";
                }

                CloudTableClient cloudTableClient = new CloudTableClient(this.UriTable, new StorageCredentials(token));
                var photoContext = new PhotoDataServiceContext(cloudTableClient);

                photoContext.AddPhoto(photo);

                //Send create notification
                var msg = new CloudQueueMessage("Photo Uploaded");
                this.GetCloudQueue().AddMessage(msg);

                return this.RedirectToAction("Index");
            }

            return this.View();
        }
        public ActionResult Create(PhotoViewModel photoViewModel, HttpPostedFileBase file, FormCollection collection)
        {
            if (this.ModelState.IsValid)
            {
                photoViewModel.PartitionKey = this.User.Identity.IsAuthenticated ? this.User.Identity.Name : "Public";
                var photo = this.FromViewModel(photoViewModel);

                if (file != null)
                {
                    //Save file stream to Blob Storage
                    var blob = this.GetBlobContainer().GetBlockBlobReference(file.FileName);
                    blob.Properties.ContentType = file.ContentType;
                    blob.UploadFromStream(file.InputStream);
                    photo.BlobReference = file.FileName;
                }
                else
                {
                    this.ModelState.AddModelError("File", new ArgumentNullException("file"));
                    return this.View(photoViewModel);
                }

                //Save information to Table Storage
                CloudTableClient cloudTableClient = this.StorageAccount.CreateCloudTableClient();
                var photoContext = new PhotoDataServiceContext(cloudTableClient);
                photoContext.AddPhoto(photo);

                try
                {
                    //Send create notification
                    var msg = new CloudQueueMessage("Photo Uploaded");
                    this.GetCloudQueue().AddMessage(msg);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Trace.TraceInformation("Error", "Couldn't send notification");
                }

                return this.RedirectToAction("Index");
            }

            return this.View();
        }
        public ActionResult Create(PhotoViewModel photoViewModel, HttpPostedFileBase file, FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                var photo = FromViewModel(photoViewModel);

                // Upload blob
                if (file != null)
                {
                    var blob = GetBlobContainer().GetBlockBlobReference(file.FileName);
                    blob.Properties.ContentType = file.ContentType;
                    blob.UploadFromStream(file.InputStream);
                    photo.BlobReference = file.FileName;
                }
                else
                {
                    ModelState.AddModelError("File", new ArgumentNullException("file"));
                    return View(photoViewModel);
                }

                // Insert table entry
                photo.PartitionKey = User.Identity.IsAuthenticated ? User.Identity.Name : "Public";
                var cloudTableClient = this.storageAccount.CreateCloudTableClient();
                var photoContext = new PhotoDataServiceContext(cloudTableClient);
                photoContext.AddPhoto(photo);

                // Send create notification
                try
                {
                    var msg = new CloudQueueMessage("Photo Uploaded");
                    GetCloudQueue().AddMessage(msg);
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Failed to send notification: {0}", ex.Message);
                }

                return RedirectToAction("Index");
            }

            return View();
        }
        public ActionResult ToPublic(string partitionKey, string rowKey)
        {
            CloudTableClient cloudTableClient = new CloudTableClient(this.UriTable, new StorageCredentials(this.AuthenticatedTableSas));
            var photoContext = new PhotoDataServiceContext(cloudTableClient);
            var photo = photoContext.GetById(partitionKey, rowKey);
            if (photo == null)
            {
                return this.HttpNotFound();
            }

            photoContext.DeletePhoto(photo);

            cloudTableClient = new CloudTableClient(this.UriTable, new StorageCredentials(this.PublicTableSas));
            photoContext = new PhotoDataServiceContext(cloudTableClient);
            photo.PartitionKey = "Public";
            photoContext.AddPhoto(photo);

            return RedirectToAction("Index");
        }