示例#1
0
        public static IQueryable <T> OrderBy <T>(this IQueryable <T> source, params ISorting[] sortings)
        {
            IEntitySorter <T> sorter = null;

            if (sortings != null)
            {
                foreach (var sorting in sortings)
                {
                    if (sorter == null)
                    {
                        sorter = sorting.Ascending
                            ? EntitySorter <T> .OrderBy(sorting.ColumnName)
                            : EntitySorter <T> .OrderByDescending(sorting.ColumnName);
                    }
                    else
                    {
                        sorter = sorting.Ascending
                            ? sorter.ThenBy(sorting.ColumnName)
                            : sorter.ThenByDescending(sorting.ColumnName);
                    }
                }
                return(sorter != null?sorter.Sort(source) : source);
            }
            return(source);
        }
示例#2
0
        //public static IQueryable<T> ApplyPaging<T>(this IQueryable<T> data, int itemsDisplayed, int pageSize)
        //{
        //    if (pageSize > 0 && itemsDisplayed > 0)
        //        data = data.Skip(itemsDisplayed);

        //    data = data.Take(pageSize);

        //    return data;
        //}

        //public static IQueryable<T> ApplySorting<T>(this IQueryable<T> data, string sortDirection, Expression<Func<T, string>> orderingFunction)
        //{
        //    return sortDirection == "asc" ? data.OrderBy(orderingFunction) : data.OrderByDescending(orderingFunction);
        //}


        /// <summary>
        /// 透過 <see cref="EntitySorter"/>,作到動態屬性名稱的排序
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="source"></param>
        /// <param name="criteria"></param>
        /// <param name="defaultKeySelector"></param>
        /// <param name="isDescending"></param>
        /// <returns></returns>
        public static IOrderedQueryable <TEntity> SortByCriteria <TEntity, TKey>(this IQueryable <TEntity> source,
                                                                                 QueryCriteriaModel criteria, Expression <Func <TEntity, TKey> > defaultKeySelector, bool isDescending = true)
        {
            IEntitySorter <TEntity> sorter;

            if (string.IsNullOrEmpty(criteria.Sort))
            {
                sorter = (isDescending)
                            ? EntitySorter <TEntity> .OrderByDescending(defaultKeySelector)
                            : EntitySorter <TEntity> .OrderBy(defaultKeySelector);
            }
            else
            {
                // 動態利用 EntitySorter 來排序~
                sorter = (criteria.IsDescending)
                     ? EntitySorter <TEntity> .OrderByDescending(criteria.Sort)
                     : EntitySorter <TEntity> .OrderBy(criteria.Sort);
            }

            var sortedResult = sorter.Sort(source);

            //Console.WriteLine(sortedResult.ToString());

            return(sortedResult);
        }
示例#3
0
        public void SortFieldByIndex(EntityConfig entity)
        {
            var business = new EntitySorter {
                Entity = entity
            };

            business.SortFieldByIndex(true);
        }
示例#4
0
 public async Task <CookBook> GetUserCookBookWithEagerLoadedObjectsAsyncByName(string userId, string cookBookName)
 {
     return(EntitySorter.SortRecipesInCookBook(await context
                                               .CookBooks
                                               .Where(n => n.CookBookName == cookBookName && n.OwnerId == userId)
                                               .Include(r => r.Recipes)
                                               .Include(o => o.Owner)
                                               .SingleAsync()));
 }
示例#5
0
 public async Task <CookBook> GetCookBookWithEagerLoadedObjectsAsync(int id)
 {
     return(EntitySorter.SortRecipesInCookBook(await context
                                               .CookBooks
                                               .Where(i => i.CookBookId == id)
                                               .Include(r => r.Recipes)
                                               .Include(o => o.Owner)
                                               .SingleAsync()));
 }
示例#6
0
        public async Task <List <CookBook> > GetUserCookBooksWithEagerLoadedObjectsAsync(ClaimsIdentity identity)
        {
            string currentUserId = new CurrentUserIdRetriever().GetUserId(identity);

            return(EntitySorter.SortCookBooks(await context
                                              .CookBooks
                                              .Where(i => i.OwnerId == currentUserId)
                                              .Include(r => r.Recipes)
                                              .Include(o => o.Owner)
                                              .ToListAsync()));
        }
示例#7
0
        public static IQueryable <T> OrderBy <T>(this IQueryable <T> entities, SortDirection sortDirection, string sortField)
        {
            switch (sortDirection)
            {
            case SortDirection.Asc:
                return(EntitySorter <T> .OrderBy(sortField).Sort(entities));

            case SortDirection.Desc:
                return(EntitySorter <T> .OrderByDescending(sortField).Sort(entities));

            default:
                return(entities);
            }
        }
示例#8
0
        public void SortField(EntityConfig entity)
        {
            if (entity == null ||
                MessageBox.Show($"确认修改{entity.ReadTableName}的字段顺序吗?", "对象编辑", MessageBoxButton.YesNo) !=
                MessageBoxResult.Yes)
            {
                return;
            }

            var model = new EntitySorter {
                Entity = entity
            };

            model.SortField();
        }
示例#9
0
        public void SortByGroup()
        {
            if (Context.SelectEntity == null ||
                MessageBox.Show($"确认修改{Context.SelectEntity.ReadTableName}的字段顺序吗?", "对象编辑", MessageBoxButton.YesNo) !=
                MessageBoxResult.Yes)
            {
                return;
            }

            var model = new EntitySorter {
                Entity = Context.SelectEntity
            };

            model.SortByGroup();
        }
示例#10
0
        public void SortFieldByIndex()
        {
            var result = MessageBox.Show("是按序号大小排序并从0更新序号,否仅按序号大小排序", "排序", MessageBoxButton.YesNoCancel);

            if (result == MessageBoxResult.Cancel)
            {
                return;
            }
            var tables = Context.GetSelectEntities();

            foreach (var entity in tables)
            {
                var business = new EntitySorter
                {
                    Entity = entity
                };
                business.SortFieldByIndex(result == MessageBoxResult.Yes);
            }
        }
 public static IEntitySorter <T> OrderBy <T, TKey>(
     this IEntitySorter <T> sorter,
     Expression <Func <T, TKey> > keySelector)
 {
     return(EntitySorter <T> .OrderBy(keySelector));
 }