public async Task HandleAsync(AddProductImageCommand 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 imageUploader = new CloudinaryImageUploader(); foreach (var imageString in command.ImagesString) { var bytesImg = Convert.FromBase64String(imageString.Substring(imageString.IndexOf(',') + 1)); var img = await imageUploader.Upload(Guid.NewGuid().ToString(), bytesImg, 500, 450); command.Images.Add(new Image() { ImageUrl = img.SecureUrl.AbsoluteUri }); } aggregateProduct.AddProductImage(command); await _repo.SaveAsync(aggregateProduct, cancellationToken); }
public Task HandleAsync(AddProductImageCommand command) { return(_writeRepository.AddImagesAsync(command.ProductImages)); }
public void AddProductImage(AddProductImageCommand command) { ApplyChange(new AddedProductImageEvent(command.Images, this, command)); }
public async Task <IActionResult> AddProductImages([FromBody] AddProductImageCommand command) { await _commandSender.SendAsync(command); return(Ok()); }
public async Task <IActionResult> AddProductImageAsync([FromBody] AddProductImageCommand command) { await Mediator.SendAsync(command).ConfigureAwait(false); return(Ok()); }