﻿using System.Web.Http;
using System.Web.OData.Builder;
using System.Web.OData.Extensions;
using Microsoft.OData.Core.UriParser;
using ODataSimplifiedKeyConvention.Models;

namespace ODataSimplifiedKeyConvention
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            var builder = new ODataConventionModelBuilder();
            builder.EntitySet<Customer>("Customers");
            var model = builder.GetEdmModel();
            config.SetUrlConventions(ODataUrlConventions.ODataSimplified);
            config.MapODataServiceRoute("odata", "odata", model);

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
}
