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); }
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); }
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); }
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); }
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); }
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); }
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); }
public abstract EventResult Apply(EventBase e, IEventOptions options);