コード例 #1
0
        public override EventResult Apply(ProductTagAdd e, IEventOptions options)
        {
            var result = base.Apply(e, options);

            var tag = UnitOfWork.TagRepository.Find(x => x.Name == e.Value).FirstOrDefault();

            if (tag == null)
            {
                Entity.ProductTags.Add(new DataModel.ProductTag {
                    ProductId = Entity.Id, Tag = new DataModel.Tag {
                        Name = e.Value
                    }
                });
            }
            else
            {
                Entity.ProductTags.Add(new DataModel.ProductTag {
                    ProductId = Entity.Id, TagId = tag.Id
                });
            }

            if (options.Store)
            {
                CreateLog("Tags", e.Value.ToString());
            }
            return(result);
        }
コード例 #2
0
        protected virtual EventResult ApplyChanges(V entity, T e, IEventOptions options)
        {
            var result   = new EventResult();
            var handlers = GetHandlers(entity);

            foreach (var ev in e.Events)
            {
                foreach (var h in handlers)
                {
                    h.Apply(ev.Value, options);
                }
            }
            return(result);
        }
コード例 #3
0
        public override EventResult Apply(ProductNameChange e, IEventOptions options)
        {
            var result = base.Apply(e, options);

            if (!string.Equals(Entity.Name, e.Value))
            {
                Entity.Name = e.Value;
                if (options.Store)
                {
                    CreateLog("Name", e.Value);
                }
            }
            return(result);
        }
コード例 #4
0
        public override EventResult Apply(ProductStateChange e, IEventOptions options)
        {
            var result = base.Apply(e, options);

            if (Entity.State != e.Value)
            {
                Entity.State = e.Value;
                if (options.Store)
                {
                    CreateLog("State", e.Value.ToString());
                }
            }
            return(result);
        }
コード例 #5
0
        public override EventResult Apply(ProductPriceChange e, IEventOptions options)
        {
            var result = base.Apply(e, options);

            if (!decimal.Equals(Entity.Price, e.Value))
            {
                Entity.Price = e.Value;
                if (options.Store)
                {
                    CreateLog("Price", e.Value.ToString());
                }
            }

            return(result);
        }
コード例 #6
0
        public sealed override EventResult Apply(T e, IEventOptions options)
        {
            var result = base.Apply(e, options);

            var entity = GetEntity(e);

            result += ApplyChanges(entity, e, options);

            if (result.Success)
            {
                result += SaveChanges(entity);
            }
            else
            {
                result += Rollback(entity);
            }
            return(result);
        }
コード例 #7
0
        public override EventResult Apply(ProductTagRemove e, IEventOptions options)
        {
            var result = base.Apply(e, options);

            var tag = UnitOfWork.TagRepository.Find(x => x.Name == e.Value).FirstOrDefault();

            if (tag == null)
            {
                return(result);
            }

            Entity.ProductTags.Remove(Entity.ProductTags.FirstOrDefault(x => x.TagId == tag.Id));

            if (options.Store)
            {
                CreateLog("Tags", e.Value.ToString());
            }
            return(result);
        }
コード例 #8
0
 public abstract EventResult Apply(EventBase e, IEventOptions options);