zhaolei
2020-11-20 4a2e5b9a21940f11757be37d99f0944e240e908b
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using Bootstrap.DataAccess;
using Prow.Web.Mvc;
using System;
using System.Linq;
 
namespace Bootstrap.Admin.Query
{
    /// <summary>
    ///
    /// </summary>
    public class QueryMenuOption : PaginationOption
    {
        /// <summary>
        ///
        /// </summary>
        public string? Name { get; set; }
 
        /// <summary>
        ///
        /// </summary>
        public string? ParentName { get; set; }
 
        /// <summary>
        ///
        /// </summary>
        public string? Category { get; set; }
 
        /// <summary>
        ///
        /// </summary>
        public string? IsResource { get; set; }
 
        /// <summary>
        ///
        /// </summary>
        public string? AppId { get; set; }
 
        /// <summary>
        ///
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public QueryData<object> RetrieveData(string? userName)
        {
            var data = MenuHelper.RetrieveMenusByUserName(userName);
            if (!string.IsNullOrEmpty(ParentName))
            {
                data = data.Where(t => t.Name.Contains(ParentName, StringComparison.OrdinalIgnoreCase) || (t.ParentName != null && t.ParentName.Contains(ParentName, StringComparison.OrdinalIgnoreCase)));
            }
            if (!string.IsNullOrEmpty(Name))
            {
                data = data.Where(t => t.Name.Contains(Name, StringComparison.OrdinalIgnoreCase));
            }
            if (!string.IsNullOrEmpty(Category))
            {
                data = data.Where(t => t.Category.Contains(Category, StringComparison.OrdinalIgnoreCase));
            }
            if (!string.IsNullOrEmpty(IsResource))
            {
                data = data.Where(t => t.IsResource.ToString() == IsResource);
            }
            if (!string.IsNullOrEmpty(AppId))
            {
                data = data.Where(t => t.Application.Equals(AppId, StringComparison.OrdinalIgnoreCase));
            }
            if (!string.IsNullOrEmpty(Search))
            {
                data = data.Where(t => t.Name.Contains(Search, StringComparison.OrdinalIgnoreCase) || t.ParentName.Contains(Search, StringComparison.OrdinalIgnoreCase));
            }
            var ret = new QueryData<object>();
            ret.total = data.Count();
            switch (Sort)
            {
                case "Name":
                    data = Order == "asc" ? data.OrderBy(t => t.Name) : data.OrderByDescending(t => t.Name);
                    break;
                case "ParentName":
                    data = Order == "asc" ? data.OrderBy(t => t.ParentName) : data.OrderByDescending(t => t.ParentName);
                    break;
                case "Order":
                    data = Order == "asc" ? data.OrderBy(t => t.Application).ThenBy(t => t.ParentId).ThenBy(t => t.Order) : data.OrderBy(t => t.Application).ThenBy(t => t.ParentId).ThenByDescending(t => t.Order);
                    break;
                case "CategoryName":
                    data = Order == "asc" ? data.OrderBy(t => t.CategoryName) : data.OrderByDescending(t => t.CategoryName);
                    break;
                case "Target":
                    data = Order == "asc" ? data.OrderBy(t => t.Target) : data.OrderByDescending(t => t.Target);
                    break;
                case "IsResource":
                    data = Order == "asc" ? data.OrderBy(t => t.IsResource) : data.OrderByDescending(t => t.IsResource);
                    break;
                case "Application":
                    data = Order == "asc" ? data.OrderBy(t => t.Application) : data.OrderByDescending(t => t.Application);
                    break;
            }
            ret.rows = data.Skip(Offset).Take(Limit).Select(p => new
            {
                p.Id,
                p.ParentId,
                p.ParentName,
                p.Name,
                p.Order,
                p.Icon,
                p.Url,
                p.Category,
                p.CategoryName,
                p.Target,
                p.IsResource,
                p.Application
            });
            return ret;
        }
    }
}