コード例 #1
0
ファイル: LockRepository.cs プロジェクト: cahitbeyaz/iot-poc
 /// <summary>
 /// Inserting passed LockDeviceBson into the database.
 /// </summary>
 public async Task UpsertLockDeviceBson(LockDeviceBson lockDevice)
 {
     var result = _LockDeviceBsonsCollection.ReplaceOne(
         filter: new BsonDocument("lockDeviceId", lockDevice.LockDeviceId),
         options: new UpdateOptions {
         IsUpsert = true,
     },
         replacement: lockDevice);
 }
コード例 #2
0
ファイル: LockController.cs プロジェクト: cahitbeyaz/iot-poc
        public async Task UpdateLockStatus([FromBody] ApiLockDevice lockDevice)
        {
            var ld = await MongoDriver.MongoDbRepo.GetLockDeviceBsonsByField("lockDeviceId", lockDevice.LockDeviceId);

            if (ld.FirstOrDefault() != null)
            {
                LockDeviceBson lockDeviceBson = ld.FirstOrDefault();
                lockDeviceBson.IsActive = lockDevice.IsActive;
                await MongoDriver.MongoDbRepo.UpsertLockDeviceBson(lockDeviceBson);
            }
            else
            {
                throw new Exception($"Lock device not found {lockDevice}");
            }
        }