public async Task Delete(StubObject stubObject) { _logger.LogDebug("Delete request, deleting: {@StubObject}", stubObject); var collection = _mongoClient.GetDatabase($"{nameof(StubObject)}").GetCollection <StubObject>($"{nameof(StubObject)}"); var filter = Builders <StubObject> .Filter.Eq("Id", stubObject.Id); await collection.DeleteOneAsync(filter); }
public async Task <ActionResult> Delete(StubObject packet) { try { await _database.Delete(packet); return(Ok()); } catch (Exception e) { _logger.LogError("Failed to delete object {@Object} with error {@Exception}", packet, e.Message); return(Conflict()); } }
public void JTokenToObjectConversion_Tests() { var o = new StubObject { Firstname = "test1", Lastname = "test1" }; var jtoken = o.AsJToken(); var co = jtoken.AsObject <StubObject>(); Assert.NotNull(co); Assert.Equal(o.Firstname, co.Firstname); Assert.Equal(o.Lastname, co.Lastname); jtoken = null; Assert.Null(jtoken.AsObject <StubObject>()); }
public async Task Update(StubObject stubObject) { _logger.LogDebug("Update request, update: {@StubObject}", stubObject); var collection = _mongoClient.GetDatabase($"{nameof(StubObject)}").GetCollection <StubObject>($"{nameof(StubObject)}"); await collection.ReplaceOneAsync(doc => doc.Id == stubObject.Id, stubObject); }
public async Task Create(StubObject stubObject) { _logger.LogDebug("Create request, creating: {@stubObject}", stubObject); var collection = _mongoClient.GetDatabase($"{nameof(StubObject)}").GetCollection <StubObject>($"{nameof(StubObject)}"); await collection.InsertOneAsync(stubObject); }