/// <summary>
        /// Implementation of <see cref="IProductCommands.AddAttributeToProduct(Guid, Guid, object)"/>
        /// </summary>
        /// <param name="productId">The product id</param>
        /// <param name="attributeId">The attribute id</param>
        /// <param name="value">The attribute value</param>
        /// <returns></returns>
        public virtual async Task AddAttributeToProduct(Guid productId, Guid attributeId, object value)
        {
            try
            {
                if (productId == Guid.Empty)
                {
                    throw new ArgumentException("value cannot be empty", nameof(productId));
                }

                if (attributeId == Guid.Empty)
                {
                    throw new ArgumentException("value cannot be empty", nameof(attributeId));
                }

                var product = await Repository.GetByKeyAsync <Product>(productId);

                var attribute = await Repository.GetByKeyAsync <CustomAttribute>(attributeId);

                product.AddAttribute(attribute, value);

                await Repository.SaveChangesAsync();

                var @event = new ProductAttributeAddedEvent(productId, attributeId, value);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }
Пример #2
0
 public void Handle(ProductAttributeAddedEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }
Пример #3
0
        public void ProductAttributeAddedEvent_Ctor_Should_Set_Arguments_Correctly()
        {
            Guid   productId   = Guid.NewGuid();
            Guid   attributeId = Guid.NewGuid();
            object value       = "123";

            var @event = new ProductAttributeAddedEvent(productId, attributeId, value);

            Assert.Equal(productId, @event.ProductId);
            Assert.Equal(attributeId, @event.AttributeId);
            Assert.Equal(value, @event.Value);

            Assert.Equal(productId, @event.AggregateId);
            Assert.Equal(typeof(Catalog.Models.Product), @event.AggregateType);
        }
Пример #4
0
        public async Task AddAttributeToProduct(Guid productId, Guid attributeId, object value)
        {
            try
            {
                var product = await Repository.GetByKeyAsync <Product>(productId);

                var attribute = await Repository.GetByKeyAsync <CustomAttribute>(attributeId);

                product.AddAttribute(attribute, value);

                await Repository.SaveChangesAsync();

                var @event = new ProductAttributeAddedEvent(productId, attributeId, value);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }