/// <summary> /// Implementation of <see cref="IProductCommands.ChangeProductTierPrice(Guid, Guid, int, int, Currency)"/> /// </summary> /// <param name="productId">The product id</param> /// <param name="tierPriceId">The tier price id</param> /// <param name="fromQuantity">The new starting quantity</param> /// <param name="toQuantity">The new ending quantity</param> /// <param name="price">The new price</param> /// <returns></returns> public virtual async Task ChangeProductTierPrice(Guid productId, Guid tierPriceId, int fromQuantity, int toQuantity, Currency price) { try { if (productId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(productId)); } if (tierPriceId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(tierPriceId)); } var product = await Repository.GetByKeyAsync <Product>(productId); product.ChangeTierPrice(tierPriceId, fromQuantity, toQuantity, price); await Repository.SaveChangesAsync(); var @event = new ProductTierPriceChangedEvent(productId, tierPriceId, fromQuantity, toQuantity, price); EventBus.RaiseEvent(@event); } catch { throw; } }
public void Handle(ProductTierPriceChangedEvent @event) { try { EventStore.Save(@event); } catch { throw; } }
public async Task ChangeProductTierPrice(Guid productId, Guid tierPriceId, int fromQuantity, int toQuantity, Currency price) { try { var product = await Repository.GetByKeyAsync <Product>(productId); product.ChangeTierPrice(tierPriceId, fromQuantity, toQuantity, price); await Repository.SaveChangesAsync(); var @event = new ProductTierPriceChangedEvent(productId, tierPriceId, fromQuantity, toQuantity, price); EventBus.RaiseEvent(@event); } catch { throw; } }
public void ProductTierPriceChangedEvent_Ctor_Should_Set_Arguments_Correctly() { Guid productId = Guid.NewGuid(); Guid tierPriceId = Guid.NewGuid(); int fromQuantity = 1; int toQuantity = 5; Currency price = new Currency { Amount = 10, Code = "EUR" }; var @event = new ProductTierPriceChangedEvent(productId, tierPriceId, fromQuantity, toQuantity, price); Assert.Equal(productId, @event.ProductId); Assert.Equal(tierPriceId, @event.TierPriceId); Assert.Equal(fromQuantity, @event.FromQuantity); Assert.Equal(toQuantity, @event.ToQuantity); Assert.Equal(price, @event.Price); Assert.Equal(productId, @event.AggregateId); Assert.Equal(typeof(Catalog.Models.Product), @event.AggregateType); }