Skip to content

Step 2: Managing Customers

Ole Melhus edited this page Mar 6, 2017 · 4 revisions

List all customers

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.
});

Get a specific customer

var customer = await vismaNet.Customers.Get("10000171");
Console.WriteLine($"Customer name: {customer.name}");

Create a new customer

var newCustomer = new Customer { name = "John Smith" };
var createdCustomer = await vismaNet.Customers.Add(newCustomer);
Console.WriteLine($"New customer created with number: {createdCustomer.number}");

Update an existing customer

var customer = await vismaNet.Customers.Get("10000171");
customer.name = "Name is updated";
customer.accountReference = "New account reference here";
await vismaNet.Customers.Update(customer);

Continue to Customer Invoices

Clone this wiki locally