コード例 #1
0
 /// <summary>
 /// <see cref="IHandleEvent{TEvent}.Handle(TEvent)"/>
 /// </summary>
 /// <param name="event"></param>
 public void Handle(ProductMainCategoryChangedEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }
コード例 #2
0
        public void ProductMainCategoryChangedEvent_Ctor_Should_Set_Arguments_Correctly()
        {
            Guid productId  = Guid.NewGuid();
            Guid categoryId = Guid.NewGuid();

            var @event = new ProductMainCategoryChangedEvent(productId, categoryId);

            Assert.Equal(productId, @event.ProductId);
            Assert.Equal(categoryId, @event.CategoryId);

            Assert.Equal(productId, @event.AggregateId);
            Assert.Equal(typeof(Catalog.Models.Product), @event.AggregateType);
        }
コード例 #3
0
        /// <summary>
        /// Implementation of <see cref="IProductCommands.ChangeProductMainCategory(Guid, Guid)"/>
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public async Task ChangeProductMainCategory(Guid productId, Guid categoryId)
        {
            try
            {
                if (productId == Guid.Empty)
                {
                    throw new ArgumentException("value cannot be empty", nameof(productId));
                }

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

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

                var category = await Repository.GetByKeyAsync <Category>(categoryId);

                var currentMainCategory = product.MainCategory;
                if (currentMainCategory != null)
                {
                    product.RemoveCategory(currentMainCategory);
                }

                product.AddMainCategory(category);

                var @event = new ProductMainCategoryChangedEvent(productId, categoryId);
                EventBus.RaiseEvent(@event);

                await Repository.SaveChangesAsync();
            }
            catch
            {
                throw;
            }
        }