Beispiel #1
0
        /// <summary>
        /// 获取Jason格式的列表数据
        /// </summary>
        /// <param name="self">是否需要对数据进行Json编码</param>
        /// <param name="returnColumnObject">不在后台进行ColumnFormatInfo的转化,而是直接输出ColumnFormatInfo的json结构到前端,由前端处理,默认False</param>
        /// <returns>Json格式的数据</returns>
        public static string GetDataJson <T>(this IBasePagedListVM <T, BaseSearcher> self, bool returnColumnObject = false) where T : TopBasePoco, new()
        {
            var sb = new StringBuilder();

            self.GetHeaders();
            if (self.IsSearched == false)
            {
                self.DoSearch();
            }
            var el = self.GetEntityList().ToList();

            //如果列表主键都为0,则生成自增主键,避免主键重复
            if (el.All(x => x.ID == Guid.Empty))
            {
                el.ForEach(x => x.ID = Guid.NewGuid());
            }
            //循环生成列表数据
            for (int x = 0; x < el.Count; x++)
            {
                var sou = el[x];
                sb.Append(self.GetSingleDataJson(sou, returnColumnObject, x));
                if (x < el.Count - 1)
                {
                    sb.Append(",");
                }
            }
            return($"[{sb.ToString()}]");
        }
        /// <summary>
        /// 获取Jason格式的列表数据
        /// </summary>
        /// <param name="self">是否需要对数据进行Json编码</param>
        /// <returns>Json格式的数据</returns>
        public static List <T> GetDataJson <T>(this IBasePagedListVM <T, BaseSearcher> self) where T : TopBasePoco, new()
        {
            var sb = new StringBuilder();

            self.GetHeaders();
            if (self.IsSearched == false)
            {
                self.DoSearch();
            }
            var el = self.GetEntityList().ToList();

            //如果列表主键都为0,则生成自增主键,避免主键重复
            if (el.All(x => x.ID == Guid.Empty))
            {
                el.ForEach(x => x.ID = Guid.NewGuid());
            }
            return(el);
        }
Beispiel #3
0
        /// <summary>
        /// 获取Jason格式的列表数据
        /// </summary>
        /// <param name="self">是否需要对数据进行Json编码</param>
        /// <returns>Json格式的数据</returns>
        public static string GetDataJson <T>(this IBasePagedListVM <T, BaseSearcher> self) where T : TopBasePoco, new()
        {
            var sb = new StringBuilder();

            self.GetHeaders();
            self.DoSearch();
            if (self.EntityDataTable != null)
            {
                for (int i = 0; i < self.EntityDataTable.Rows.Count; i++)
                {
                    sb.Append(self.GetSingleRowJson(self.EntityDataTable.Rows[i], i));
                    if (i < self.EntityDataTable.Rows.Count - 1)
                    {
                        sb.Append(",");
                    }
                }
            }
            else
            {
                var el = self.GetEntityList().ToList();
                //如果列表主键都为0,则生成自增主键,避免主键重复
                if (el.All(x => x.ID == Guid.Empty))
                {
                    el.ForEach(x => x.ID = Guid.NewGuid());
                }
                //循环生成列表数据
                for (int x = 0; x < el.Count; x++)
                {
                    var sou = el[x];
                    sb.Append(self.GetSingleDataJson(sou, x));
                    if (x < el.Count - 1)
                    {
                        sb.Append(",");
                    }
                }
            }
            return($"[{sb.ToString()}]");
        }