Exemplo n.º 1
0
        public ContentQueryResult Items(HttpContextBase context)
        {
            var request   = context.Request;
            var list      = this.Parent;
            var _query    = new ContentQuery(request);
            var _filter   = "";
            var routeData = request.RequestContext.RouteData.Values;

            if (routeData.ContainsKey("tags") || routeData.ContainsKey("achrives"))
            {
                if (routeData.ContainsKey("achrives"))
                {
                    var year  = (int)routeData["year"];
                    var month = (int)routeData["month"];
                    _filter = string.Format("published >=#{0}-{1}-01# AND Published <=#{0}-{1}-30#", year, month);
                }
                else
                {
                    var tag = routeData["tag"];
                    _filter = "tags LIKE '%" + tag + "%'";
                }
            }
            else
            {
                if (list.IsModerated)
                {
                    var ext = "";
                    if (Parent.IsHierarchy && string.IsNullOrEmpty(context.Request.QueryString["parentId"]))
                    {
                        ext = " AND parentId='" + Guid.Empty.ToString() + "'";
                    }

                    if (list.IsOwner(context) || (request.IsAuthenticated && list.IsModerator(context.User.Identity.Name)))
                    {
                        //Here is Moderator
                        _filter = "(" + DataNames.IsPublished + "=True And " + DataNames.Owner + "<>'" + context.User.Identity.Name + "')" +
                                  " Or " + DataNames.Owner + "='" + context.User.Identity.Name + "'";
                    }
                    else
                    {
                        _filter = "(" + DataNames.IsPublished + "=True" +
                                  " And " + DataNames.State + "=" + ((int)ModerateStates.Approved).ToString() +
                                  ") Or " + DataNames.Owner + "='" + context.User.Identity.Name + "'";
                    }

                    if (!string.IsNullOrEmpty(ext))
                    {
                        _filter = "(" + _filter + ") " + ext;
                    }
                }
                else
                {
                    if (Parent.IsHierarchy && string.IsNullOrEmpty(context.Request.QueryString["parentId"]))
                    {
                        _filter = DataNames.IsPublished + "=True" + " AND parentId='" + Guid.Empty.ToString() + "'";
                    }
                    else
                    {
                        _filter = DataNames.IsPublished + "=True";
                    }
                }
            }


            if (string.IsNullOrEmpty(_query.Filter) && !string.IsNullOrEmpty(_filter))
            {
                _query.Filter = _filter;
            }

            if (string.IsNullOrEmpty(_query.Sort) && !string.IsNullOrEmpty(this.DefaultQuery.Sort))
            {
                _query.Sort = this.DefaultQuery.Sort;
            }

            return(Items(_query));
        }
Exemplo n.º 2
0
 public ContentQueryResult GetItems(ContentQuery query = null)
 {
     return(this.Items(query));
 }
Exemplo n.º 3
0
        public ContentQueryResult Items(ContentQuery query = null)
        {
            var dt       = GetDataTable();
            var dataView = dt.DefaultView;

            dataView.AllowDelete      = false;
            dataView.AllowEdit        = false;
            dataView.AllowNew         = false;
            dataView.ApplyDefaultSort = false;

            if (query != null)
            {
                if (!string.IsNullOrEmpty(query.Sort))
                {
                    dataView.Sort = query.Sort;
                }

                if (!string.IsNullOrEmpty(query.Filter))
                {
                    dataView.RowFilter = FormatFilter(query.Filter);
                }
            }
            else
            {
                query         = this.DefaultQuery;
                dataView.Sort = query.Sort;
            }

            query.Total = dataView.Count;
            var resultItems = new List <ContentQueryResultItem>();

            if (query.Size == 0 && this.AllowPaging)
            {
                query.Size = this.PageSize;
            }

            var counter = dataView.Count;

            #region groupby

            //dataView.AsQueryable()
            //var selQuery=from r in dataView
            //           group r by r.f
            #endregion

            if (query.Size > 0)
            {
                counter = query.Index <= 1 ? query.Size : ((query.Index - 1) * query.Size + query.Size);
            }

            var skip = query.Index <= 1 ? 0 : (query.Index - 1) * query.Size;

            for (int i = skip; i < counter; i++)
            {
                if (i >= dataView.Count)
                {
                    break;
                }

                var     rowView = dataView[i];
                dynamic rowData = new ExpandoObject();
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    var col = dt.Columns[j];
                    ((IDictionary <String, Object>)rowData).Add(col.ColumnName, rowView[col.ColumnName]);
                }
                resultItems.Add(new ContentQueryResultItem(this, rowData));
            }

            return(new ContentQueryResult()
            {
                List = this.Parent,
                Items = resultItems,
                View = this,
                Query = query
            });
        }