移动系统liao
2025-02-17 557c2711a3e103ebc3d0492344eca9730d5e92b2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/***********************************************************************
 *            Project: baifenBinfa.Net                                     *
 *                Web: https://baifenBinfa.com                             *
 *        ProjectName: 百分兵法管理系统                               *
 *             Author:                                        *
 *              Email:                               *
 *         CreateTime: 2020-03-21 22:32:23
 *        Description: 暂无
 ***********************************************************************/
 
 
using System.Collections.Generic;
using System.Linq;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.DTO;
 
namespace CoreCms.Net.Utility.Helper
{
    public class AreaHelper
    {
        /// <summary>
        /// 迭代方法
        /// </summary>
        /// <param name="oldNavs"></param>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public static List<AreasDto> GetList(List<CoreCmsArea> oldNavs)
        {
            List<AreasDto> childList = new List<AreasDto>();
            var model1 = oldNavs.Where(p => p.depth == 1).ToList();
            var model2 = oldNavs.Where(p => p.depth == 2).ToList();
            var model3 = oldNavs.Where(p => p.depth == 3).ToList();
 
            foreach (var item in model1)
            {
                var child = new AreasDto();
                child.value = item.id;
                child.label = item.name;
 
                var fsChild = new List<AreasDto>();
                var sc = model2.Where(p => p.parentId == item.id).ToList();
                foreach (var sss in sc)
                {
                    var scItem = new AreasDto();
                    scItem.value = sss.id;
                    scItem.label = sss.name;
 
                    var scChild = new List<AreasDtoTh>();
                    var th = model3.Where(p => p.parentId == sss.id).ToList();
                    foreach (var itsmth in th)
                    {
                        scChild.Add(new AreasDtoTh()
                        {
                            label = itsmth.name,
                            value = itsmth.id
                        });
                    }
                    scItem.children = scChild;
                    fsChild.Add(scItem);
                }
 
                child.children = fsChild;
                childList.Add(child);
            }
            return childList;
        }
 
 
    }
}