Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        public static T InsertSync <T>(this T item) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();

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

            collection.Save(item);
            return(item);
        }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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));
        }
Exemplo n.º 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)));
        }