Esempio n. 1
0
        public async Task <ICommandResult <File> > DeleteAsync(File model)
        {
            // Validate
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            // Invoke FileDeleting subscriptions
            foreach (var handler in _broker.Pub <File>(this, "FileDeleting"))
            {
                model = await handler.Invoke(new Message <File>(model, this));
            }

            var result = new CommandResult <File>();

            if (await _fileStore.DeleteAsync(model))
            {
                // Invoke FileDeleted subscriptions
                foreach (var handler in _broker.Pub <File>(this, "FileDeleted"))
                {
                    model = await handler.Invoke(new Message <File>(model, this));
                }

                // Return success
                return(result.Success(model));
            }

            return(result.Failed(new CommandError("An unknown error occurred whilst attempting to delete the file")));
        }
        private async Task DeleteUploadedImageAsync(MediaItem mediaItem)
        {
            MediaItemStorageLocation storageLocation = mediaItem.StorageLocations.First();

            Logger.LogMessage("Deleting original uploaded image: {0}", storageLocation.Filename);
            await _fileStore.DeleteAsync(storageLocation);

            mediaItem.StorageLocations.Clear();
        }
Esempio n. 3
0
        public async Task <IActionResult> Delete([FromBody] int id)
        {
            // Validate
            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(id));
            }

            // Get authenticated user
            var user = await base.GetAuthenticatedUserAsync();

            // We need to be authenticated
            if (user == null)
            {
                return(base.UnauthorizedException());
            }

            // Get attachment
            var attachment = await _fileStore.GetByIdAsync(id);

            // Ensure attachment exists
            if (attachment == null)
            {
                return(NotFound());
            }

            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.DeleteOwnFiles))
            {
                return(Unauthorized());
            }

            // Delete attachment
            var success = await _fileStore.DeleteAsync(attachment);

            // Return result
            return(base.Result(success));
        }
Esempio n. 4
0
        public async Task DeleteAsync(MediaItem item)
        {
            item.Deleted     = true;
            item.LastUpdated = DateTime.UtcNow;

            // Delete the files from S3!
            List <Task> tasks = new List <Task>();

            foreach (var mediaItemStorageLocation in item.StorageLocations)
            {
                tasks.Add(_fileStore.DeleteAsync(mediaItemStorageLocation));
            }

            // Wait for all the delete requests.
            Task.WaitAll(tasks.ToArray(), 60000);

            //await SaveAsync(item);
            await _mediaRepository.DeleteAsync(item);

            RemoveMediaItemCache(item);

            await PublishMediaItemDeletedAsync(item);
        }