示例#1
0
 private static void SetVersion(IEntity entity, EnvelopeHeaders headers)
 {
     if (entity is IUpdateableEntityWithVersion updateable)
     {
         updateable.Version = headers.EventStreamNumber();
     }
 }
示例#2
0
 private static void SetVersion(EnvelopeHeaders headers, IMongoEntity entity)
 {
     if (entity is IEntityWithVersion withVersion)
     {
         withVersion.Version = headers.EventStreamNumber();
     }
 }
        public static async Task <bool> TryUpdateAsync <T>(this IMongoCollection <T> collection, SquidexEvent @event, EnvelopeHeaders headers, Action <T> updater) where T : class, IEntity, new()
        {
            var entity =
                await collection.Find(t => t.Id == headers.AggregateId())
                .FirstOrDefaultAsync();

            if (entity != null)
            {
                if (entity is IEntityWithVersion withVersion)
                {
                    var eventVersion = headers.EventStreamNumber();

                    if (eventVersion <= withVersion.Version)
                    {
                        return(false);
                    }
                }

                await collection.UpdateAsync(@event, headers, entity, updater);

                return(true);
            }

            return(false);
        }
示例#4
0
 protected Task On(ContentStatusChanged @event, EnvelopeHeaders headers)
 {
     return(ForAppIdAsync(@event.AppId.Id, collection =>
     {
         return collection.UpdateOneAsync(
             Filter.Eq(x => x.Id, @event.ContentId),
             Update
             .Set(x => x.Status, @event.Status)
             .Set(x => x.LastModified, headers.Timestamp())
             .Set(x => x.LastModifiedBy, @event.Actor)
             .Set(x => x.Version, headers.EventStreamNumber()));
     }));
 }
示例#5
0
        protected Task On(ContentUpdated @event, EnvelopeHeaders headers)
        {
            return(ForSchemaAsync(@event.AppId, @event.SchemaId.Id, (collection, schema) =>
            {
                var idData = @event.Data?.ToIdModel(schema.SchemaDef, true);

                return collection.UpdateOneAsync(
                    Filter.Eq(x => x.Id, @event.ContentId),
                    Update
                    .Set(x => x.DataText, idData.ToFullText())
                    .Set(x => x.IdData, idData)
                    .Set(x => x.ReferencedIds, idData.ToReferencedIds(schema.SchemaDef))
                    .Set(x => x.LastModified, headers.Timestamp())
                    .Set(x => x.LastModifiedBy, @event.Actor)
                    .Set(x => x.Version, headers.EventStreamNumber()));
            }));
        }