Browse Source

No deletion anymore

pull/1/head
Sebastian 9 years ago
parent
commit
b82752e2b9
  1. 15
      src/Squidex.Read.MongoDb/Contents/MongoContentRepository_EventHandling.cs

15
src/Squidex.Read.MongoDb/Contents/MongoContentRepository_EventHandling.cs

@ -111,29 +111,22 @@ namespace Squidex.Read.MongoDb.Contents
}); });
} }
protected Task On(FieldDeleted @event, EnvelopeHeaders headers) protected Task On(ContentDeleted @event, EnvelopeHeaders headers)
{ {
return ForSchemaIdAsync(@event.SchemaId.Id, collection => return ForSchemaIdAsync(@event.SchemaId.Id, collection =>
{ {
return collection.UpdateManyAsync(new BsonDocument(), Update.Unset(new StringFieldDefinition<MongoContentEntity>($"Data.{@event.FieldId}"))); return collection.DeleteOneAsync(x => x.Id == headers.AggregateId());
}); });
} }
protected Task On(ContentDeleted @event, EnvelopeHeaders headers) protected Task On(FieldDeleted @event, EnvelopeHeaders headers)
{ {
return ForSchemaIdAsync(@event.SchemaId.Id, collection => return ForSchemaIdAsync(@event.SchemaId.Id, collection =>
{ {
return collection.DeleteOneAsync(x => x.Id == headers.AggregateId()); return collection.UpdateManyAsync(new BsonDocument(), Update.Unset(new StringFieldDefinition<MongoContentEntity>($"Data.{@event.FieldId}")));
}); });
} }
protected Task On(SchemaDeleted @event, EnvelopeHeaders headers)
{
var collectionName = $"{Prefix}{@event.SchemaId.Id}";
return database.DropCollectionAsync(collectionName);
}
private async Task ForSchemaIdAsync(Guid schemaId, Func<IMongoCollection<MongoContentEntity>, Task> action) private async Task ForSchemaIdAsync(Guid schemaId, Func<IMongoCollection<MongoContentEntity>, Task> action)
{ {
var collection = GetCollection(schemaId); var collection = GetCollection(schemaId);

Loading…
Cancel
Save