public static CommonQueryParameters RemapAll(this CommonQueryParameters parameters, Dictionary <string, string> originalThenTarget)
        {
            foreach (var pair in originalThenTarget)
            {
                parameters = parameters.RemapAll(pair.Key, pair.Value);
            }

            return(parameters);
        }
        public static CommonQueryParameters RemapFilter(this CommonQueryParameters parameters, string originalField, string targetField)
        {
            var f = parameters.Filters.FirstOrDefault(_ => string.Compare(_.Field, originalField, StringComparison.InvariantCultureIgnoreCase) == 0);

            if (f != null)
            {
                f.Field = targetField;
            }

            return(parameters);
        }
        public static CommonQueryParameters RemapSortField(this CommonQueryParameters parameters, string originalField, string targetField)
        {
            if (string.IsNullOrWhiteSpace(parameters.SortBy))
            {
                return(parameters);
            }

            if (string.Compare(parameters.SortBy, originalField, StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                parameters.SortBy = targetField;
            }

            return(parameters);
        }
        public CommonQueryParameters Extend(CommonQueryParameters settings, bool isSearch = false)
        {
            var retval = new CommonQueryParameters
            {
                Skip      = settings?.Skip ?? Skip,
                Take      = settings?.Take ?? Take,
                GetAllIds = (settings?.GetAllIds).GetValueOrDefault(),
                Filters   = settings?.Filters ?? Filters
            };

            if (isSearch)
            {
                // when searching, advanced sorting will be applied
                retval.SortBy  = settings?.SortBy;
                retval.SortDir = settings?.SortDir;
            }
            else
            {
                retval.SortBy  = settings?.SortBy ?? SortBy;
                retval.SortDir = settings?.SortDir ?? SortDir;
            }

            return(retval);
        }
 public static CommonQueryParameters RemapAll(this CommonQueryParameters parameters, string originalField, string targetField)
 {
     return(parameters
            .RemapFilter(originalField, targetField)
            .RemapSortField(originalField, targetField));
 }