zhaolei
2020-11-20 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
78
79
80
81
82
83
84
85
86
87
88
89
90
using Bootstrap.Admin.Pages.Components;
using Bootstrap.DataAccess;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using System.Linq;
 
namespace Bootstrap.Admin.Pages.Views.Admin.Components
{
    /// <summary>
    /// 消息通知组件
    /// </summary>
    public class NotificationsBase : ComponentBase
    {
        /// <summary>
        /// 获得 授权服务
        /// </summary>
        [Inject]
        protected AuthenticationStateProvider? AuthenticationStateProvider { get; set; }
 
        /// <summary>
        /// 获得/设置 编辑类型实例
        /// </summary>
        protected User DataContext { get; set; } = new User();
 
        /// <summary>
        /// 获得/设置 用户登录名
        /// </summary>
        protected string? UserName { get; set; }
 
        /// <summary>
        /// 获得/设置 Table 实例
        /// </summary>
 
        protected TableBase<User>? Table { get; set; }
 
        /// <summary>
        /// OnInitializedAsync 方法
        /// </summary>
        /// <returns></returns>
        protected override async System.Threading.Tasks.Task OnInitializedAsync()
        {
            if (AuthenticationStateProvider != null)
            {
                var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
                UserName = state?.User.Identity.Name;
            }
        }
 
        /// <summary>
        /// 数据查询方法
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        protected QueryData<User> Query(QueryPageOptions options)
        {
            var data = UserHelper.RetrieveNewUsers();
            return new QueryData<User>()
            {
                Items = data,
                PageIndex = 1,
                PageItems = data.Count(),
                TotalCount = data.Count()
            };
        }
 
        /// <summary>
        /// 批准新用户方法
        /// </summary>
        protected void Approve(string? userId)
        {
            if (!string.IsNullOrEmpty(userId) && !string.IsNullOrEmpty(UserName))
            {
                UserHelper.Approve(userId, UserName);
                Table?.Query();
            }
        }
 
        /// <summary>
        /// 拒绝新用户方法
        /// </summary>
        protected void Reject(string? userId)
        {
            if (!string.IsNullOrEmpty(userId) && !string.IsNullOrEmpty(UserName))
            {
                UserHelper.Reject(userId, UserName);
                Table?.Query();
            }
        }
    }
}