private void ReadConfiguration(ref IFilterRequest message, NameValueCollection collection) { Dictionary <string, object> otherValues = new Dictionary <string, object>(); foreach (string key in collection.AllKeys) { if (key == "draw") { message.Draw = GetValue <int>(collection[key]); } else if (key == "start") { message.Start = GetValue <int>(collection[key]); } else if (key == "length") { message.Length = GetValue <int>(collection[key]); } else if (key == "search[value]") { message.Search.Value = GetValue <string>(collection[key]); } else if (key == "search[regex]") { message.Search.IsRegex = GetValue <bool>(collection[key]); } else if (key.StartsWith("order")) { ReadSortConfiguration(ref message, key, collection[key]); } else if (key.StartsWith("columns")) { ReadColumnConfiguration(ref message, key, collection[key]); } else { otherValues.Add(key, collection[key]); } } FormConvertHelper.ReadForm(message, otherValues, prop => FormConvertHelper.GetPropertiesFromType(typeof(IFilterRequest)).Select(x => x.Name).Contains(prop.Name)); }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { IValueProvider valueProvider = bindingContext.ValueProvider; IFilterRequest message = Activator.CreateInstance(_concreteType) as IFilterRequest; message.Draw = GetValue <int>(valueProvider, "sEcho"); message.Start = GetValue <int>(valueProvider, "iDisplayStart"); message.Length = GetValue <int>(valueProvider, "iDisplayLength"); message.Search.Value = GetValue <string>(valueProvider, "sSearch"); message.Search.IsRegex = GetValue <bool>(valueProvider, "bEscapeRegex"); message.Sort.Capacity = GetValue <int>(valueProvider, "iSortingCols"); for (int i = 0; i < message.Sort.Capacity; i++) { ISort sort = new Sort(); sort.Column = GetValue <int>(valueProvider, "iSortCol_" + i); sort.Direction = GetValue <string>(valueProvider, "sSortDir_" + i).AsSortDirection(); message.Sort.Add(sort); } int totalColumns = GetValue <int>(valueProvider, "iColumns"); for (int i = 0; i < totalColumns; i++) { IColumn column = new Column(); column.Data = GetValue <string>(valueProvider, "mDataProp_" + i); column.Searchable = GetValue <bool>(valueProvider, "bSearchable_" + i); column.Sortable = GetValue <bool>(valueProvider, "bSortable_" + i); column.Search.Value = GetValue <string>(valueProvider, "sSearch_" + i); column.Search.IsRegex = GetValue <bool>(valueProvider, "bRegex_" + i); message.Columns.Add(i, column); } FormConvertHelper.ReadForm(message, valueProvider, prop => FormConvertHelper.GetPropertiesFromType(typeof(IFilterRequest)).Select(x => x.Name).Contains(prop.Name)); return(message); }