コード例 #1
0
        public bool ReplaceSchoolList(Oldschool data)
        {
            FilterDefinition <Oldschool> filter =
                Builders <Oldschool> .Filter.Eq(x => x.Id, data.Id);

            var updateBuilders = Builders <Oldschool> .Update
                                 .Set(x => x.SchoolList, data.SchoolList);

            var result = Collection.UpdateOne(filter, updateBuilders);

            return(result.IsAcknowledged);
        }
コード例 #2
0
 public bool Insert(Oldschool data)
 {
     try
     {
         Collection.InsertOne(data);
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
コード例 #3
0
        public bool Update(Oldschool data)
        {
            FilterDefinition <Oldschool> filter =
                Builders <Oldschool> .Filter.Eq(x => x.Id, data.Id);

            var updateBuilders = Builders <Oldschool> .Update
                                 .Set(x => x.Name, data.Name)
                                 .Set(x => x.LastUpdateDate, DateTime.UtcNow);

            var result = Collection.UpdateOne(filter, updateBuilders);

            return(result.IsAcknowledged);
        }
コード例 #4
0
        public bool Upsert1(Oldschool data)
        {
            var utcnow = DateTime.UtcNow;

            data.CreateDate = utcnow;
            var result = Collection.ReplaceOne(o => o.Id == data.Id,
                                               data,
                                               new ReplaceOptions()
            {
                IsUpsert = true
            });

            return(result.IsAcknowledged);
        }
コード例 #5
0
        public bool Upsert2(Oldschool data)
        {
            var utcnow = DateTime.UtcNow;

            FilterDefinition <Oldschool> filter =
                Builders <Oldschool> .Filter.Eq(x => x.Id, data.Id);

            var updateBuilders = Builders <Oldschool> .Update
                                 .Set(x => x.Name, data.Name)
                                 .SetOnInsert(x => x.CreateDate, utcnow)
                                 .Set(x => x.LastUpdateDate, utcnow);

            var updateOption = new UpdateOptions
            {
                IsUpsert = true
            };

            var result = Collection.UpdateOne(filter, updateBuilders, updateOption);

            return(result.IsAcknowledged);
        }
コード例 #6
0
        public bool Delete(Oldschool data)
        {
            var result = Collection.DeleteOne(x => x.Id == data.Id);

            return(result.IsAcknowledged);
        }