private IEventMap <ProjectionContext> BuildMapFrom(IEventMapBuilder <TProjection, string, ProjectionContext> mapBuilder) { mapBuilder.HandleProjectionModificationsAs((key, context, projector, options) => { TProjection projection = store.GetRepository <TProjection>().Find(key); if (projection == null) { projection = new TProjection() { Id = key }; store.Add(projection); } return(projector(projection)); }); mapBuilder.HandleProjectionDeletionsAs((key, context, options) => { store.GetRepository <TProjection>().RemoveByKey(key); return(Task.FromResult(0)); }); mapBuilder.HandleCustomActionsAs((context, projector) => projector()); return(mapBuilder.Build()); }
private IEventMap <ProjectionContext> BuildMapFrom(IEventMapBuilder <TProjection, string, ProjectionContext> mapBuilder) { return(mapBuilder.Build(new ProjectorMap <TProjection, string, ProjectionContext> { Create = async(key, context, projector, shouldOverride) => { var projection = new TProjection() { Id = key }; await projector(projection); store.Add(projection); }, Update = async(key, context, projector, createIfMissing) => { TProjection projection = store.GetRepository <TProjection>().Find(key); await projector(projection); store.Add(projection); }, Delete = (key, context) => { store.GetRepository <TProjection>().RemoveByKey(key); return Task.FromResult(true); }, Custom = (context, projector) => projector() })); }
private string GetCountryName(Guid countryCode) { var lookup = store.GetRepository <CountryLookup>().Find(countryCode.ToString()); return((lookup != null) ? lookup.Name : ""); }