private void DeleteUnprocessedEntities <TEntity>(IEnumerable <int> entityKeys) where TEntity : BaseModel { EntitiesByKeyQuery <TEntity> entitiesQuery = new EntitiesByKeyQuery <TEntity>(entityKeys, x => !entityKeys.Contains(x.Key)); IEnumerable <TEntity> entities = queryDispatcher.Dispatch <EntitiesByKeyQuery <TEntity>, IEnumerable <TEntity> >(entitiesQuery); DeleteEntitiesCommand <TEntity> entitiesCommand = new DeleteEntitiesCommand <TEntity>(entities); commandDispatcher.Dispatch(entitiesCommand); }
public void Handle(DeleteEntitiesCommand <TEntity> command) { foreach (var entity in command.Entities) { FilterDefinition <TEntity> filter = Builders <TEntity> .Filter.Eq(x => x.Id, entity.Id); UpdateDefinition <TEntity> update = Builders <TEntity> .Update .Set(x => x.IsDeleted, true) .Set(x => x.DeletedOn, DateTime.UtcNow); dbContext.GetCollection <TEntity>().UpdateOne(filter, update); cache.Delete(entity.Key); } }