public bool Remove(string id)
        {
            MongoDB.Driver.FilterDefinition <Dashboard.Models.Session> filter = Builders <Session> .Filter.Eq("_id", id);

            MongoDB.Driver.DeleteResult result = _collection.DeleteOne(filter);
            return(result.DeletedCount == 1);
        }
Ejemplo n.º 2
0
        public async Task <bool> RemoveLoan(Guid id)
        {
            try
            {
                DeleteResult actionResult
                    = await _context.Mortgages.DeleteOneAsync(Builders <MortgageDoc> .Filter.Eq("Id", id));

                return(actionResult.IsAcknowledged && actionResult.DeletedCount > 0);
            }
            catch (Exception ex)
            {
                // log or manage the exception
                throw ex;
            }
        }
Ejemplo n.º 3
0
        public async Task <bool> RemoveAllLoans()
        {
            try
            {
                DeleteResult actionResult
                    = await _context.Mortgages.DeleteManyAsync(_ => true);

                return(actionResult.IsAcknowledged && actionResult.DeletedCount > 0);
            }
            catch (Exception ex)
            {
                // log or manage the exception
                throw ex;
            }
        }
Ejemplo n.º 4
0
        public async Task <DeleteResult> DeleteOneAsync(DeleteOneModel <TDocument> model, TimeSpan?timeout, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(model, "model");

            try
            {
                var bulkModel = new BulkWriteModel <TDocument>(new[] { model });
                var result    = await BulkWriteAsync(bulkModel, timeout, cancellationToken);

                return(DeleteResult.FromCore(result));
            }
            catch (BulkWriteException <TDocument> ex)
            {
                throw WriteException.FromBulkWriteException(ex);
            }
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public virtual DeleteResult DeleteMany(FilterDefinition <TDocument> filter, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(filter, nameof(filter));

            var model = new DeleteManyModel <TDocument>(filter);

            try
            {
                var result = BulkWrite(new[] { model }, null, cancellationToken);
                return(DeleteResult.FromCore(result));
            }
            catch (MongoBulkWriteException <TDocument> ex)
            {
                throw MongoWriteException.FromBulkWriteException(ex);
            }
        }
Ejemplo n.º 6
0
        /// <inheritdoc />
        public virtual async Task <DeleteResult> DeleteOneAsync(FilterDefinition <TDocument> filter, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(filter, "filter");

            var model = new DeleteOneModel <TDocument>(filter);

            try
            {
                var result = await BulkWriteAsync(new[] { model }, null, cancellationToken).ConfigureAwait(false);

                return(DeleteResult.FromCore(result));
            }
            catch (MongoBulkWriteException <TDocument> ex)
            {
                throw MongoWriteException.FromBulkWriteException(ex);
            }
        }
        private DeleteResult DeleteOne(FilterDefinition <TDocument> filter, DeleteOptions options, Func <IEnumerable <WriteModel <TDocument> >, BulkWriteResult> bulkWrite)
        {
            Ensure.IsNotNull(filter, nameof(filter));
            options = options ?? new DeleteOptions();

            var model = new DeleteOneModel <TDocument>(filter)
            {
                Collation = options.Collation
            };

            try
            {
                var result = bulkWrite(new[] { model });
                return(DeleteResult.FromCore(result));
            }
            catch (MongoBulkWriteException <TDocument> ex)
            {
                throw MongoWriteException.FromBulkWriteException(ex);
            }
        }
        private async Task <DeleteResult> DeleteOneAsync(FilterDefinition <TDocument> filter, DeleteOptions options, Func <IEnumerable <WriteModel <TDocument> >, Task <BulkWriteResult <TDocument> > > bulkWriteAsync)
        {
            Ensure.IsNotNull(filter, nameof(filter));
            options = options ?? new DeleteOptions();

            var model = new DeleteOneModel <TDocument>(filter)
            {
                Collation = options.Collation
            };

            try
            {
                var result = await bulkWriteAsync(new[] { model }).ConfigureAwait(false);

                return(DeleteResult.FromCore(result));
            }
            catch (MongoBulkWriteException <TDocument> ex)
            {
                throw MongoWriteException.FromBulkWriteException(ex);
            }
        }