Updating Records
Fetch the entity, modify its properties, then call UpdateAsync. The full entity is sent to the API.
Update a coworker
var endpoint = new CoworkerEndpoint(client);
var coworker = await endpoint.GetAsync(id);
coworker!.CompanyName = "Updated Corp";
coworker.Position = "Senior Engineer";
await endpoint.UpdateAsync(coworker);
Console.WriteLine("Coworker updated.");
Update a product
var endpoint = new ProductEndpoint(client);
var product = await endpoint.GetAsync(productId);
product!.Name = "Premium Day Pass";
product.Price = 35.00m;
await endpoint.UpdateAsync(product);
Error handling
UpdateAsync throws InvalidOperationException on failure:
try
{
await endpoint.UpdateAsync(entity);
}
catch (InvalidOperationException ex)
{
Console.WriteLine($"Update failed: {ex.Message}");
}
Always fetch the latest version of the entity before updating to avoid overwriting changes made by other users or processes.