Contact Manager Web API

This sample uses ASP.NET Web API to build a simple contact manager application. The application consists of a contact manager web API that is used by an ASP.NET MVC application, a Windows Phone application, and a Windows 8 app to display and manage a list of contacts.

C# (1.9 MB)
 
 
 
 
 
4.4 Star
(37)
93,762 times
Add to favorites
8/16/2012
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C#
@using System.Net.Http.Headers
@model Dictionary<MediaTypeHeaderValue, object>

@{
    // Group the samples into a single tab if they are the same.
    Dictionary<string, object> samples = Model.GroupBy(pair => pair.Value).ToDictionary(
        pair => String.Join(", ", pair.Select(m => m.Key.ToString()).ToArray()), 
        pair => pair.Key);
    var mediaTypes = samples.Keys;
}
<div class="mediaTypeTabs">
    <ul>
    @{ int id = 0; }
    @foreach (var mediaType in mediaTypes)
    {
        <li><a href="#@ViewData["sampleClass"]_@(id++)">@mediaType</a></li>
    }
    </ul>
    @{ id = 0; }
    @foreach (var mediaType in mediaTypes)
    {
        <div id="@ViewData["sampleClass"]_@(id++)">
            <h3>Sample:</h3>
            @{
                var sample = samples[mediaType];
                if (sample == null)
                {
                    <p>Sample not available.</p>
                }
                else
                {
                    @Html.DisplayFor(s => sample);
                }
            }
        </div>
    }
</div>