File size: 4,794 Bytes
fc06b79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@model IEnumerable<ContactManagementAPI.Models.AppUser>
@{
    ViewData["Title"] = "Users";
    var isSuperAdmin = (ViewBag.IsSuperAdmin as bool?) == true;
}

<div class="admin-container">
    <div class="admin-header">
        <h2><i class="fas fa-users"></i> Users</h2>
        <a href="/admin/createuser" class="btn btn-primary"><i class="fas fa-user-plus"></i> New User</a>
    </div>

    @if (TempData["SuccessMessage"] != null)
    {
        <div class="alert alert-success">@TempData["SuccessMessage"]</div>
    }

    @if (TempData["ErrorMessage"] != null)
    {
        <div class="alert alert-danger">@TempData["ErrorMessage"]</div>
    }

    <div class="table-responsive">
        @if (isSuperAdmin)
        {
            <form method="post" action="/admin/deleteselectedusers" onsubmit="return confirm('Delete selected users? This cannot be undone.');">
                @Html.AntiForgeryToken()
                <div style="display:flex; gap:10px; align-items:center; margin-bottom:12px; flex-wrap:wrap;">
                    <button type="submit" class="btn btn-danger"><i class="fas fa-trash"></i> Delete Selected</button>
                    <span class="text-muted" style="font-size: 13px;">Note: Delete contacts first, then users, then user groups.</span>
                </div>
                <table class="table">
            <thead>
                <tr>
                    <th style="width: 50px; text-align:center;">Select</th>
                    <th>User Name</th>
                    <th>Full Name</th>
                    <th>Group</th>
                    <th>Admin</th>
                    <th>Status</th>
                    <th style="width: 220px;">Actions</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var user in Model)
                {
                    var isProtected = string.Equals(user.UserName, ContactManagementAPI.Services.SeedData.SuperAdminUserName, StringComparison.OrdinalIgnoreCase) ||
                                      string.Equals(user.UserName, "admin", StringComparison.OrdinalIgnoreCase);
                    <tr>
                        <td style="text-align:center; vertical-align:middle;">
                            @if (isProtected)
                            {
                                <input type="checkbox" disabled title="Protected system user" />
                            }
                            else
                            {
                                <input type="checkbox" name="userIds" value="@user.Id" />
                            }
                        </td>
                        <td>@user.UserName</td>
                        <td>@user.FullName</td>
                        <td>@(user.Group?.Name ?? "-")</td>
                        <td>@(user.IsAdmin ? "Yes" : "No")</td>
                        <td>@(user.IsActive ? "Active" : "Inactive")</td>
                        <td>
                            @if (!isProtected)
                            {
                                <a href="/admin/edituser/@user.Id" class="btn btn-sm btn-warning"><i class="fas fa-edit"></i> Edit</a>
                                <a href="/admin/userrights/@user.Id" class="btn btn-sm btn-info"><i class="fas fa-key"></i> Rights</a>
                            }
                        </td>
                    </tr>
                }
            </tbody>
                </table>
            </form>
        }
        else
        {
            <table class="table">
                <thead>
                    <tr>
                        <th>User Name</th>
                        <th>Full Name</th>
                        <th>Group</th>
                        <th>Admin</th>
                        <th>Status</th>
                        <th style="width: 220px;">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var user in Model)
                    {
                        <tr>
                            <td>@user.UserName</td>
                            <td>@user.FullName</td>
                            <td>@(user.Group?.Name ?? "-")</td>
                            <td>@(user.IsAdmin ? "Yes" : "No")</td>
                            <td>@(user.IsActive ? "Active" : "Inactive")</td>
                            <td>
                                <a href="/admin/edituser/@user.Id" class="btn btn-sm btn-warning"><i class="fas fa-edit"></i> Edit</a>
                                <a href="/admin/userrights/@user.Id" class="btn btn-sm btn-info"><i class="fas fa-key"></i> Rights</a>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        }
    </div>
</div>