Book Image

Learning Microsoft Azure

By : Geoff Webber Cross, Geoff Webber-Cross
Book Image

Learning Microsoft Azure

By: Geoff Webber Cross, Geoff Webber-Cross

Overview of this book

Table of Contents (19 chapters)
Learning Microsoft Azure
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Updating the admin website


As with the order processor, we can do a small modification to the admin website to call the Notification/PostProductNews action when a new product is created, which will send push notifications to all customers. The procedure for this is pretty much the same, but here, I created a separate helper class to separate the logic from the controller:

private readonly MobileServiceClient _mobileService;

public Notifications()
{
    var mobileServiceUrl = ConfigurationManager.AppSettings["mobileServiceUrl"];
    var mobileServiceKey = ConfigurationManager.AppSettings["mobileServiceKey"];

    this._mobileService = new MobileServiceClient(mobileServiceUrl, mobileServiceKey);
}

public async Task NotifyPostProductNews(int productId)
{
    dynamic data = new ExpandoObject();
    data.productId = productId;

    await this._mobileService.InvokeApiAsync<object, dynamic>("Notification/PostProductNews", data);
}

This method can be called by the ProductController.Create...