Ejemplo n.º 1
0
        public async Task On(MediaDeleted @event)
        {
            var feeds = (await GetAll()).Where(x => x.MediaId == @event.Id);

            foreach (var feed in feeds)
            {
                await Remove(feed);
            }
        }
        public async Task On(MediaDeleted @event)
        {
            await _dbConnection.Medias
            .Where(x => x.Id == @event.Id)
            .DeleteAsync();

            await _dbConnection.MediaFeeds
            .Where(x => x.MediaId == @event.Id)
            .DeleteAsync();
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> DeleteById(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_entityIndex.Exists(ResourceType.Media, id))
            {
                return(NotFound());
            }

            var status = _entityIndex.Status(ResourceType.Media, id).GetValueOrDefault();

            if (!UserPermissions.IsAllowedToDelete(User.Identity, status, _entityIndex.Owner(ResourceType.Media, id)))
            {
                return(Forbid());
            }

            if (!UserPermissions.IsAllowedToDelete(User.Identity, status, _entityIndex.Owner(ResourceType.Media, id)))
            {
                return(BadRequest(ErrorMessages.CannotBeDeleted(ResourceType.Media, id)));
            }

            if (status == ContentStatus.Published)
            {
                return(BadRequest(ErrorMessages.CannotBeDeleted(ResourceType.Media, id)));
            }

            if (_referencesIndex.IsUsed(ResourceType.Media, id))
            {
                return(BadRequest(ErrorMessages.ResourceInUse));
            }

            // Remove file
            var directoryPath = Path.GetDirectoryName(_mediaIndex.GetFilePath(id));

            if (directoryPath != null && Directory.Exists(directoryPath))
            {
                Directory.Delete(directoryPath, true);
            }

            var ev = new MediaDeleted
            {
                Id        = id,
                UserId    = User.Identity.GetUserIdentity(),
                Timestamp = DateTimeOffset.Now
            };

            await _eventStore.AppendEventAsync(ev);

            await InvalidateThumbnailCacheAsync(id);

            return(StatusCode(204));
        }
 protected virtual void OnMediaDeleted(IMedia media)
 {
     MediaDeleted?.Invoke(this, new MediaEventArgs(media));
 }
Ejemplo n.º 5
0
 //public void NewMediaAddedInvoke(object sender, ProfileMediaDTO neMedia) => NewMediaAdded.Invoke(sender, neMedia);
 public void MediaDeletedInvoke(object sender, ProfileMediaDTO deletedMedia) => MediaDeleted.Invoke(sender, deletedMedia);