/// <summary>
        /// Convert Web query predicate to LinqPredicate
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public static LinqPredicate ConvertWebPredicateToLinqPredicate(WebServiceQueryPredicate predicate)
        {
            if (predicate == null) return null;

            IList<object> LinqPredicateParameters = new List<object>();

            foreach (var param in predicate.Parameters)
            {
                try
                {
                    switch (param.Type)
                    {
                        case WebServiceQueryPredicateParameterTypes.DateTime:
                            LinqPredicateParameters.Add(Kit.ConvertType(param.Value, typeof(System.DateTime)));
                            break;
                        case WebServiceQueryPredicateParameterTypes.Decimal:
                            LinqPredicateParameters.Add(Kit.ConvertType(param.Value, typeof(System.Decimal)));
                            break;
                        case WebServiceQueryPredicateParameterTypes.Double:
                            LinqPredicateParameters.Add(Kit.ConvertType(param.Value, typeof(System.Double)));
                            break;
                        case WebServiceQueryPredicateParameterTypes.Guid:
                            LinqPredicateParameters.Add(Kit.ConvertType(param.Value, typeof(System.Guid)));
                            break;
                        case WebServiceQueryPredicateParameterTypes.Integer:
                            LinqPredicateParameters.Add(Kit.ConvertType(param.Value, typeof(System.Int32)));
                            break;
                        default:
                            LinqPredicateParameters.Add(param.Value);
                            break;

                    }
                }
                catch (Exception exp)
                {
                    throw new BadRequestException(exp.Message);
                }
            }

            LinqPredicate linqPredicate = new LinqPredicate(predicate.Expression, LinqPredicateParameters.ToArray());
            return linqPredicate;
        }
 /// <summary>
 /// Find user business objects by custom predicates.
 /// </summary>           
 /// <param name="orderby">sorting field and direction</param>
 /// <param name="pageIndex">current paging index</param>
 /// <param name="pageSize">page size</param>         
 /// <param name="predicate">linq predicate. see user properties for predicate at <see cref="RapidWebDev.Platform.Linq.User"/>.</param>
 /// <returns>Returns enumerable user objects</returns>
 public UserQueryResult QueryUsersXml(string orderby, int pageIndex, int pageSize, WebServiceQueryPredicate predicate)
 {
     return QueryUsersJson(orderby, pageIndex, pageSize, predicate);
 }
 /// <summary>
 /// Find concrete data in all types by custom predicates.
 /// </summary>
 /// <param name="orderby"></param>
 /// <param name="pageIndex"></param>
 /// <param name="pageSize"></param>
 /// <param name="predicate"></param>
 public ConcreteDataQueryResult QueryConcreteDataXml(string orderby, int pageIndex, int pageSize, WebServiceQueryPredicate predicate)
 {
     return this.QueryConcreteDataJson(orderby, pageIndex, pageSize, predicate);
 }
        /// <summary>
        /// Find concrete data in all types by custom predicates.<br />
        /// </summary>
        /// <param name="orderby"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="predicate"></param>
        public ConcreteDataQueryResult QueryConcreteDataJson(string orderby, int pageIndex, int pageSize, WebServiceQueryPredicate predicate)
        {
            int recordCount;
            try
            {
                pageSize = (pageSize == 0) ? 25 : pageSize;

                LinqPredicate linqPredicate = ServicesHelper.ConvertWebPredicateToLinqPredicate(predicate);
                IEnumerable<ConcreteDataObject> rets = concreteDataApi.FindConcreteData(linqPredicate, orderby, pageIndex, pageSize, out recordCount);

                ConcreteDataQueryResult results = new ConcreteDataQueryResult(rets.ToList())
                {
                    PageIndex = pageIndex,
                    PageSize = pageSize,
                    TotalRecordCount = recordCount
                };
                return results;
            }
            catch (ArgumentException ex)
            {
                throw new BadRequestException(string.Format(CultureInfo.InvariantCulture, ex.Message));
            }
            catch (BadRequestException bad)
            {
                throw new BadRequestException(string.Format(CultureInfo.InvariantCulture, bad.Message));
            }
            catch (FormatException formatEx)
            {
                throw new BadRequestException(string.Format(CultureInfo.InvariantCulture, formatEx.Message));
            }
            catch (Exception exp)
            {
                Logger.Instance(this).Error(exp);
                throw new InternalServerErrorException();
            }
        }
 /// <summary>
 /// Query organizations by custom predicates.
 /// </summary>
 /// <param name="orderby">sorting field and direction</param>
 /// <param name="pageIndex">current paging index</param>
 /// <param name="pageSize">page size</param>       
 /// <param name="predicate">linq predicate. see organization properties for predicate at <see cref="RapidWebDev.Platform.Linq.Organization"/>.</param>
 /// <returns>Returns organizations</returns>
 public OrganizationQueryResult QueryOrganizationsXml(string orderby, int pageIndex, int pageSize, WebServiceQueryPredicate predicate)
 {
     return QueryOrganizationsJson(orderby, pageIndex, pageSize, predicate);
 }
        /// <summary>
        /// Query role objects by custom predicates.
        /// </summary>
        /// <param name="orderby">sorting expression</param>
        /// <param name="pageIndex">current paging index</param>
        /// <param name="pageSize">page size</param>
        /// <param name="predicate">linq predicate. see role properties for predicate at <see cref="RapidWebDev.Platform.Linq.Role"/>.</param>
        /// <returns>Returns enumerable role objects</returns>
        public RoleQueryResult QueryRolesJson(string orderby, int pageIndex, int pageSize, WebServiceQueryPredicate predicate)
        {
            try
            {
                int recordCount;
                pageSize = pageSize == 0 ? 25 : pageSize;
                IEnumerable<RoleObject> results = roleApi.FindRoles(ServicesHelper.ConvertWebPredicateToLinqPredicate(predicate), orderby, pageIndex, pageSize, out recordCount);
                if (results.Count() == 0)
                    return new RoleQueryResult() { PageIndex = pageIndex, PageSize = pageSize, TotalRecordCount = recordCount };

                RoleQueryResult result = new RoleQueryResult(results.ToList())
                {
                    PageIndex = pageIndex,
                    PageSize = pageSize,
                    TotalRecordCount = recordCount
                };

                return result;
            }

            catch (ArgumentException ex)
            {
                throw new BadRequestException(string.Format(CultureInfo.InvariantCulture, ex.Message));
            }
            catch (BadRequestException bad)
            {
                throw new BadRequestException(string.Format(CultureInfo.InvariantCulture, bad.Message));
            }
            catch (FormatException formatEx)
            {
                throw new BadRequestException(string.Format(CultureInfo.InvariantCulture, formatEx.Message));
            }
            catch (Exception exp)
            {
                Logger.Instance(this).Error(exp);
                throw new InternalServerErrorException();
            }
        }
 /// <summary>
 /// Query hierarchy data in all types by custom predicates.<br/>
 /// </summary>
 /// <param name="orderby">dynamic orderby command</param>
 /// <param name="pageIndex">current paging index</param>
 /// <param name="pageSize">page size</param>
 /// <param name="predicate">linq predicate which supports properties of <see cref="RapidWebDev.Platform.HierarchyDataObject"/> for query expression.</param>
 /// <returns></returns>
 public HierarchyDataQueryResult QueryHierarchyDataXml(string orderby, int pageIndex, int pageSize, WebServiceQueryPredicate predicate)
 {
     return QueryHierarchyDataJson(orderby, pageIndex, pageSize, predicate);
 }