示例#1
0
        public static async Task <bool> InsertOneAsync <T>(this IMongoCollection <T> mongoCollection, ITransitBus transitBus, T command) where T : class
        {
            bool flag = false;

            await mongoCollection.InsertOneAsync(command)
            .ContinueWith(async(t) =>
            {
                if (transitBus != null)
                {
                    await transitBus.Publish <T>(command);
                }
            });

            flag = true;


            return(flag);
        }
示例#2
0
        public static async Task <bool> InsertOrReplaceOneAsync <T>(this IMongoCollection <T> mongoCollection, ITransitBus transitBus, T command, Expression <Func <T, bool> > predicate) where T : class
        {
            bool flag = false;


            if ((mongoCollection.AsQueryable().Where(predicate).Any()))
            {
                await mongoCollection.ReplaceOneAsync(predicate, command);
            }
            else
            {
                await mongoCollection.InsertOneAsync(command);
            }
            if (transitBus != null)
            {
                await transitBus.Publish <T>(command);
            }


            return(flag);
        }