/// <summary> /// Implementation of <see cref="IProductCommands.AddProductTierPrice(Guid, int, int, Currency)"/> /// </summary> /// <param name="productId">The product id</param> /// <param name="fromQuantity">The start quantity</param> /// <param name="toQuantity">The end quantity</param> /// <param name="price">The price value</param> /// <returns></returns> public virtual async Task AddProductTierPrice(Guid productId, int fromQuantity, int toQuantity, Currency price) { try { if (productId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(productId)); } var product = await Repository.GetByKeyAsync <Product>(productId); if (!product.TierPriceEnabled) { product.EnableTierPrices(); } product.AddTierPrice(fromQuantity, toQuantity, price); await Repository.SaveChangesAsync(); var @event = new ProductTierPriceAddedEvent(productId, fromQuantity, toQuantity, price); EventBus.RaiseEvent(@event); } catch { throw; } }
public void Handle(ProductTierPriceAddedEvent @event) { try { EventStore.Save(@event); } catch { throw; } }
public void ProductTierPriceAddedEvent_Ctor_Should_Set_Arguments_Correctly() { Guid productId = Guid.NewGuid(); int fromQuantity = 1; int toQuantity = 5; Currency price = new Currency { Amount = 10, Code = "EUR" }; var @event = new ProductTierPriceAddedEvent(productId, fromQuantity, toQuantity, price); Assert.Equal(productId, @event.ProductId); 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); }
public async Task AddProductTierPrice(Guid productId, int fromQuantity, int toQuantity, Currency price) { try { var product = await Repository.GetByKeyAsync <Product>(productId); if (!product.TierPriceEnabled) { product.EnableTierPrices(); } product.AddTierPrice(fromQuantity, toQuantity, price); await Repository.SaveChangesAsync(); var @event = new ProductTierPriceAddedEvent(productId, fromQuantity, toQuantity, price); EventBus.RaiseEvent(@event); } catch { throw; } }