public WidgetFilter(JToken node) : base(node)
 {
     if (node["orderBy"] != null)
     {
         this._OrderBy = (WidgetOrderBy)StringEnum.Parse(typeof(WidgetOrderBy), node["orderBy"].Value <string>());
     }
 }
예제 #2
0
 public WidgetFilter(XmlElement node) : base(node)
 {
     foreach (XmlElement propertyNode in node.ChildNodes)
     {
         switch (propertyNode.Name)
         {
         case "orderBy":
             this._OrderBy = (WidgetOrderBy)StringEnum.Parse(typeof(WidgetOrderBy), propertyNode.InnerText);
             continue;
         }
     }
 }
예제 #3
0
        // Note: I would usually pass in a search object as the criteria can get quite complex.
        public async Task <Pagination <Widget> > SearchAsync(int page, int itemsPerPage, string criteria = null, bool activeOnly = false, WidgetOrderBy orderBy = WidgetOrderBy.Name)
        {
            var query = (from x in _context.Widgets
                         where
                         (
                             (String.IsNullOrEmpty(criteria) || x.Name.ToLower().Contains(criteria.ToLower())) &&
                             (activeOnly == false || x.Active == true)
                         )
                         select x);

            var count = await query.CountAsync();

            var pagination = new Pagination <Widget>(page, itemsPerPage, count);

            IOrderedQueryable <Widget> orderedQuery;

            switch (orderBy)
            {
            case WidgetOrderBy.DateCreated: orderedQuery = query.OrderBy(o => o.DateCreated); break;

            case WidgetOrderBy.Name: orderedQuery = query.OrderBy(o => o.Name); break;

            default: orderedQuery = query.OrderBy(o => o.Name); break;
            }

            pagination.Items = await orderedQuery.Skip(pagination.Skip).Take(pagination.ItemsPerPage).ToListAsync();

            return(pagination);
        }