コード例 #1
0
        /// <summary>
        /// Implementation of <see cref="IProductCommands.RemoveProductAttribute(Guid, Guid)"/>
        /// </summary>
        /// <param name="productId">The product id</param>
        /// <param name="attributeId">The attribute id</param>
        /// <returns></returns>
        public virtual async Task RemoveProductAttribute(Guid productId, Guid attributeId)
        {
            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.DeleteAttribute(attribute);

                await Repository.SaveChangesAsync();

                var @event = new ProductAttributeRemovedEvent(productId, attributeId);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }
コード例 #2
0
 public void Handle(ProductAttributeRemovedEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }
        public void ProductAttributeRemovedEvent_Ctor_Should_Set_Arguments_Correctly()
        {
            Guid productId   = Guid.NewGuid();
            Guid attributeId = Guid.NewGuid();

            var @event = new ProductAttributeRemovedEvent(productId, attributeId);

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

            Assert.Equal(productId, @event.AggregateId);
            Assert.Equal(typeof(Catalog.Models.Product), @event.AggregateType);
        }
コード例 #4
0
        public async Task RemoveProductAttribute(Guid productId, Guid attributeId)
        {
            try
            {
                var product = await Repository.GetByKeyAsync <Product>(productId);

                product.DeleteAttribute(attributeId);

                await Repository.SaveChangesAsync();

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