Example #1
0
        /// <summary>
        /// Implementation of <see cref="ICategoryCommands.SetParentForCategory(Guid, Guid)"/>
        /// </summary>
        /// <param name="categoryId">The category id</param>
        /// <param name="parentId">The parent category id</param>
        /// <returns></returns>
        public virtual async Task SetParentForCategory(Guid categoryId, Guid parentId)
        {
            try
            {
                if (categoryId == Guid.Empty)
                {
                    throw new ArgumentException("value cannot be empty", nameof(categoryId));
                }

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

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

                var parent = await Repository.GetByKeyAsync <Category>(parentId);

                category.SetParentCategory(parent);

                await Repository.SaveChangesAsync();

                var @event = new CategoryChildAddedEvent(parentId, categoryId);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }
 /// <summary>
 /// <see cref="IHandleEvent{TEvent}.Handle(TEvent)"/>
 /// </summary>
 /// <param name="event"></param>
 public void Handle(CategoryChildAddedEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }
        public void CategoryChildAddedEvent_Ctor_Should_Set_Arguments_Correctly()
        {
            Guid categoryId = Guid.NewGuid();
            Guid childId    = Guid.NewGuid();

            var @event = new CategoryChildAddedEvent(categoryId, childId);

            Assert.Equal(categoryId, @event.CategoryId);
            Assert.Equal(childId, @event.ChildId);

            Assert.Equal(categoryId, @event.AggregateId);
            Assert.Equal(typeof(Catalog.Models.Category), @event.AggregateType);
        }
Example #4
0
        public async Task AddCategoryChild(Guid categoryId, Guid childId)
        {
            try
            {
                var category = await Repository.GetByKeyAsync <Category>(categoryId);

                var child = await Repository.GetByKeyAsync <Category>(childId);

                category.AddChild(child);
                await Repository.SaveChangesAsync();

                var @event = new CategoryChildAddedEvent(categoryId, childId);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }
Example #5
0
        public async Task SetParentForCategory(Guid categoryId, Guid parentId)
        {
            try
            {
                var category = await Repository.GetByKeyAsync <Category>(categoryId);

                var parent = await Repository.GetByKeyAsync <Category>(parentId);

                category.SetParentCategory(parent);

                await Repository.SaveChangesAsync();

                var @event = new CategoryChildAddedEvent(parentId, categoryId);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }