You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/Infrastructure/Views/Shared/Index.cshtml

110 lines
4.5 KiB

@using Infrastructure.Domain
@using System.Security.Claims
@{
var entityType = ViewData["EntityTypeExt"] as Type;
var isSoftDeleteEntity = typeof(ISoftDeleteEntity).IsAssignableFrom(entityType);
var modelType = ViewData["ModelTypeExt"] as Type;
HtmlTitle = modelType.GetDisplayName();
var entityName = entityType.Name;
var hasPermissions = (User.Identity as ClaimsIdentity).Claims.Any(o => o.Value.EndsWith($"-{entityName}"));
var start = (Model.PageIndex - 1) * Model.PageSize;
}
@Html.EditorForModel("Search")
<form action="" method="post" class="form-horizontal">
@if (hasPermissions)
{
<div class="card">
<div class="card-body">
<h3 class="card-title">
@if (User.IsInRole($"Add-{entityName}"))
{
<a class="btn btn-primary" href="@Url.Action("Add")">
新建
</a>
}
@if (isSoftDeleteEntity && User.IsInRole($"Edit-{entityName}"))
{
<button type="submit" class="confirm btn btn-primary" data-action="@Url.Action("Remove")">
移除
</button>
}
@if (isSoftDeleteEntity && User.IsInRole($"Edit-{entityName}"))
{
<button type="submit" class="confirm btn btn-primary" data-action="@Url.Action("Restore")">
还原
</button>
}
@if (User.IsInRole($"Delete-{entityName}"))
{
<button type="submit" class="confirm btn btn-danger" data-action="@Url.Action("Delete")">
删除
</button>
}
</h3>
</div>
</div>
}
<div class="card">
<div class="card-body" style="overflow-x:scroll;">
<table class="table table-striped projects">
<tr>
<th><input type="checkbox" class="select_all" /></th>
<th>行号</th>
@foreach (var item in modelType.GetProperties().Where(o => !typeof(BaseEntity).IsAssignableFrom(o.PropertyType) && o.Name != "Id" && !o.CustomAttributes.Any(t => t.AttributeType == typeof(ScaffoldColumnAttribute))))
{
if (item.PropertyType.IsGenericType && item.PropertyType.GetInterfaces().Contains(typeof(System.Collections.IEnumerable)))
{
continue;
}
<th>@item.GetDisplayName()</th>
}
@if (User.IsInRole($"Read-{entityType.Name}"))
{
<th>查看</th>
}
@if (User.IsInRole($"Edit-{entityType.Name}"))
{
<th>编辑</th>
}
</tr>
@foreach (var item in Model.List)
{
var id = modelType.GetProperty("Id").GetValue(item);
<tr>
<td title="@item.Id">
<input type="checkbox" name="list[]" value="@item.Id" />
</td>
<td>@(++start)</td>
@await Html.PartialAsync("_Index_Row", item as object)
@if (User.IsInRole($"Read-{entityName}"))
{
<td>
<a class="btn btn-info btn-sm" href="@Url.Action("Details",new { id=id})">
查看
</a>
</td>
}
@if (User.IsInRole($"Edit-{entityName}"))
{
<td>
<a class="btn btn-info btn-sm" href="@Url.Action("Edit",new { id=id})">
编辑
</a>
</td>
}
</tr>
}
</table>
</div>
@if (!HidePaged)
{
<div class="card-footer clearfix">
@(await Html.PartialAsync("_Paged"))
</div>
}
</div>
</form>
@section scripts{
@(await Html.PartialAsync("_Script"))
}