Web Camps–30 new events in the calendar, seats going fast!

Web Camp SantiagoFlair001   DSCN5251

The Web Camps team has been busy working on organizing new events around the world and we’ve got a bunch of new events to share with you!  We’ve also been getting reports in on the first Web Camps where developers have been getting free training on how to build web applications using cutting edge technologies.

A couple of weeks ago the Chile team held their first Web Camp in Santiago!  The event was a big success with hundreds of developers learning about IE9, HTML 5, WebMatrix and Razor, ASP.NET MVC 3 and Silverlight!  On the other side of the world, the clip_image001[7]team in Karachi, Pakistan ran a Web Camp on ASP.NET MVC teaching the fundamentals to developers to get them started building web app.  Meanwhile in Seoul, Korea developers packed into the Microsoft office to learn about ASP.NET MVC too! 

We’ve got a bunch of new events planned all around the world covering a bunch of interesting technologies.  Check out the www.webcamps.ms website and the event list below for a sample of some of the events we have planned for you!

 

 

 
Web Camps India – Bangalore

On the 16th November Jon Galloway and I start out Web Camp India tour in Bangalore with a one day Web Camp covering ASP.NET MVC 3 where attendees can learn what’s new in the latest version of the framework, Razor as well as NuGet the package management tool for ASP.NET!  To sign up for this event register here!

Web Camps India – Hyderabad

Next, we travel onwards to Hyderabad and on 18th/19th we’ll deliver a two day event on ASP.NET MVC 3 with presentations and demos on the first day and fresh new labs on ASP.NET MVC 3 on day two to put your learning into practice! To sign up for this event register here!

 

Full Web Camps Calendar

The full calendar is maintained and updated here.

City

Country

Date

Presenters

Registration Link

Hyderabad

India

18-Nov-10

James Senior &
Jon Galloway

Register Here

Amsterdam

Netherlands

20-Jan-11

James Senior &
Scott Hanselman

Coming Soon

Paris

France

25-Jan-11

James Senior &
Scott Hanselman

Coming Soon

Austin, TX

USA

7-Mar-11

James Senior &
Scott Hanselman

Coming Soon

Buenos Aires

Argentina

14-Mar-11

James Senior &
Phil Haack

Coming Soon

São Paulo

Brazil

18-Mar-11

James Senior &
Phil Haack

Coming Soon

Silicon Valley

USA

6-May-11

James Senior &
Doris Chen

Coming Soon

 

City

Country

Date

Technology

Registration Link

Bangalore

India

16-Nov-10

ASP.NET MVC

Register Here

Paris

France

25-Nov-10

TBA

Register Here

Bad Homburg

Germany

30-Nov-10

ASP.NET MVC

Register Here

Bogota

Colombia

30-Nov-10

Multiple

Register Here

Chennai

India

1-Dec-10

ASP.NET MVC

Register Here

Pune

India

3-Dec-10

ASP.NET MVC

Register Here

Moulineaux

France

8-Dec-10

TBA

RegisterHere

Sarajevo

Bosnia and Herzegovina

10-Dec-10

ASP.NET MVC

Register Here

Bad Homburg

Germany

16-Dec-10

ASP.NET MVC

Register Here

Moulineaux

France

11-Jan-11

TBA

RegisterHere

Cape Town

South Africa

22-Jan-11

Web Matrix

Coming Soon

Johannesburg

South Africa

29-Jan-11

Web Matrix

Coming Soon

Tunis

Tunisia

1-Feb-11

ASP.Net MVC

Register Here

Cape Town

South Africa

12-Feb-11

ASP.Net MVC

Coming Soon

San Francisco, CA

USA-West

18-Feb-11

ASP.NET MVC

Coming Soon

Johannesburg

South Africa

19-Feb-11

ASP.Net MVC

Coming Soon

Redmond, WA

USA-West

18-Mar-11

Odata

Coming Soon

Munich

Germany

31-Mar-11

Web Matrix

Register Here

Moulineaux

France

5-Apr-11

TBA

RegisterHere

Moulineaux

France

17-May-11

TBA

RegisterHere

Irvine, CA

USA-West

10-Jun-11

ASP.NET MVC

Coming Soon

Moulineaux

France

14-Jun-11

TBA

RegisterHere

Read More

New PayPal Helper for WebMatrix

This week I’ve been at the PayPal Innovate Conference in San Francisco where Microsoft and PayPal have been talking to thousands of developers about the work we have been doing to create the easiest way to build apps that use PayPal for payments.  Today we are releasing the PayPal Helper for WebMatrix (in beta) which provides a simple way to do PayPal payments from the websites you build in WebMatrix.

What’s included in the PayPal Helper?

The helper we are shipping today, provides methods for the Button Manager API and Adaptive Payments API which are two of PayPal’s most popular APIs.  Here’s what PayPal says about both:

  • Button Manager APIs let you create, manage, edit, and delete Website Payments Standard buttons. Create payment buttons that let customers purchase single or multiple items, make donations, set up recurring payments, or buy gift certificates.
  • Adaptive Payments enable developers to build apps that process transactions. App builders can control the entire transaction within a single interface.
Downloading and installing the PayPal Helper
  1. Download and install WebMatrix
  2. Download the assemblies for the Helper (PayPal.dll, paypal_base.dll, log4net.dll)
  3. Create a new website or template in WebMatrix
  4. Create a bin folder off the root
  5. Copy and paste the assemblies into the bin
  6. You’re done!
PayPal Helper: Using Button Manager

Note – If you’re not familiar with the Button Manager API from PayPal, check out PayPal’s developer portal to find out more

The first thing you need to do is initialize the helper with your PayPal account credentials.  You can of course do this inline in the page, but the recommended option is to place the init call in your _AppStart.cshtml page so that it is called once when the app runs.  Here’s the init call code:

PayPal.Profile.InitializeBMProfile(
           “[API Username]”,
           “[API Password]”,
           “[API Secret]”,
           “sandbox”);

 

Next, to create a button on the PayPal side, call the method below.  When the Create AddToCart Button is fired, it returns the HTML code needed to display the button which we can then save to the database. We’ll typically use this HTML when we display the product detail page.

var payPalButton = PayPal.AddToCartButton.Create(
                                           Business : “[insert your sandbox account]”,
                                           ItemName : name,
                                           Amount : price.ToString(“N2″));

 

Now, if you login to PayPal (remember to use your Sandbox account if you have been using that) and click the “Profile” link and then “My Saved Buttons” under Selling Preferences, you will be able to see the button you have just created:

image

PayPal Helper: Using Adaptive Payments

Note – if you are not familiar with the Adaptive Payments service from PayPal, check out their developer portal for more information

I’m a big fan of the Adaptive Payment API because it has some cool features like Split Payments which allow you to pay other people “behind the scenes” without the customer knowing.  This is great if you have suppliers that you want to pay whenever an item gets sold through your online application but you don’t want to bother the customer with the details or let them know what you are paying your suppliers Smile

First up you’ll need to Initialize the profile, just like we did for Button Manager.  Here’s the code for that:

PayPal.Profile.InitializeFNProfile(               
       “ThreeToken”,
       “[API Username]”,
       “[API Password]”,
       “[API Key]”,
       “SOAP11″,
       “SOAP11″,
       “https://svcs.sandbox.paypal.com/”,
       “[App ID]”,
       “[PayPal User Email Address]”
   );

 

Next, we prepare the payment by setting up a single instance of a “receiver” which will the store that is receiving the payment.  After that we setup a list of receivers, which represents our suppliers (or other people that we need to pay after the transaction).  Up top I’ve done a quick calculation to give the supplier 10% of the product price, of course you would typically pull this information from a database where you stored the amount you want to pay them.

Once all that is setup we then call the PayPal.ChainedPay.Execute method passing in the receivers, an empty string (this is the sender of the payment – to be specified on PayPal’s side) as well as some information on the transaction. 

PayPal returns a response from which we can get a PayKey which represents the transaction on the PayPal side.  We then redirect the user to PayPal’s site, passing in the PayKey in the querystring so that PayPal knows how the transaction has been setup.

var supplierAmount = decimal.Round(product.Price * .10m, 2);
          
        var MyStore = new Receiver();
       MyStore.amount = product.Price;
       MyStore.email = “[Store Email]”;
        
        var Suppliers = new List<Receiver>();
       var Supplier = new Receiver();
       Supplier.email = “[Supplier Email]”;
       Supplier.amount = supplierAmount;
       Suppliers.Add(Supplier);

       PayPal.ChainedPay.Language = “en_US”;
       PayPal.ChainedPay.CancelUrl = “http://www.mystore.com/ohtoobad.cshtml”;
       PayPal.ChainedPay.ReturnUrl = “http://www.mystore.com/thanks.cshtml”;
       PayPal.ChainedPay.CurrencyCode = “USD”;
      �
       var response = PayPal.ChainedPay.Execute
           (MyStore, Suppliers, “”, “Test Payment”, “127.0.0.1”, “MyDevice”);
      �
       if (response == null) {
           Response.Write(“null”);
       }
       else
       {
           Response.Write(“full”);
       }   
      �
       var payKey = response.payKey;
       var redirectUrl = “https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=” + payKey;           
      �
       Response.Redirect(redirectUrl);

 

This is what the consumer sees – note it’s just one line item to James’ test store.

image

Thanks to Chained Pay, the store sees this in it’s transaction log.  Note that our supplier has been paid automatically.

image

Open source

The code for the helper is based on the existing PayPal Base library for .NET that PayPal ship as part of the developer SDK.  This is already under the Apache license so it seemed natural to continue the tradition and release the helper in CodePlex under the Apache license.  You can download it here.

Future work

As this is a beta there’s a few items that we wanted to polish up for the final version.  

  • Remove dependency on Log4Net
  • Merge PayPal base assembly code with the new Helper assembly
  • Consolidate initialization methods for Button Manager and Adaptive Payments

As always please contact me if you have other suggestions, or leave feedback on the Codeplex project site.

Read More

New Facebook Helpers in WebMatrix Beta 2

Today we launched WebMatrix Beta 2 with a bunch of new features.  Here are my favorites:

  • Themes – quickly switch between different themes on your website
  • New HTML5 Templates in the box – rounded corners, transitions, sexy HTML5 templates. yum.
  • NuPack Package Management – get the bits you need, when you need em
  • New @Helper Syntax – adding helpers is now even easier

The new @Helper syntax makes it super easy to create your own helpers for WebMatrix.  Why would you want to do that? Well, there’s a couple of reasons.  Firstly, as a timesaver.  If you find yourself writing the same code or HTML time after time in your websites, it might be time to package up your code in a reusable Helper that you can utilize throughout your websites instead of writing the same thing over and over again and wasting time.  Secondly, if you are trying to foster a developer community that can use your service or website, then creating WebMatrix Helpers to make their life easier is a smart thing to do – because it removes friction for people to use your service.

Take the new Facebook Social Plugin Helpers in WebMatrix Beta 2 as an example.  They make use of the new @helper syntax to make it easier for developers to add social widgets to web pages.  The way you get these helpers is also worth mentioning, because it highlights a use of the NuPack technology that we announced today also.  Facebook’s Social Plugins Helper includes shortcuts to the following social widgets:

  • Login Button
  • Like Button
  • Comments
  • Recommendations
  • LikeBox
  • Facepile
  • LiveStream
  • ActivityFeed

As well as the ability to easily add metadata which shows up in rich ways across Facebook.

Getting your Helpers using NuPack

NuPack is an open source project driven by Microsoft that provides package management for developers in WebMatrix or Visual Studio 2010.  Within WebMatrix there is a package management page that you can visit where you can manage which packages are installed in your website projects.  With NuPack, it’s super easy to get Helpers and other things you’ll need to develop your website.

Note -  the current structure of our website if we create a new website from template.  Inside our app_data folder we have a bunch of folders including packages.  This is where the assets for our packages live.  We can see that we already have microsoft-web-helpers.1.0 installed by default and this package provides Helpers like Twitter, ReCapture and more.  There is also a packages.config file which contains information which points WebMatrix to the packages installed in App_Data.

image

To manage the packages installed in our website, we need to get to the admin page by simply navigating to http://localhost:xxx/_admin where xxx is your port number.  (Note – by default this is only enabled when running websites locally, as a security precaution).  If it’s the first time you’ve visited the page, you’ll be asked to create a password, remember this for future visits to the package manager page.

image

Next, you’ll be presented with a list of packages that you can install to use within your website.  Clicking on the Install button next to the Facebook.Helper 1.0 will install the files and pre-requisites for the helper to work correctly.  In the case of the Facebook Helper there are no dependencies however.

image

image

Once installed, the package “explodes” (in a useful, not violent way) in your website, installing various assets.  If we now look at the structure of the website in WebMatrix we see the Facebook Helper package has been installed successfully:

image

The most important asset is the Helper itself – FacebookSocialPlugin.cshtml and you can see that it was installed under the App_code folder in the root of website.  In this particular helper, we’ve also included some docs which explain how to get started as well as a full reference for all the methods in the helper.

To get to the docs just navigate to http://localhost:xxx/facebook/docs/starthere.htm

Note – There is already a Facebook Helper included in the Microsoft-web-helpers library which provides a shortcut to adding the Like Button to your website.  The FacebookSocialPlugin helpers has the like button as well as all the other Facebook Social Plugins and other good stuff like Open Graph etc.  In the next release we’ll merge the two Helper libraries so they are consolidated.

@helper syntax

Let’s explore the Facebook Social Plugin Helper a little more to understand how to use the @helper syntax.  The naming of the FacebookSocialPlugins.cshtml file is a good place to start.  This name will be taken as the class name at runtime, so the developer will use FacebookSocialPlugins.Foo() when using the helpers within the file.  Exploring the file, we see that all the methods use the @helper syntax, which mixes markup and code so that it’s possible to build up quite complex HTML and then inject parameters from the method or from calculated values in the helper code itself. 

Let’s take the helper method “GetInitializationScripts” as an example.  This method emits the JavaScript required by Facebook to allow their Social Plugins to work and must be added to every page that wants to use the plugins.  It’s not a trivial amount of script and before the Helper I would have to goto Facebook’s developer portal, hunt it down and copy and paste into every page.  Now with the Facebook Social Plugins Helper I can simply add the method to my _Layout.cshtml page, and by default it’s included on every page.  That’s a nice timesaver.

@helper GetInitializationScripts() {
   <div id="fb-root"></div>
   <script type="text/javascript">
       window.fbAsyncInit = function() {
           FB.init({appId: '@FacebookSocialPlugins.AppId', status: true, cookie: true, xfbml: true});
        };
       (function() {
           var e = document.createElement('script'); e.async = true;
           e.src = document.location.protocol +
           '//connect.facebook.net/en_US/all.js';
           document.getElementById('fb-root').appendChild(e);
       }());
   
       function loginRedirect(url) { window.location = url; }
   </script>
}

Notice how we inject he AppId from the FacebookSocialPlugins class?  This notion of mixing code and markup within a class method is very powerful and useful in lots of ways.  There’s a couple additional steps that you must do in order to have the Social Plugins working including calling the following method in _AppStart.cshtml.

@{
   FacebookSocialPlugins.Initialize("[Your App Id]", "[Your App Secret]", "bakery");
}

Secondly you must register the Facebook namespace in _Layout.cshtml which tells the page about the Facebook markup:

<html xmlns="http://www.w3.org/1999/xhtml" @FacebookSocialPlugins.FbmlNamespaces() >

 

Normally this would be a copy and paste from the depths of the Facebook developer portal, now it’s simply a case of using the Helper and you’re done.

This then clears the path for us to easily add Facebook’s Social Plugins to a WebMatrix website:

    <p>
   @FacebookSocialPlugins.Comments()
</p>

 

Results in:

image

It’s important to note that some Social Plugins require your site to be published to an external host that Facebook can communicate back and forth to.

I recommend checking out the documentation which comes as part of the Helper NuPack for more information on getting started, simply press the “run” button in WebMatrix  with startHere.html opened to browse the docs.

image

Other good reading on WebMatrix Beta 2

Read More

Web Camps Training Kit – September Edition

The Web Camp in Los Angeles was a great success last Friday with Phil Haack, Jon Galloway and myself imparting a raft of knowledge on ASP.NET MVC 2, jQuery, Entity Framework Code-first, ASP.NET MVC 3 and Razor.  However, there’s little time to pat ourselves on the back – because this week marks the launch of the September Edition of the Web Camps Training Kit!

Online and available as a download

The previous version of the Web Camps Training Kit was only available as a download, but we listened to your feedback and are now publishing it online too!  Choose your flavor below:

Browse the content online

Download it Now

What’s new in the Web Camps Training Kit – September edition?

The goal for Web Camps is to provide great training events and an accompanying Training Kit so that web developers have thing they can rely to build websites and apps on the Microsoft Web Platform.  To be a complete web developer, you have to understand many different types of technology, not just the server side.  You also need to know technologies like jQuery, OData and when/how to leverage Web Apps like Umbraco, Kentico, DotNetNuke and more.  As things move so fast, you’ll also need to keep in touch with the latest developments in HTML 5 and how to take advantage of them in the websites you build.

So, in the September edition we are starting to introduce some new technologies areas that help you to keep on the cutting edge.  This is only the beginning and in future editions we will be constantly adding to future versions of the Training Kit.  Here are some new things I would like to highlight:

  1. jQuery

    Working with the .appendTo() team we’ve put together 3 jQuery sessions with presentations, demo scripts and source code.  This content covers some of the fundamentals of jQuery and then extends using Ajax as well as jQuery Templates and jQuery UI.
  2. IE 9 & HTML 5

    With the IE9 Beta just out the door, we’ve provided you some presentations on how to develop on IE9 as well as some of the enhancements the team have made on performance.  This is useful background material and we’ll be following this up with more content in the next release.
  3. ASP.NET MVC 2

    The ASP.NET MVC 2 content has been refreshed and we’re now basing all the content off the MVC Music Store.  There are presentations, labs and demo scripts that walk you through build the site and we’ve also provided a bonus lab on how to start adding Tests to the project.
  4. Web Apps

    The beauty of Web Apps are that they install really easily and they get you to 80% of a completed solution with little effort.  You can customize and tweak them the rest of the way for your own requirements to build complete solutions for customers is no time at all.  In this release we’ve teamed up with Umbraco, Kentico and DotNetNuke to provide presentations, videos and labs for you to get started building solutions.

  5. OData

    OData is the new standards-based web protocol for querying and updating data.  If you are writing an API for your website, it’s worth seeing how you can leverage OData to give developers a clean and familiar way to access your data.  Or, if you are interested in consuming one of the many OData services out there then there are a bunch of SDKs out there to get started in your language.  We provide an intro presentation into OData with more content coming soon to help you learn the programming syntax.

Phew – there’s lots of new content in this release and it’s been fun pulling it all together.  We’ll continue to add more as well as update existing pieces as they become out of date.  Of course, if you have feedback we’d love to here it – please get in contact here.

Don’t forget about the events – you can get expert training by registering for a Web Camp here.  We will be releasing a raft of new event dates very soon.  We are going large – stay tuned!

Read More

New: Windows Azure Storage Helper for WebMatrix

Hot on the heels of the OData Helper for WebMatrix today we are pushing out a new helper into the community.  The Windows Azure Storage Helper makes it ridiculously easy to use Windows Azure Storage (both blob and table) when building your apps.  If you’re not familiar with “cloud storage” I would recommend you take a look at this video where my pal Ryan explains what it’s all about.  In a nutshell, it provides infinitely simple yet scalable storage which is great if you are a website with lots of user generated content and you need your storage to grow auto-magically with the success of your apps.  Tables aren’t your normal relational databases – but they are great for simple data structures and they are super fast.

You can download the helper from the Codeplex website.

Get started in 60 seconds
  1. If you haven’t already got one, sign up for a Windows Azure account
  2. In the _start.cshtml file setup the helper for use with your account by adding this code:
    1. @using Microsoft.Samples.WebPages.Helpers
    2. @{
    3.     WindowsAzureStorage.AccountName = "youraccountname";
    4.     WindowsAzureStorage.AccountKey = "youraccountkey";
    5. }

  3. Download the latest Windows Azure Storage Helper Binaries
  4. In your WebMatrix project, create a folder named "bin" off the root
  5. Copy the Windows Azure Storage Helper Binaries there
  6. Check out the documentation
  7. Start using Windows Azure Storage Tables and Blobs from WebMatrix with the Helper!

There are loads of use cases out there for blob and table storage.  You just need to look at of the popular startups like Facebook, Twitter, YFrog, Foursquare, Dropbox who all use this type of storage to gain great scale and performance.

How to use the helper

With the helper we’ve provided a bunch of methods that make common operations really easy so that you can that in your WebMatrix apps.  Here are some of my favorite examples:

1. Getting a row from a table – notice how we can just dump the result into a WebGrid and have it render our table for us.

  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3.     var rows = WindowsAzureStorage.GetRows("JamesTable");
  4.     var grid = new WebGrid(rows);
  5. }

2. Updating a row in a table – first we get the individual row, making sure to pass it the partition and table name.  Next we make a change to an item, then update the table.

  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3.     var row = WindowsAzureStorage.GetRow("JamesTable", "partition1", "row1");
  4.     row.Name = "James Senior";
  5.     WindowsAzureStorage.UpdateRow("JamesTable", row);
  6. }

3. Uploading a file into blob storage – I like to use this in combination with the FileUpload helper that we ship with WebMatrix.  You can pass a stream, binary file or text string into the helper method and it’ll be placed in the blob address you specify.

  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3.     var uploadedFile = Request.Files[0];
  4.     WindowsAzureStorage.UploadBinaryToBlob("MyContainer/" + uploadedFile.FileName, uploadedFile.InputStream);
  5. }

4. To grab the blob, use one of the download methods like DownloadBlobAsText or DownloadBlobAsText.

@using Microsoft.Samples.WebPages.Helpers
@{
   // reference to my blob
   var blobRef = "MyContainer/foo.txt";

   // gets the blob as text
   var astring = WindowsAzureStorage.DownloadBlobAsText(blobRef);
  
   // gets the blob as a byte array and puts it in the
   var bytes = WindowsAzureStorage.DownloadBlobAsByteArray(blobRef);
 
   // Send the response so the user can download the file
   Response.ClearContent();
   Response.AppendHeader("Content-Type", "application/octet-stream");
   Response.AppendHeader("Content-Disposition:", String.Format("attachment; filename={0}", HttpUtility.UrlPathEncode(blobRef)));
   Response.BinaryWrite(bytes);
   Response.End();
}

Here’s a video where I walk through how to do all this good stuff in detail:

Get Microsoft Silverlight

 

Future work

There’s some more features I’d like to add to the next version of this helper. I’ve started a discussion here about that – join the conversation if you have any ideas!  Here are the current ideas:

  • Error Handling (Windows Azure Tables)
  • Pagination and continuation tokens (Windows Azure Tables)
  • Lease/Snapshot/Copy Blob operations (Windows Azure Blobs)
  • Sharing Blobs (Windows Azure Blobs)
  • Delimiters (Windows Azure Blobs)
  • Client-side ordering (Windows Azure Tables)

Read More

Announcing the OData Helper for WebMatrix Beta

I’m a big fan of working smarter, not harder.  I hope you are too.  That’s why I’m excited by the helpers in WebMatrix which are designed to make your life easier when creating websites.  There are a range of Helpers available out of the box with WebMatrix – you’ll use these day in, day out when creating websites – things like Data access, membership, WebGrid and more.  Get more information on the built-in helpers here.

It’s also possible to create your own helpers (more on that in a future blog post) to enable other people to use your own services or widgets.  We are are currently working on a community site for people to share and publicize their own helpers – stay tuned for more information on that. 

Today we are releasing the OData Helper for WebMatrix.  Designed to make it easier to use OData services in your WebMatrix website, we are open sourcing it on CodePlex and is available for you to download, use, explore and also contribute to.  You can download it from the CodePlex website.

  1. @{
  2. var result = OData.Get("http://odata.netflix.com/Catalog/Genres('Horror')/Titles","$orderby=AverageRating desc&$top=5");
  3. var grid = new WebGrid(result);
  4. }
  5.  
  6. @grid.GetHtml();

 

What is OData?

OData, or as I like to call it “Oh…. Data” Winking smile, is an open specification that makes it possible to have consistent APIs for all the different services out there.  Effectively it’s REST with a powerful query syntax that makes it easy to extract the data you want from a service.  So far there are a bunch of websites out there that have exposed their data using the spec, including Facebook, Netflix, Stackoverlow etc.  There’s a full list over at www.odata.org as well as more information on the spec itself.

Getting Started Video

Get Microsoft Silverlight

How to use the OData Helper

The OData helper supports CRUD (Create, Read, Update and Delete) methods – as you would expect -  but for reading there are a couple of syntaxes available; use the one which feels most natural to you.  Here are a couple of examples of the different syntaxes:

Get the top 5 Horror Titles (Using String Filters)

 

  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3. var result = OData.Get("http://odata.netflix.com/Catalog/Genres('Horror')/Titles","$orderby=AverageRating desc&$top=5");
  4. var grid = new WebGrid(result);
  5. }

 

Get the top 3 Movies in French (Using Query Syntax)

 

  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3. var result = OData.Open("http://odata.netflix.com/Catalog/Languages('French')/Titles")
  4. .Where("Type eq 'Movie'")
  5. .OrderBy("AverageRating desc")
  6. .Top(3)
  7. .Get();
  8. var grid = new WebGrid(result);
  9. }

 

Inserting new data
  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3.    var movie = OData.CreateEntity();
  4.    movie.Name = "OData Helpers – The Movie";
  5.    movie.ReleaseYear = 2010;
  6.    movie.BoxArt.LargeUrl = "http://cdn-4.nflximg.com/us/boxshots/tiny/5670394.jpg";
  7.    OData.Insert("http://odata.netflix.com/Catalog/Titles", movie);
  8. }

Updating existing data

 

  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3.    var movie = OData.Get("http://odata.netflix.com/Catalog/Titles('13kaI')");
  4.    movie.Name = "OData Helpers – The Movie";
  5.    OData.Update("http://odata.netflix.com/Catalog/Titles('13kaI')", movie);
  6. }

 

Deleting existing data
  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3.    OData.Delete("http://odata.netflix.com/Catalog/Titles('13kaI')");
  4. }

With Netflix service the insert, update and delete operations won’t work because they only provide read access – so the examples above are just for illustrative purposes only.

If you are new to the OData query syntax I would recommend checking out the docs that the OData team have put together.

What can you do?

There are bunch of OData services out there (full list here), why not create some wrapper classes for each service with common operations baked in so other developers don’t even have to know the syntax.  You’ll see what I mean if you explore the sample application in the download section of the CodePlex project.  We’ve included a Netflix.cs file in app_code folder – it’s just a wrapper around the OData helper class which performs some commonly used queries for the user.  I’d love to hear what you can do!

Next Steps

OData Helper v2

We’ve already cooked up some enhancements for the next version of the OData helper, you can find the list here.  If you think of anything you would like to see, please reply to the discussion in the forum!

Other Helpers

I’m now working on some other helpers which I think are pretty cool – you’ll hear more about them soon.  I’d love to hear about your ideas for helpers – maybe I can build it for you!  If you have an idea leave me a comment or send me mail – james {at} microsoft.com

Read More

Announcing the Web Camps Training Kit: July 2010 Edition

webCamps150x240

Today, we are releasing the Web Camps Training Kit: July 2010 Edition – Download it here.

The kit includes all the content we presented around the world at the recent Web Camps events; presentations, demos, labs and more.  Inside the new kit you’ll find content that covers the following technologies:

  • ASP.NET MVC 2
  • ASP.NET 4 Web Forms
  • jQuery
  • Entity Framework
  • Visual Studio 2010
  • Deployment

We’ve also included the agenda so if you want to run your own Web Camp with some of our content, you can do that. Let the team know if you are planning to run your own – we’ll help get the word out (webcamps [at] microsoft.com).

As a bonus we’ve also included scenario based content which comes in the form of complimentary slides, demos, demo scripts and hands-on-labs.  These scenarios show you how to take your own web application from an idea and prototype all the way to getting more visitors and optimizing for performance using the Microsoft Web Platform and other technologies from Microsoft.

  • Prototyping Your Web App
  • Building Your Web App
  • Enhancing Your Web App
  • Getting More Visitors to your Web App
  • Optimizing Your Web App for High Performance

We are going to be adding new scenarios as well as fresh content covering the latest on WebMatrix, ASP.NET MVC, Entity Framework, jQuery and more as well as brand new Web Camps!  Stay tuned!  Again, we’re open to hearing your feedback and requests – if there is anything you would like to see in the next version of the training kit, let us know (webcamps [at] microsoft.com).

Download the Web Camps Training Kit!

Read More