Index.cshtml
3.33 KB
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
@using System.Security.Principal
@using CWA.CpoOnline.Models
@using GridMvc.Html
@model IEnumerable<CpoUserViewModel>
@{
ViewBag.Title = "Manage Users & Access";
}
<h3><i class="fa fa-user"></i> @ViewBag.Title</h3>
<div class="card mb-2">
<div class="card-body">
<div class="row">
<div class="col text-lg">
<b>Total Users :</b>
@Model.Count()
</div>
<div class="col text-right">
<a class="btn btn-success" href="@Url.Action("add","users")"><i class="fa fa-plus-circle"></i> Add User</a>
</div>
</div>
</div>
</div>
<div class="table-cpo">
@Html.Grid(Model).Columns(columns =>
{
columns.Add(row => row.FirstName).Titled("First");
columns.Add(row => row.LastName).Titled("Last");
columns.Add(row => row.Email).Titled("Email").Css("d-none d-md-table-cell");
columns.Add(row => row.IsAdministrator).RenderValueAs(row => IsAdmin(row.IsAdministrator)).Encoded(false).Sanitized(false).Titled("Admin").Css("d-none d-sm-table-cell");
columns.Add(row => row.LastLogin).RenderValueAs(row=>LocalTime(row.LastLogin)).Encoded(false).Sanitized(false).Titled("Last Login").Css("d-none d-lg-table-cell datetime");
columns.Add().RenderValueAs(row => Controls(row.Id, row.FirstName, row.LastName)).Encoded(false).Sanitized(false).Css("col-auto text-right").SetWidth(160);
}).WithPaging(25).Sortable(true).Filterable(true).WithMultipleFilters()
</div>
@helper IsAdmin(bool isAdmin)
{
if (isAdmin)
{
<i class="fa fa-fw fa-check-circle text-success"></i>
}
else
{
<i></i>
}
}
@helper LocalTime(DateTime? dt)
{
<div>@Html.Partial("_LocalTime", dt)</div>
}
@helper Controls(string userId, string fname, string lname)
{
<a class="btn btn-xs btn-secondary"
data-target="#deleteModal"
href="#"
data-href="@Url.Action("deleteuser", new {id = userId})"
data-toggle="modal"
data-userid="@userId"
title="Delete User"><span class="fa fa-trash-o"></span></a>
<span class="d-none" id="name_@userId">@fname @lname</span>
<a class="btn btn-xs btn-secondary" href="@Url.Action("edit", new { id = userId })">Edit</a>
<a class="btn btn-xs btn-primary" href="@Url.Action("access", new { id = userId })">Access</a>
}
@* Modal Delete Window *@
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
Confirm Delete
</div>
<div class="modal-body">
<b class="modal-username"></b>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<a class="btn btn-danger btn-delete">Delete User</a>
</div>
</div>
</div>
</div>
@section scripts{
<script>
$('#deleteModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var userId = button.data('userid'); // Extract info from data-* attributes
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
var modal = $(this);
var $username = $("#name_" + userId).text();
modal.find('.modal-username').text($username);
modal.find('.btn-delete').attr('href', $(event.relatedTarget).data('href'));
})
</script>
}