Exemplo n.º 1
0
        public Expression <Func <Exhibition, bool> > Lambdas(ExhibitionWhere Where)
        {
            Expression <Func <Exhibition, bool> > exp = LambdasHelper.True <Exhibition>();

            if (Where != null)
            {
                if (!string.IsNullOrEmpty(Where.Title))
                {
                    exp = exp.And(c => c.Title.Contains(Where.Title));
                }
                if (!string.IsNullOrEmpty(Where.Synopsis))
                {
                    exp = exp.And(c => c.Title.Contains(Where.Synopsis));
                }
                if (!string.IsNullOrEmpty(Where.Time1))
                {
                    exp = exp.And(c => c.Time >= DateTime.Parse(Where.Time1));
                }
                if (!string.IsNullOrEmpty(Where.Time2))
                {
                    exp = exp.And(c => c.Time <= DateTime.Parse(Where.Time2));
                }
            }
            return(exp);
        }
        /// <summary>
        /// Method that extends IQueryable<T> allowing to order query with request properties
        /// </summary>
        /// <typeparam name="TSource">Generic type of the entity</typeparam>
        /// <param name="source">Self IQueryable<T> instance</param>
        /// <param name="request">Self IWrapRequest<T> instance</param>
        /// <returns>Returns IQueryable instance with with the configuration for ordination</returns>
        public static IQueryable <TSource> OrderBy <TSource>(
            this IQueryable <TSource> source,
            IWrapRequest <TSource> request
            ) where TSource : class
        {
            var ordination = request.Ordination();

            string order   = ordination.Order;
            string orderBy = ordination.OrderBy;

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            Type       type   = typeof(TSource);
            var        lambda = LambdasHelper.GenereteLambdaExpression <TSource>(ref type, orderBy);
            MethodInfo orderMethod;

            if (order.ToLower().Equals(Constants.CONST_ORDENATION_ORDER_ASCENDING.ToLower()))
            {
                orderMethod = ReflectionsHelper.GetMethodFromType(typeof(Queryable), "OrderBy", 2, 2);
            }
            else
            {
                orderMethod = ReflectionsHelper.GetMethodFromType(typeof(Queryable), "OrderByDescending", 2, 2);
            }

            return((IQueryable <TSource>)orderMethod.MakeGenericMethod(typeof(TSource), type).Invoke(null, new object[] { source, lambda }));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Method that extends IQueryable<T> allowing to select results with request properties
 /// </summary>
 /// <typeparam name="TSource">Generic type of the entity</typeparam>
 /// <param name="source">Self IQueryable<T> instance</param>
 /// <param name="request">Self IWrapRequest<T> instance</param>
 /// <returns>Returns IQueryable instance with with the configuration for select</returns>
 public static IQueryable <object> Select <TSource>(
     this IQueryable <TSource> source,
     IWrapRequest <TSource> request
     ) where TSource : class
 {
     return(source.Select(LambdasHelper.GenerateSelectExpression <TSource>(request.GetSelectedModel())));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Method that extends IQueryable<T> allowing to search query with request properties
        /// </summary>
        /// <typeparam name="TSource">Generic type of the entity</typeparam>
        /// <param name="source">Self IQueryable<T> instance</param>
        /// <param name="request">Self IWrapRequest<T> instance</param>
        /// <returns>Returns IQueryable instance with with the configuration for search</returns>
        public static IQueryable <TSource> Search <TSource>(
            this IQueryable <TSource> source,
            IWrapRequest <TSource> request
            ) where TSource : class
        {
            var search = request.Search();

            var query       = search.Query;
            var queryStrict = search.Strict;
            var queryPhrase = search.Phrase;

            if (string.IsNullOrWhiteSpace(query))
            {
                return(source);
            }

            var queryTokens = TermsHelper.GetSearchTerms(query, queryPhrase);

            query = string.Join("+", queryTokens.ToArray());

            if (queryTokens.Count == 0)
            {
                return(source);
            }

            List <string> searchableProperties = new List <string>();

            searchableProperties = typeof(TSource).GetProperties().Where(x =>
                                                                         !request.IsPropertySuppressed(x.Name) && !TypesHelper.TypeIsComplex(x.PropertyType)
                                                                         ).Select(x => x.Name).ToList();

            var criteriaExp = LambdasHelper.GenerateSearchCriteriaExpression <TSource>(searchableProperties, queryTokens, queryStrict);

            return(source.Where(criteriaExp));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Method that configures suppressed properties
 /// </summary>
 /// <param name="expression">Property lambda expression</param>
 public void ConfigSuppressedProperties(
     Expression <Func <TModel, object> > expression
     )
 {
     SetConfigProperty(
         Constants.CONST_SUPRESSED,
         typeof(TModel).GetProperties().Where(p => p.Name.Equals(LambdasHelper.GetPropertyName(expression))).SingleOrDefault().Name.ToCamelCase()
         );
 }
Exemplo n.º 6
0
        /// <summary>
        /// Method that configures suppressed response properties
        /// </summary>
        /// <param name="expression">Property lambda expression</param>
        public void ConfigSuppressedResponseProperties(
            Expression <Func <TModel, object> > expression
            )
        {
            var expressionPropertyName = LambdasHelper.GetPropertyName(expression);

            SetConfigProperty(
                Constants.CONST_SUPPRESSED_RESPONSE,
                expressionPropertyName
                );
        }
Exemplo n.º 7
0
        public Expression <Func <ContentList, bool> > Lambdas(ContentListWhere Where)
        {
            Expression <Func <ContentList, bool> > exp = LambdasHelper.True <ContentList>();

            if (CookieHelper.GetCookie("ContentListShow") == "1")
            {
                exp = exp.And(c => c.IsShow == true);
            }
            if (Where == null)
            {
                return(exp);
            }
            if (!string.IsNullOrEmpty(Where.Author))
            {
                exp = exp.And(c => c.Author.Contains(Where.Author));
            }
            if (!string.IsNullOrEmpty(Where.Content))
            {
                exp = exp.And(c => c.Content.Contains(Where.Content));
            }
            if (!string.IsNullOrEmpty(Where.Title))
            {
                exp = exp.And(c => c.Title.Contains(Where.Title));
            }
            if (!string.IsNullOrEmpty(Where.Label))
            {
                exp = exp.And(c => c.Label.Contains(Where.Label));
            }
            if (!string.IsNullOrEmpty(Where.LastTime1))
            {
                exp = exp.And(c => c.LastTime >= DateTime.Parse(Where.LastTime1));
            }
            if (!string.IsNullOrEmpty(Where.LastTime2))
            {
                exp = exp.And(c => c.LastTime <= DateTime.Parse(Where.LastTime2));
            }
            if (!string.IsNullOrEmpty(Where.Time1))
            {
                exp = exp.And(c => c.Time >= DateTime.Parse(Where.Time1));
            }
            if (!string.IsNullOrEmpty(Where.Time2))
            {
                exp = exp.And(c => c.Time <= DateTime.Parse(Where.Time2));
            }
            return(exp);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Method that extends IQueryable<T> allowing to filter query with request properties
        /// </summary>
        /// <typeparam name="TSource">Generic type of the entity</typeparam>
        /// <param name="source">Self IQueryable<T> instance</param>
        /// <param name="request">Self IWrapRequest<T> instance</param>
        /// <returns>Returns IQueryable instance with with the configuration for filter</returns>
        public static IQueryable <TSource> Filter <TSource>(
            this IQueryable <TSource> source,
            IWrapRequest <TSource> request
            ) where TSource : class
        {
            var filterProperties = request.FilterProperties();

            if (filterProperties == null || filterProperties.Count == 0)
            {
                return(source);
            }

            request.RequestObject.SetValue(Constants.CONST_FILTER_PROPERTIES.ToCamelCase(), filterProperties);

            var filterDictionary = new Dictionary <string, object>();

            filterProperties.ForEach(filter => filterDictionary.Add(filter.Name, filter.Value));

            var criteriaExp = LambdasHelper.GenerateFilterCriteriaExpression <TSource>(filterDictionary);

            return(source.Where(criteriaExp));
        }