コード例 #1
0
        public static DataTableResponseModel <T> GetDataTableResponse <T>(this IQueryable <T> data,
                                                                          DataTableRequestModel dataTableRequestModel) where T : class, new()
        {
            // Count or LongCount is very annoying cause an extra evaluation.

            var totalRecords = data.Count();

            var filters = new DataTableParamModelHelper();

            var outputProperties = new DataTableTypeInfoModel <T>().Properties;

            var filteredData = filters.ApplyFiltersAndSort(dataTableRequestModel, data, outputProperties);

            var totalDisplayRecords = filteredData.Count();

            var skipped = filteredData.Skip(dataTableRequestModel.DisplayStart);

            var page = (dataTableRequestModel.DisplayLength <= 0
                ? skipped
                : skipped.Take(dataTableRequestModel.DisplayLength)).ToArray();

            var result = new DataTableResponseModel <T>
            {
                TotalRecord        = totalRecords,
                TotalDisplayRecord = totalDisplayRecords,
                Echo = dataTableRequestModel.Echo,
                Data = page.Cast <object>().ToArray()
            };

            return(result);
        }
コード例 #2
0
        public static void SetFilterValue <T>(DataTableRequestModel model, string propertyName, string value) where T : class, new()
        {
            var properties = new DataTableTypeInfoModel <T>().Properties;

            for (var i = 0; i < properties.Length; i++)
            {
                if (properties[i].PropertyInfo.Name != propertyName)
                {
                    continue;
                }

                model.SearchValues[i] = value;

                break;
            }
        }
コード例 #3
0
        internal static DataTableActionResult <T> Create <T>(DataTableRequestModel request,
                                                             DataTableResponseModel <T> response) where T : class, new()
        {
            var result = new DataTableActionResult <T>(response);

            var dictionaryTransformFunc = new DataTableTypeInfoModel <T>().ToFuncDictionary();

            result.Data =
                result
                .Data
                .Transform(dictionaryTransformFunc)
                .Transform <Dictionary <string, object>, Dictionary <string, object> >(
                    StringTransformer.StringifyValues);

            result.Data = ApplyOutputRules(request, result.Data);

            return(result);
        }
コード例 #4
0
        /// <summary>
        ///     Get Filter Values to Dictionary, key is property name and value is filter value of the property.
        /// </summary>
        /// <param name="model"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        /// <remarks>If the filter value not found, then not have the property name (key) in Dictionary</remarks>
        public static Dictionary <string, string> GetFilterValues <T>(DataTableRequestModel model) where T : class, new()
        {
            var properties = new DataTableTypeInfoModel <T>().Properties;

            var filterValues = new Dictionary <string, string>();

            for (var i = 0; i < properties.Length; i++)
            {
                var index = i;

                ActionHelper.IgnoreError(() =>
                {
                    var filterValue = model.SearchValues[index];
                    filterValues.Add(properties[index].PropertyInfo.Name, filterValue);
                });
            }

            return(filterValues);
        }
コード例 #5
0
        internal static Dictionary <string, object> MergeTransformValuesIntoDictionary <T, TTransform>(
            Func <T, TTransform> transformInput, T input)
        {
            // Get the the properties from the input as a dictionary
            var dict = new DataTableTypeInfoModel <T>().ToDictionary(input);

            // Get the transform object
            var transform = transformInput(input);

            if (transform == null)
            {
                return(dict);
            }

            foreach (var propertyInfo in transform.GetType().GetTypeInfo().GetProperties())
            {
                dict[propertyInfo.Name] = propertyInfo.GetValue(transform, null);
            }

            return(dict);
        }