/// <summary> /// Delete ALL records/blobs for an object in one particular format /// </summary> public static DataAccessResponseType DeleteImageRecordForObject(Account account, string imageFormatGroupTypeNameKey, string objectId, string imageGroupNameKey, string imageFormatNameKey) { //Get the record (so we can loop through blobs for deletion) var imageRecords = ImageRecordsManager.GetImageRecordsForObject(account.AccountID.ToString(), account.StoragePartition, account.AccountNameKey, imageFormatGroupTypeNameKey, objectId); //Delete all Blobs associated with ALL image records (loop if gallery) foreach (ImageRecordGroupModel group in imageRecords) { if (group.GroupNameKey == imageGroupNameKey) { foreach (ImageRecordModel record in group.ImageRecords) { if (record.FormatNameKey == imageFormatNameKey) { if (record.Type == "single") { ImageStorageManager.DeleteImageBlobs(account.StoragePartition, record.ContainerName, record.BlobPath); } else { foreach (ImageRecordGalleryModel galleryRecord in record.GalleryImages) { ImageStorageManager.DeleteImageBlobs(account.StoragePartition, record.ContainerName, galleryRecord.BlobPath); } } } } } } //Can also be used to clear ALL images in a gallery record return(Internal.ImageRecordTableStorage.DeleteImageRecord(account.AccountID.ToString(), account.StoragePartition, imageFormatGroupTypeNameKey, objectId, imageGroupNameKey, imageFormatNameKey)); }
public static DataAccessResponseType DeleteGalleryImage(Account account, string imageFormatGroupTypeNameKey, string objectId, string imageGroupNameKey, string imageFormatNameKey, int imageIndex) { //Get the records (so we can loop through blobs for deletion) var imageRecords = ImageRecordsManager.GetImageRecordsForObject(account.AccountID.ToString(), account.StoragePartition, account.AccountNameKey, imageFormatGroupTypeNameKey, objectId); ImageRecordModel imageRecord = null; #region Get the record associated with the gallery deletion request //Delete all Blobs associated with ALL image records (loop if gallery) foreach (ImageRecordGroupModel group in imageRecords) { if (group.GroupNameKey == imageGroupNameKey) { foreach (ImageRecordModel record in group.ImageRecords) { if (record.FormatNameKey == imageFormatNameKey) { if (record.Type != "gallery") { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "This image record is not a gallery" }); } else { //Assign to the record object imageRecord = record; ImageStorageManager.DeleteImageBlobs(account.StoragePartition, record.ContainerName, record.GalleryImages[imageIndex].BlobPath); } } } } } #endregion //if this is the only image in the gallery we delete the entire record if (imageRecord.GalleryImages.Count <= 1) { //This is the last image so we delete the ENTIRE record return(Internal.ImageRecordTableStorage.DeleteImageRecord(account.AccountID.ToString(), account.StoragePartition, imageFormatGroupTypeNameKey, objectId, imageGroupNameKey, imageFormatNameKey)); } else { //Update record to remove the array index on ALL comma deliminated records return(Internal.ImageRecordTableStorage.DeleteImageGalleryRecordItem(account.AccountID.ToString(), account.StoragePartition, imageFormatGroupTypeNameKey, objectId, imageGroupNameKey, imageFormatNameKey, imageIndex)); } }