public void Handle(ProductImageAddedEvent @event) { try { EventStore.Save(@event); } catch { throw; } }
public void ProductImageAddedEvent_Ctor_Should_Set_Arguments_Correctly() { Guid productId = Guid.NewGuid(); string name = "image"; string originalName = "original"; var @event = new ProductImageAddedEvent(productId, name, originalName); Assert.Equal(productId, @event.ProductId); Assert.Equal(name, @event.Name); Assert.Equal(originalName, @event.OriginalName); Assert.Equal(productId, @event.AggregateId); Assert.Equal(typeof(Catalog.Models.Product), @event.AggregateType); }
public async Task AddProductImage(Guid productId, string path, string name, string originalName, bool isMain, DateTime uploadedOn) { try { var product = await Repository.GetByKeyAsync <Product>(productId); product.AddImage(path, name, originalName, isMain, uploadedOn); await Repository.SaveChangesAsync(); var @event = new ProductImageAddedEvent(productId, name, originalName); EventBus.RaiseEvent(@event); } catch { throw; } }
/// <summary> /// Implementation of <see cref="IProductCommands.AddProductImage(Guid, string, string, string, bool, DateTime)"/> /// </summary> /// <param name="productId">The product id</param> /// <param name="path">The file path</param> /// <param name="name">The file name</param> /// <param name="originalName">The file original name</param> /// <param name="isMain">Whether is the main image for the product</param> /// <param name="uploadedOn">The date and time of when the image is uploaded</param> /// <returns></returns> public virtual async Task AddProductImage(Guid productId, string path, string name, string originalName, bool isMain, DateTime uploadedOn) { try { if (productId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(productId)); } var product = await Repository.GetByKeyAsync <Product>(productId); product.AddImage(path, name, originalName, isMain, uploadedOn); await Repository.SaveChangesAsync(); var @event = new ProductImageAddedEvent(productId, name, originalName); EventBus.RaiseEvent(@event); } catch { throw; } }