public async Task <DefaultResult> Handle(DeleteProductImageCommand command, CancellationToken cancellationToken)
        {
            var result = new DefaultResult();

            var productImage = await _productImageRepository.FindAsync(x => x.Id == command.Id);

            if (productImage == null)
            {
                Notifications.Handle("Imagem de produto não encontrado");
                return(null);
            }

            _productImageRepository.Remove(productImage);

            if (!await CommitAsync())
            {
                return(result);
            }

            return(result);
        }
        public async Task HandleAsync(DeleteProductImageCommand command, CancellationToken cancellationToken = default)
        {
            var aggregateProduct = await _repo.GetAsync(command.Id, cancellationToken : cancellationToken);

            if (aggregateProduct == null)
            {
                throw new CannotFindException("No data on this Id");
            }

            var cloudinary = new CloudinaryImageUploader();
            var result     = await cloudinary.DeleteByTag(command.PublicId) as DelResResult;

            if (result?.DeletedCounts?.Count > 0)
            {
                aggregateProduct.DeleteProductImage(command);
                await _repo.SaveAsync(aggregateProduct, cancellationToken);
            }
            else
            {
                throw new Exception($"Can not find images: {result}");
            }
        }
Example #3
0
 public Task HandleAsync(DeleteProductImageCommand command)
 {
     return(_writeRepository.DeleteImageAsync(command.ImageId));
 }
Example #4
0
 public void DeleteProductImage(DeleteProductImageCommand command)
 {
     ApplyChange(new DeletedProductImageEvent(command.PublicId, this, command));
 }
 public async Task <ActionResult> DeleteProductImage([FromRoute] DeleteProductImageCommand productImage)
 {
     throw new NotImplementedException();
 }
Example #6
0
 public async Task <IProcessResult> Delete(DeleteProductImageCommand command) => await mediator.Send(command);
        public async Task <IActionResult> RemoveProductImage([FromBody] DeleteProductImageCommand command)
        {
            await _commandSender.SendAsync(command);

            return(Ok());
        }
        public async Task <IActionResult> DeleteProductImageAsync([FromBody] DeleteProductImageCommand command)
        {
            await Mediator.SendAsync(command).ConfigureAwait(false);

            return(Ok());
        }