-
Notifications
You must be signed in to change notification settings - Fork 24
Step 2: Managing Customers
Ole Melhus edited this page Mar 6, 2017
·
4 revisions
You can fetch all customers by using the All
method. This will download all the customers using a buffer and return them when they are all downloaded.
var customers = await vismaNet.Customers.All()
foreach(var customer in customers){
Console.WriteLine("{0}: {1}", customer.number, customer.name);
}
Alternatively you can use the function ForEach
which will stream the results as soon as it starts receiving it. This function takes a callback Action, or Func<T, Task> for async/await, that will run for each item returned from the API.
await vismaNet.Customers.ForEach(customer => {
// ... do stuff with customer.
});
await vismaNet.Customers.ForEach(async customer => {
// ... await stuff with customer.
});
var customer = await vismaNet.Customers.Get("10000171");
Console.WriteLine($"Customer name: {customer.name}");
var newCustomer = new Customer { name = "John Smith" };
var createdCustomer = await vismaNet.Customers.Add(newCustomer);
Console.WriteLine($"New customer created with number: {createdCustomer.number}");
var customer = await vismaNet.Customers.Get("10000171");
customer.name = "Name is updated";
customer.accountReference = "New account reference here";
await vismaNet.Customers.Update(customer);