@@ -14,99 +14,99 @@ public object BindModel(ControllerContext controllerContext, ModelBindingContext
1414 {
1515 FilterRequest message = new FilterRequest ( ) ;
1616
17- ReadConfiguration ( ref message , controllerContext . HttpContext . Request . QueryString ) ;
18- ReadConfiguration ( ref message , controllerContext . HttpContext . Request . Form ) ;
17+ ReadConfiguration ( ref message , controllerContext . HttpContext . Request . QueryString ) ;
18+ ReadConfiguration ( ref message , controllerContext . HttpContext . Request . Form ) ;
1919
2020 return message ;
2121 }
2222
23- private void ReadConfiguration ( ref FilterRequest message , NameValueCollection collection )
24- {
25- foreach ( string key in collection . AllKeys )
26- {
27- if ( key == "draw" )
28- message . Draw = GetValue < int > ( collection [ key ] ) ;
29-
30- else if ( key == "start" )
31- message . Start = GetValue < int > ( collection [ key ] ) ;
32-
33- else if ( key == "length" )
34- message . Length = GetValue < int > ( collection [ key ] ) ;
35-
36- else if ( key == "search[value]" )
37- message . Search . Value = GetValue < string > ( collection [ key ] ) ;
38-
39- else if ( key == "search[regex]" )
40- message . Search . IsRegex = GetValue < bool > ( collection [ key ] ) ;
41-
42- else if ( key . StartsWith ( "order" ) )
43- ReadSortConfiguration ( ref message , key , collection [ key ] ) ;
44-
45- else if ( key . StartsWith ( "columns" ) )
46- ReadColumnConfiguration ( ref message , key , collection [ key ] ) ;
47- }
48- }
49-
50- private void ReadSortConfiguration ( ref FilterRequest message , string key , object value )
51- {
52- Match match = Regex . Match ( key , @"order\[([0-9]+)\](.+)" ) ;
53- if ( match . Success && match . Groups . Count == 3 )
54- {
55- int index = Convert . ToInt32 ( match . Groups [ 1 ] . Value ) ;
56- string propertyName = match . Groups [ 2 ] . Value ;
57-
58- while ( index >= message . Sort . Count )
59- message . Sort . Add ( new Sort ( ) ) ;
60-
61- if ( propertyName == "[column]" )
62- message . Sort [ index ] . Column = GetValue < int > ( value ) ;
63-
64- else if ( propertyName == "[dir]" )
65- message . Sort [ index ] . Direction = GetValue < string > ( value ) . AsSortDirection ( ) ;
66- }
67- }
68-
69- private void ReadColumnConfiguration ( ref FilterRequest message , string key , object value )
70- {
71- Match match = Regex . Match ( key , @"columns\[([0-9]+)\](.+)" ) ;
72- if ( match . Success && match . Groups . Count == 3 )
73- {
74- int index = Convert . ToInt32 ( match . Groups [ 1 ] . Value ) ;
75- string propertyName = match . Groups [ 2 ] . Value ;
76-
77- Column currentColumn = null ;
78-
79- if ( ! message . HasColumn ( index ) )
80- {
81- currentColumn = new Column ( ) ;
82- message . Columns . Add ( index , currentColumn ) ;
83- }
84- else
85- currentColumn = message . GetColumn ( index ) ;
86-
87- if ( propertyName == "[data]" )
88- currentColumn . Data = GetValue < string > ( value ) ;
89-
90- else if ( propertyName == "[name]" )
91- currentColumn . Name = GetValue < string > ( value ) ;
92-
93- else if ( propertyName == "[searchable]" )
94- currentColumn . Searchable = GetValue < bool > ( value ) ;
95-
96- else if ( propertyName == "[orderable]" )
97- currentColumn . Sortable = GetValue < bool > ( value ) ;
98-
99- else if ( propertyName == "[search][value]" )
100- currentColumn . Search . Value = GetValue < string > ( value ) ;
101-
102- else if ( propertyName == "[search][regex]" )
103- currentColumn . Search . IsRegex = GetValue < bool > ( value ) ;
104- }
105- }
106-
107- private static T GetValue < T > ( object value )
108- {
109- return ( value == null ) ? default ( T ) : ( T ) Convert . ChangeType ( value , typeof ( T ) ) ;
110- }
23+ private void ReadConfiguration ( ref FilterRequest message , NameValueCollection collection )
24+ {
25+ foreach ( string key in collection . AllKeys )
26+ {
27+ if ( key == "draw" )
28+ message . Draw = GetValue < int > ( collection [ key ] ) ;
29+
30+ else if ( key == "start" )
31+ message . Start = GetValue < int > ( collection [ key ] ) ;
32+
33+ else if ( key == "length" )
34+ message . Length = GetValue < int > ( collection [ key ] ) ;
35+
36+ else if ( key == "search[value]" )
37+ message . Search . Value = GetValue < string > ( collection [ key ] ) ;
38+
39+ else if ( key == "search[regex]" )
40+ message . Search . IsRegex = GetValue < bool > ( collection [ key ] ) ;
41+
42+ else if ( key . StartsWith ( "order" ) )
43+ ReadSortConfiguration ( ref message , key , collection [ key ] ) ;
44+
45+ else if ( key . StartsWith ( "columns" ) )
46+ ReadColumnConfiguration ( ref message , key , collection [ key ] ) ;
47+ }
48+ }
49+
50+ private void ReadSortConfiguration ( ref FilterRequest message , string key , object value )
51+ {
52+ Match match = Regex . Match ( key , @"order\[([0-9]+)\](.+)" ) ;
53+ if ( match . Success && match . Groups . Count == 3 )
54+ {
55+ int index = Convert . ToInt32 ( match . Groups [ 1 ] . Value ) ;
56+ string propertyName = match . Groups [ 2 ] . Value ;
57+
58+ while ( index >= message . Sort . Count )
59+ message . Sort . Add ( new Sort ( ) ) ;
60+
61+ if ( propertyName == "[column]" )
62+ message . Sort [ index ] . Column = GetValue < int > ( value ) ;
63+
64+ else if ( propertyName == "[dir]" )
65+ message . Sort [ index ] . Direction = GetValue < string > ( value ) . AsSortDirection ( ) ;
66+ }
67+ }
68+
69+ private void ReadColumnConfiguration ( ref FilterRequest message , string key , object value )
70+ {
71+ Match match = Regex . Match ( key , @"columns\[([0-9]+)\](.+)" ) ;
72+ if ( match . Success && match . Groups . Count == 3 )
73+ {
74+ int index = Convert . ToInt32 ( match . Groups [ 1 ] . Value ) ;
75+ string propertyName = match . Groups [ 2 ] . Value ;
76+
77+ Column currentColumn = null ;
78+
79+ if ( ! message . HasColumn ( index ) )
80+ {
81+ currentColumn = new Column ( ) ;
82+ message . Columns . Add ( index , currentColumn ) ;
83+ }
84+ else
85+ currentColumn = message . GetColumn ( index ) ;
86+
87+ if ( propertyName == "[data]" )
88+ currentColumn . Data = GetValue < string > ( value ) ;
89+
90+ else if ( propertyName == "[name]" )
91+ currentColumn . Name = GetValue < string > ( value ) ;
92+
93+ else if ( propertyName == "[searchable]" )
94+ currentColumn . Searchable = GetValue < bool > ( value ) ;
95+
96+ else if ( propertyName == "[orderable]" )
97+ currentColumn . Sortable = GetValue < bool > ( value ) ;
98+
99+ else if ( propertyName == "[search][value]" )
100+ currentColumn . Search . Value = GetValue < string > ( value ) ;
101+
102+ else if ( propertyName == "[search][regex]" )
103+ currentColumn . Search . IsRegex = GetValue < bool > ( value ) ;
104+ }
105+ }
106+
107+ private static T GetValue < T > ( object value )
108+ {
109+ return ( value == null ) ? default ( T ) : ( T ) Convert . ChangeType ( value , typeof ( T ) ) ;
110+ }
111111 }
112112}
0 commit comments