/// <summary> /// Implementation of <see cref="IProductCommands.RemoveProductImage(Guid, Guid)"/> /// </summary> /// <param name="productId">The product id</param> /// <param name="imageId">The image id</param> /// <returns></returns> public virtual async Task RemoveProductImage(Guid productId, Guid imageId) { try { if (productId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(productId)); } if (imageId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(imageId)); } var product = await Repository.GetByKeyAsync <Product>(productId); product.DeleteImage(imageId); await Repository.SaveChangesAsync(); var @event = new ProductImageRemovedEvent(productId, imageId); EventBus.RaiseEvent(@event); } catch { throw; } }
public void Handle(ProductImageRemovedEvent @event) { try { EventStore.Save(@event); } catch { throw; } }
public void ProductImageRemovedEvent_Ctor_Should_Set_Arguments_Correctly() { Guid productId = Guid.NewGuid(); Guid imageId = Guid.NewGuid(); var @event = new ProductImageRemovedEvent(productId, imageId); Assert.Equal(productId, @event.ProductId); Assert.Equal(imageId, @event.ImageId); Assert.Equal(productId, @event.AggregateId); Assert.Equal(typeof(Catalog.Models.Product), @event.AggregateType); }
public async Task RemoveProductImage(Guid productId, Guid imageId) { try { var product = await Repository.GetByKeyAsync <Product>(productId); product.DeleteImage(imageId); await Repository.SaveChangesAsync(); var @event = new ProductImageRemovedEvent(productId, imageId); EventBus.RaiseEvent(@event); } catch { throw; } }