Index.cshtml 3.33 KB
@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">
				&nbsp;<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>
}