Exemplo n.º 1
0
        private IQueryable <Article> RestrictDate(IQueryable <Article> query, ArticleServiceOptions options)
        {
            bool hasStartDate = options.DateStart.HasValue;
            bool hasEndDate   = options.DateEnd.HasValue;

            if (!hasStartDate && !hasEndDate)
            {
                return(query);
            }
            else if (hasStartDate && hasEndDate && (options.DateStart.Value > options.DateEnd.Value))
            {
                return(query);
            }
            else
            {
                string propertyName = options.ArticleType.Value == ArticleType.Highlighted
                    ? "HighlightedAt"
                    : options.ArticleType.Value == ArticleType.Published
                        ? "PublishedAt"
                        : "CreatedAt";

                if (hasStartDate)
                {
                    query = query.Where(a => EF.Property <DateTime>(a, propertyName) >= options.DateStart.Value);
                }
                if (hasEndDate)
                {
                    query = query.Where(a => EF.Property <DateTime>(a, propertyName) <= options.DateEnd.Value);
                }
            }

            return(query);
        }
Exemplo n.º 2
0
        public ArticleServiceOptions Merge(ArticleServiceOptions options)
        {
            Offset        = Offset ?? options.Offset;
            Limit         = Limit ?? options.Limit;
            IncludeImages = IncludeImages ?? options.IncludeImages;
            SearchString  = SearchString ?? options.SearchString;
            ArticleType   = ArticleType ?? options.ArticleType;
            SearchType    = SearchType ?? options.SearchType;
            DateStart     = DateStart ?? options.DateStart;
            DateEnd       = DateEnd ?? options.DateEnd;

            return(this);
        }
Exemplo n.º 3
0
        private IQueryable <Article> RestrictSearch(IQueryable <Article> query, ArticleServiceOptions options)
        {
            string filteredSearchString = options.SearchString.Trim().ToLower();

            if (filteredSearchString.Length > 0)
            {
                bool isName    = options.SearchType.Value.HasFlag(ArticleSearchType.Name);
                bool isLead    = options.SearchType.Value.HasFlag(ArticleSearchType.Lead);
                bool isContent = options.SearchType.Value.HasFlag(ArticleSearchType.Content);
                if (isName || isLead || isContent)
                {
                    query = query.Where(a =>
                                        (isName && a.Name.ToLower().Contains(filteredSearchString)) ||
                                        (isLead && a.Lead.ToLower().Contains(filteredSearchString)) ||
                                        (isContent && a.Content.ToLower().Contains(filteredSearchString)));
                }
            }

            return(query);
        }