예제 #1
0
        /// <summary>
        /// Deletes the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="personId">The person identifier.</param>
        /// <returns></returns>
        public override bool Delete(BinaryFile item, int?personId)
        {
            // if we can determine the StorageProvider, use the provider to remove the file from the provider's external storage medium
            Rock.Storage.ProviderComponent storageProvider = DetermineBinaryFileStorageProvider(item);

            if (storageProvider != null)
            {
                storageProvider.RemoveFile(item, HttpContext.Current);
            }

            // delete the record from the database
            return(base.Delete(item, personId));
        }
예제 #2
0
        /// <summary>
        /// Saves the specified <see cref="Rock.Model.BinaryFile"/>.
        /// </summary>
        /// <param name="item">A <see cref="Rock.Model.BinaryFile"/> to save.</param>
        /// <param name="personId">A <see cref="System.Int32"/> representing the PersonId of the <see cref="Rock.Model.Person"/> who is saving the BinaryFile..</param>
        /// <returns></returns>
        public override bool Save(BinaryFile item, int?personId)
        {
            item.LastModifiedDateTime = DateTime.Now;
            Rock.Storage.ProviderComponent storageProvider = DetermineBinaryFileStorageProvider(item);

            if (storageProvider != null)
            {
                //// if this file is getting replaced, and we can determine the StorageProvider, use the provider to get and remove the file from the provider's
                //// external storage medium before we save it again. This especially important in cases where the provider for this filetype has changed
                //// since it was last saved

                // first get the FileContent from the old/current fileprovider in case we need to save it somewhere else
                item.Data         = item.Data ?? new BinaryFileData();
                item.Data.Content = storageProvider.GetFileContent(item, HttpContext.Current);

                // now, remove it from the old/current fileprovider
                storageProvider.RemoveFile(item, HttpContext.Current);
            }

            // when a file is saved (unless it is getting Deleted/Saved), it should use the StoredEntityType that is associated with the BinaryFileType
            if (item.BinaryFileType != null)
            {
                // make sure that it updated to use the same storage as specified by the BinaryFileType
                if (item.StorageEntityTypeId != item.BinaryFileType.StorageEntityTypeId)
                {
                    item.SetStorageEntityTypeId(item.BinaryFileType.StorageEntityTypeId);
                    storageProvider = DetermineBinaryFileStorageProvider(item);
                }
            }

            if (storageProvider != null)
            {
                // save the file to the provider's new storage medium
                storageProvider.SaveFile(item, HttpContext.Current);
            }

            return(base.Save(item, personId));
        }