Beispiel #1
0
        /// <summary>
        /// 拖拽排序支持
        /// </summary>
        /// <typeparam name="TEntity">实体</typeparam>
        /// <typeparam name="TPrimaryKey">主键类型</typeparam>
        /// <param name="repository">仓储</param>
        /// <param name="input">输入参数</param>
        /// <returns></returns>
        protected async Task MoveTo <TEntity, TPrimaryKey>(IRepository <TEntity, TPrimaryKey> repository, MoveToInputDto <TPrimaryKey> input) where TEntity : class, IEntity <TPrimaryKey>, ISortNo
        {
            var sourceItem = await repository.GetAsync(input.SourceId);

            var targetItem = await repository.GetAsync(input.TargetId);

            switch (input.MoveToPosition)
            {
            case MoveToPositions.Up:
            {
                var list = repository.GetAll().Where(p => p.SortNo <= targetItem.SortNo);
                foreach (var item in list)
                {
                    item.SortNo--;
                }
            }
                sourceItem.SortNo = targetItem.SortNo - 1;
                break;

            case MoveToPositions.Down:
            {
                var list = repository.GetAll().Where(p => p.SortNo > targetItem.SortNo);
                foreach (var item in list)
                {
                    item.SortNo++;
                }
            }
                sourceItem.SortNo = targetItem.SortNo + 1;
                break;

            default:
                break;
            }
        }
 public async Task MoveTo(MoveToInputDto <long> input) => await base.MoveTo(_columnInfoRepository, input);