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

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

                if (parentId != Guid.Empty)
                {
                    var parent = await Repository.GetByKeyAsync <Category>(parentId);

                    category.RemoveParent(parent);
                    await Repository.SaveChangesAsync();

                    var @event = new CategoryChildRemovedEvent(parentId, categoryId);
                    EventBus.RaiseEvent(@event);
                }
            }
            catch
            {
                throw;
            }
        }
 /// <summary>
 /// <see cref="IHandleEvent{TEvent}.Handle(TEvent)"/>
 /// </summary>
 /// <param name="event"></param>
 public void Handle(CategoryChildRemovedEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }
Пример #3
0
        public void CategoryChildRemovedEvent_Ctor_Should_Set_Arguments_Correctly()
        {
            Guid categoryId = Guid.NewGuid();
            Guid childId    = Guid.NewGuid();

            var @event = new CategoryChildRemovedEvent(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);
        }
Пример #4
0
        public async Task RemoveChildForCategory(Guid categoryId, Guid childId)
        {
            try
            {
                var category = await Repository.GetByKeyAsync <Category>(categoryId);

                category.RemoveChild(childId);

                await Repository.SaveChangesAsync();

                var @event = new CategoryChildRemovedEvent(categoryId, childId);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }
Пример #5
0
        public async Task RemoveParentForCategory(Guid categoryId)
        {
            try
            {
                var category = await Repository.GetByKeyAsync <Category>(categoryId);

                var parentId = category.Parent?.Id;

                category.RemoveParent();

                await Repository.SaveChangesAsync();

                if (parentId != null)
                {
                    var @event = new CategoryChildRemovedEvent((Guid)parentId, categoryId);
                    EventBus.RaiseEvent(@event);
                }
            }
            catch
            {
                throw;
            }
        }