/// <summary>
        /// Implementation of <see cref="IProductCommands.AddMainCategoryToProduct(Guid, Guid)"/>
        /// </summary>
        /// <param name="productId">The product id</param>
        /// <param name="categoryId">The category id</param>
        /// <returns></returns>
        public virtual async Task AddMainCategoryToProduct(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);

                product.AddMainCategory(category);

                await Repository.SaveChangesAsync();

                var @event = new ProductCategoryAddedEvent(productId, categoryId, true);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }
Exemple #2
0
 public void Handle(ProductCategoryAddedEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }
        public void ProductCategoryAddedEvent_Ctor_Should_Set_Arguments_Correctly()
        {
            Guid productId  = Guid.NewGuid();
            Guid categoryId = Guid.NewGuid();
            bool isMain     = true;

            var @event = new ProductCategoryAddedEvent(productId, categoryId, isMain);

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

            Assert.Equal(productId, @event.AggregateId);
            Assert.Equal(typeof(Catalog.Models.Product), @event.AggregateType);
        }
Exemple #4
0
        public async Task AddMainCategoryToProduct(Guid productId, Guid categoryId)
        {
            try
            {
                var product = await Repository.GetByKeyAsync <Product>(productId);

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

                product.AddMainCategory(category);

                await Repository.SaveChangesAsync();

                var @event = new ProductCategoryAddedEvent(productId, categoryId, true);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }