/// <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); }
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}"); } }