Exemple #1
0
        public static async Task <T> Update <T>(this T item) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();
            await collection.ReplaceOneAsync(a => a.Id == item.Id, item);

            return(item);
        }
Exemple #2
0
        public static T UpdateSync <T>(this T item) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();

            collection.ReplaceOne(a => a.Id == item.Id, item);
            return(item);
        }
Exemple #3
0
        public static async Task <T> Insert <T>(this T item) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();
            await collection.InsertOneAsync(item);

            return(item);
        }
Exemple #4
0
        public static T InsertSync <T>(this T item) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();

            collection.InsertOne(item);
            return(item);
        }
Exemple #5
0
        public static T Update <T>(this T item) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();

            collection.Save(item);
            return(item);
        }
Exemple #6
0
 public static async Task Delete <T>(this T item) where T : IMongoModel
 {
     var collection = MongoTools.GetCollection <T>();
     var oid        = item.Id;
     await collection.DeleteOneAsync(a => a.Id == oid);
 }
Exemple #7
0
 public static async Task Delete <T>(this string id) where T : IMongoModel
 {
     var collection = MongoTools.GetCollection <T>();
     var oid        = new ObjectId(id);
     await collection.DeleteOneAsync(a => a.Id == oid);
 }
Exemple #8
0
        public static void Delete <T>(this T item) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();

            collection.Remove(Query.EQ("_id", item.Id));
        }
Exemple #9
0
        public static void Delete <T>(this string id) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();

            collection.Remove(Query.EQ("_id", ObjectId.Parse(id)));
        }