zhaolei
8 days ago 921de2254ff5712a44ed8575ee8efe34252f6603
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
using Bootstrap.DataAccess;
using Prow.Web.Mvc;
using System;
using System.Linq;
 
namespace Bootstrap.Admin.Query
{
    /// <summary>
    /// 用户维护查询条件类
    /// </summary>
    public class QueryUserOption : PaginationOption
    {
        /// <summary>
        /// 获得/设置 用户登录名称
        /// </summary>
        public string? Name { get; set; }
 
        /// <summary>
        /// 获得/设置 用户显示名称
        /// </summary>
        public string? DisplayName { get; set; }
 
        /// <summary>
        /// 获取用户分页数据
        /// </summary>
        /// <returns></returns>
        public QueryData<object> RetrieveData()
        {
            // int limit, int offset, string name, string price, string sort, string order
            var data = UserHelper.Retrieves();
            if (!string.IsNullOrEmpty(Name))
            {
                data = data.Where(t => t.UserName.Contains(Name, StringComparison.OrdinalIgnoreCase));
            }
            if (!string.IsNullOrEmpty(DisplayName))
            {
                data = data.Where(t => t.DisplayName.Contains(DisplayName, StringComparison.OrdinalIgnoreCase));
            }
            if (!string.IsNullOrEmpty(Search))
            {
                data = data.Where(t => t.DisplayName.Contains(Search, StringComparison.OrdinalIgnoreCase) || t.Description.Contains(Search, StringComparison.OrdinalIgnoreCase) || t.UserName.Contains(Search, StringComparison.OrdinalIgnoreCase));
            }
            var ret = new QueryData<object>();
            ret.total = data.Count();
            switch (Sort)
            {
                case "UserName":
                    data = Order == "asc" ? data.OrderBy(t => t.UserName) : data.OrderByDescending(t => t.UserName);
                    break;
                case "DisplayName":
                    data = Order == "asc" ? data.OrderBy(t => t.DisplayName) : data.OrderByDescending(t => t.DisplayName);
                    break;
                case "RegisterTime":
                    data = Order == "asc" ? data.OrderBy(t => t.RegisterTime) : data.OrderByDescending(t => t.RegisterTime);
                    break;
                case "ApprovedTime":
                    data = Order == "asc" ? data.OrderBy(t => t.ApprovedTime) : data.OrderByDescending(t => t.ApprovedTime);
                    break;
                case "ApprovedBy":
                    data = Order == "asc" ? data.OrderBy(t => t.ApprovedBy) : data.OrderByDescending(t => t.ApprovedBy);
                    break;
            }
            ret.rows = data.Skip(Offset).Take(Limit).Select(u => new
            {
                u.Id,
                u.UserName,
                u.DisplayName,
                u.RegisterTime,
                u.ApprovedTime,
                u.ApprovedBy,
                u.Description,
                u.IsReset
            });
            return ret;
        }
    }
}