Esempio n. 1
0
        public async Task <bool> SaveAsync(WebhookPublisher model, bool?references = true, CancellationToken token = default)
        {
            var persisted = false;

            using (var scope = TransactionScopeOption.Required.AsTransactionScopeFlow())
            {
                var candidate = model;
                if (!references.HasValue || !references.Value)
                {
                    candidate = model.CreateCopy();
                    candidate.Definitions.Clear();
                }
                var result = await collection.ReplaceOneAsync(x => x.Id == model.Id, candidate, new ReplaceOptions { IsUpsert = true });

                persisted = result.IsAcknowledged;
                scope.Complete();
            }
            return(persisted);
        }
Esempio n. 2
0
        public bool Save(WebhookPublisher model, bool?references = true)
        {
            var persisted = false;

            using (var scope = TransactionScopeOption.Required.AsTransactionScope())
            {
                var candidate = model;
                if (!references.HasValue || !references.Value)
                {
                    candidate = model.CreateCopy();
                    candidate.Definitions.Clear();
                }
                var result = collection.ReplaceOne(x => x.Id == model.Id, candidate, new ReplaceOptions {
                    IsUpsert = true
                });
                persisted = result.IsAcknowledged;
                scope.Complete();
            }
            return(persisted);
        }