55 lines
2.1 KiB
C#
55 lines
2.1 KiB
C#
using System.Globalization;
|
|
using System.Web.Http;
|
|
using Kreta.Core.JsonConverter;
|
|
using Kreta.Core.ModelBinder;
|
|
using Kreta.Web.ModelBinder;
|
|
using Newtonsoft.Json;
|
|
using CoreConstants = Kreta.Core.Constants;
|
|
|
|
namespace Kreta.Web.App_Start
|
|
{
|
|
public class WebApiConfig
|
|
{
|
|
public static void Register(HttpConfiguration config)
|
|
{
|
|
// Web API configuration and services
|
|
System.Net.Http.Formatting.JsonMediaTypeFormatter formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
|
|
|
|
formatter.SerializerSettings = new JsonSerializerSettings
|
|
{
|
|
Formatting = Formatting.Indented,
|
|
TypeNameHandling = TypeNameHandling.None,
|
|
Culture = CultureInfo.CreateSpecificCulture(CoreConstants.General.HungarianCulture)
|
|
};
|
|
|
|
formatter.SerializerSettings.Converters.Add(new StringTrimConverter());
|
|
|
|
// Web API routes
|
|
config.MapHttpAttributeRoutes();
|
|
|
|
config.Routes.MapHttpRoute(
|
|
name: Constants.RouteKey.ActionApi,
|
|
routeTemplate: "api/{controller}/{action}/{id}",
|
|
defaults: new { id = RouteParameter.Optional }
|
|
);
|
|
|
|
config.Routes.MapHttpRoute(
|
|
name: Constants.RouteKey.DefaultApi,
|
|
routeTemplate: "api/{controller}/{id}",
|
|
defaults: new { id = RouteParameter.Optional }
|
|
);
|
|
|
|
config.BindParameter(typeof(double), new DoubleModelBinder());
|
|
config.BindParameter(typeof(double?), new DoubleModelBinder());
|
|
|
|
config.BindParameter(typeof(decimal), new DecimalModelBinder());
|
|
config.BindParameter(typeof(decimal?), new DecimalModelBinder());
|
|
|
|
config.BindParameter(typeof(int), new IntegerModelBinder());
|
|
config.BindParameter(typeof(int?), new IntegerModelBinder());
|
|
|
|
config.BindParameter(typeof(string), new StringTrimModelBinder());
|
|
config.BindParameter(typeof(Kendo.Mvc.UI.DataSourceRequest), new DataSourceRequestModelBinder());
|
|
}
|
|
}
|
|
}
|