/// <summary> /// Implementation of <see cref="IProductCommands.SetProductVendor(Guid, Guid)"/> /// </summary> /// <param name="productId">The product id</param> /// <param name="brandId">The vendor id</param> /// <returns></returns> public virtual async Task SetProductVendor(Guid productId, Guid brandId) { try { if (productId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(productId)); } if (brandId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(brandId)); } var product = await Repository.GetByKeyAsync <Product>(productId); var brand = await Repository.GetByKeyAsync <Brand>(brandId); product.SetVendor(brand); await Repository.SaveChangesAsync(); var @event = new ProductVendorSetEvent(productId, brandId); EventBus.RaiseEvent(@event); } catch { throw; } }
public void Handle(ProductVendorSetEvent @event) { try { EventStore.Save(@event); } catch { throw; } }
public void ProductVendorSetEvent_Ctor_Should_Set_Arguments_Correctly() { Guid productId = Guid.NewGuid(); Guid vendorId = Guid.NewGuid(); var @event = new ProductVendorSetEvent(productId, vendorId); Assert.Equal(productId, @event.ProductId); Assert.Equal(vendorId, @event.VendorId); Assert.Equal(productId, @event.AggregateId); Assert.Equal(typeof(Catalog.Models.Product), @event.AggregateType); }
public async Task SetProductVendor(Guid productId, Guid brandId) { try { var product = await Repository.GetByKeyAsync <Product>(productId); var brand = await Repository.GetByKeyAsync <Brand>(brandId); product.SetVendor(brand); await Repository.SaveChangesAsync(); var @event = new ProductVendorSetEvent(productId, brandId); EventBus.RaiseEvent(@event); } catch { throw; } }