Within the current preview version Office365 API’s are generating only a sample how to read data. Because I got some questions on how to write new entities back to Office365 and I got some rumors that these APIs only allow “reading” data. I’d like to share the following sample which shows how to implement all CRUD methods using Office365 API.

I hope this post makes clear, that Office365 are supporting the full CRUD stack, no matter which kind of entity (Contacts, Calendar Events, Users, Groups, Mails, Files) you’re interested in!

Consider you’ve already created a new MVC Web App using Visual Studio and added a Connected Service for Contacts (with both READ and WRITE permissions). (See my post here if you’re not sure how to complete these steps).

Instead of relying on the generated ContacsAPISample class I’d advice you to use a regular class which allows you to build testable Web Apps and you can of course use a Dependency Injection Container such as Ninject in order to decouple your components.

In order to provide a testable Repository I’ve extracted the interface IContacsRepositoy which looks like the following

[gist id=”0efd53eca4fc77008e9e” file=”IContactsRepository.cs”]

The corresponding implementation is straight forward using C# async/await pattern

[gist id=”0efd53eca4fc77008e9e” file=”ContactsRepository.cs”]

To make it clear again. Office 365 API’s support all kind of CRUD operations