using System.Net.Http.Formatting;
using System.Web.Http;

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

            // Web API routes
            config.MapHttpAttributeRoutes();

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

            //szukam formatu XML i ustawiam jako pierwszy
            for (int i = 0; i < config.Formatters.Count; ++i)
            {
                MediaTypeFormatter format = config.Formatters[i];
                if (format is XmlMediaTypeFormatter)
                {
                    config.Formatters.Remove(format);
                    config.Formatters.Insert(0, format);
                    break;
                }
            }
        }
    }
}
