// // GET: /Home/Delete/5 public ActionResult Delete(string partitionKey, string rowKey) { string token = partitionKey == "Public" ? this.PublicTableSas : this.AuthenticatedTableSas; CloudTableClient cloudTableClient = new CloudTableClient(this.UriTable, new StorageCredentials(token)); var photoContext = new PhotoDataServiceContext(cloudTableClient); PhotoEntity photo = photoContext.GetById(partitionKey, rowKey); if (photo == null) { return this.HttpNotFound(); } var viewModel = this.ToViewModel(photo); if (!string.IsNullOrEmpty(photo.BlobReference)) { viewModel.Uri = this.GetBlobContainer().GetBlockBlobReference(photo.BlobReference).Uri.ToString(); } return this.View(viewModel); }
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"); }
public ActionResult DeleteConfirmed(string partitionKey, string rowKey) { var token = partitionKey == "Public" ? this.PublicTableSas : this.AuthenticatedTableSas; CloudTableClient cloudTableClient = new CloudTableClient(this.UriTable, new StorageCredentials(this.PublicTableSas)); var photoContext = new PhotoDataServiceContext(cloudTableClient); PhotoEntity photo = photoContext.GetById(partitionKey, rowKey); photoContext.DeletePhoto(photo); //Deletes the Image from Blob Storage if (!string.IsNullOrEmpty(photo.BlobReference)) { var blob = this.GetBlobContainer().GetBlockBlobReference(photo.BlobReference); blob.DeleteIfExists(); } //Send delete notification var msg = new CloudQueueMessage("Photo Deleted"); this.GetCloudQueue().AddMessage(msg); return this.RedirectToAction("Index"); }
public ActionResult Share(string partitionKey, string rowKey) { var cloudTableClient = new CloudTableClient(this.UriTable, new StorageCredentials(this.AuthenticatedTableSas)); var photoContext = new PhotoDataServiceContext(cloudTableClient); PhotoEntity photo = photoContext.GetById(partitionKey, rowKey); if (photo == null) { return this.HttpNotFound(); } string sas = string.Empty; if (!string.IsNullOrEmpty(photo.BlobReference)) { CloudBlockBlob blobBlockReference = this.GetBlobContainer().GetBlockBlobReference(photo.BlobReference); sas = photoContext.GetSasForBlob(blobBlockReference, SharedAccessBlobPermissions.Read); } if (!string.IsNullOrEmpty(sas)) { return View("Share", null, sas); } return RedirectToAction("Index"); }
// // GET: /Home/Delete/5 public ActionResult Delete(string partitionKey, string rowKey) { CloudTableClient cloudTableClient = this.StorageAccount.CreateCloudTableClient(); var photoContext = new PhotoDataServiceContext(cloudTableClient); PhotoEntity photo = photoContext.GetById(partitionKey, rowKey); if (photo == null) { return this.HttpNotFound(); } var viewModel = this.ToViewModel(photo); if (!string.IsNullOrEmpty(photo.BlobReference)) { viewModel.Uri = this.GetBlobContainer().GetBlockBlobReference(photo.BlobReference).Uri.ToString(); } return this.View(viewModel); }
public ActionResult DeleteConfirmed(string partitionKey, string rowKey) { if (ModelState.IsValid) { string token = partitionKey == "Public" ? this.PublicTableSas : this.AuthenticatedTableSas; CloudTableClient cloudTableClient = new CloudTableClient(this.UriTable, new StorageCredentials(token)); var photoContext = new PhotoDataServiceContext(cloudTableClient); PhotoEntity photo = photoContext.GetById(partitionKey, rowKey); if (photo == null) { return this.HttpNotFound(); } photoContext.DeletePhoto(photo); //Deletes the Image from Blob Storage if (!string.IsNullOrEmpty(photo.BlobReference)) { var blob = this.GetBlobContainer().GetBlockBlobReference(photo.BlobReference); blob.DeleteIfExists(); } try { //Send delete notification var msg = new CloudQueueMessage(string.Format("Photo Deleted,{0}", photo.BlobReference)); this.GetCloudQueue().AddMessage(msg); } catch (Exception e) { System.Diagnostics.Trace.TraceInformation("Error", "Couldn't send notification"); } } return this.RedirectToAction("Index"); }
public ActionResult DeleteConfirmed(string partitionKey, string rowKey) { CloudTableClient cloudTableClient = this.StorageAccount.CreateCloudTableClient(); var photoContext = new PhotoDataServiceContext(cloudTableClient); PhotoEntity photo = photoContext.GetById(partitionKey, rowKey); photoContext.DeletePhoto(photo); //Deletes the Image from Blob Storage if (!string.IsNullOrEmpty(photo.BlobReference)) { var blob = this.GetBlobContainer().GetBlockBlobReference(photo.BlobReference); blob.DeleteIfExists(); } try { //Send delete notification var msg = new CloudQueueMessage("Photo Deleted"); this.GetCloudQueue().AddMessage(msg); } catch (Exception e) { System.Diagnostics.Trace.TraceInformation("Error", "Couldn't send notification"); } return this.RedirectToAction("Index"); }
public ActionResult Delete(string id) { this.RefreshAccessCredentials(); CloudTableClient cloudTableClient = new CloudTableClient(this.Uri, new StorageCredentials(Session["Sas"].ToString())); var photoContext = new PhotoDataServiceContext(cloudTableClient); PhotoEntity photo = photoContext.GetById("Public", id); if (photo == null) { photo = photoContext.GetById(this.User.Identity.Name, id); if (photo == null) { return this.HttpNotFound(); } } var viewModel = this.ToViewModel(photo); if (!string.IsNullOrEmpty(photo.BlobReference)) { viewModel.Uri = this.GetBlobContainer().GetBlockBlobReference(photo.BlobReference).Uri.ToString(); } return this.View(viewModel); }
public ActionResult DeleteConfirmed(string id) { this.RefreshAccessCredentials(); //Delete information From Table Storage CloudTableClient cloudTableClient = new CloudTableClient(this.Uri, new StorageCredentials(Session["Sas"].ToString())); var photoContext = new PhotoDataServiceContext(cloudTableClient); PhotoEntity photo = photoContext.GetById("Public", id); if (photo == null) { photo = photoContext.GetById(this.User.Identity.Name, id); if (photo == null) { return this.HttpNotFound(); } } photoContext.DeletePhoto(photo); //Deletes the Image from Blob Storage if (!string.IsNullOrEmpty(photo.BlobReference)) { var blob = this.GetBlobContainer().GetBlockBlobReference(photo.BlobReference); blob.DeleteIfExists(); } //Send delete notification var msg = new CloudQueueMessage("Photo Deleted"); this.GetCloudQueue().AddMessage(msg); return this.RedirectToAction("Index"); }
// // GET: /Home/Delete/5 public ActionResult Delete(string partitionKey, string rowKey) { var cloudTableClient = this.storageAccount.CreateCloudTableClient(); var photoContext = new PhotoDataServiceContext(cloudTableClient); PhotoEntity photo = photoContext.GetById(partitionKey, rowKey); if (photo == null) { return HttpNotFound(); } var viewModel = ToViewModel(photo); if (!String.IsNullOrEmpty(photo.BlobReference)) { viewModel.Uri = GetBlobContainer().GetBlockBlobReference(photo.BlobReference).Uri.ToString(); } // Send create notification try { var msg = new CloudQueueMessage("Photo Deleted"); GetCloudQueue().AddMessage(msg); } catch (Exception ex) { Trace.TraceError("Failed to send notification: {0}", ex.Message); } return View(viewModel); }
public ActionResult DeleteConfirmed(string partitionKey, string rowKey) { var cloudTableClient = this.storageAccount.CreateCloudTableClient(); var photoContext = new PhotoDataServiceContext(cloudTableClient); var photo = photoContext.GetById(partitionKey, rowKey); photoContext.DeletePhoto(photo); if (!String.IsNullOrEmpty(photo.BlobReference)) { var blob = GetBlobContainer().GetBlockBlobReference(photo.BlobReference); blob.DeleteIfExists(); } return RedirectToAction("Index"); }