@model ResourceModel
@* Generated from Custom Template. *@
@* Model namespace using directive should be added to _ViewImports.cshtml. *@
@{
var containerDivClass = "container";
var dateTimePickerClass = "datetimepicker";
}
@{
ViewData["Title"] = "Resource Edit";
}
<div class="@containerDivClass">
<h3>@ViewData["Title"]</h3>
<hr />
</div>
@if (Model is not null)
{
<div class="@containerDivClass">
@if (TempData["Message"] is not null)
{
<p class="text-danger">
@TempData["Message"]
</p>
}
<form asp-action="Edit" autocomplete="off">
@Html.AntiForgeryToken()
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="row mb-3">
<label asp-for="Title" class="col-2 col-form-label fw-bold"></label>
<div class="col-10">
<input asp-for="Record.Title" class="form-control" />
<span asp-validation-for="Record.Title" class="text-danger"></span>
</div>
</div>
<div class="row mb-3">
<label asp-for="Content" class="col-2 col-form-label fw-bold"></label>
<div class="col-10">
<input asp-for="Record.Content" class="form-control" />
<span asp-validation-for="Record.Content" class="text-danger"></span>
</div>
</div>
@*
The application users with role "User" shouldn't give scores to their resources.
They also shouldn't set a date since it will be automatically assigned in the action.
They also shouldn't select users since their user ids will be automatically assigned in the action.
So these fields should be only shown to the application users with role "Admin".
*@
@if (User.IsInRole("Admin"))
{
<div class="row mb-3">
<label asp-for="Score" class="col-2 col-form-label fw-bold"></label>
<div class="col-10">
<input asp-for="Record.Score" class="form-control" />
<span asp-validation-for="Record.Score" class="text-danger"></span>
</div>
</div>
<div class="row mb-3">
<label asp-for="Date" class="col-2 col-form-label fw-bold"></label>
<div class="col-10">
<input asp-for="Record.Date" class="form-control @dateTimePickerClass" type="text" />
<span asp-validation-for="Record.Date" class="text-danger"></span>
</div>
</div>
@* Can be uncommented and used for many to many relationships. {Entity} may be replaced with the related entiy name in the controller and views. *@
@*
The ViewData set in the action will be filled as items of the select HTML tag with multiple attribute.
The selected user Id values will be sent to the post action with the resource model's Record.UserIds property.
*@
<div class="row mb-3">
<label asp-for="UserIds" class="col-2 col-form-label fw-bold"></label>
<div class="col-10">
<select multiple asp-for="UserIds" class="form-select" asp-items="ViewBag.UserIds"></select> @* list box *@
<span asp-validation-for="UserIds" class="text-danger"></span>
</div>
</div>
}
<input type="hidden" asp-for="Record.Id" />
<hr />
<div class="row mb-3">
<div class="offset-2 col-10">
<button type="submit" class="btn btn-primary">Save</button>
<button type="reset" class="btn btn-outline-primary">Reset</button>
@*
for User role if application user Id is in the UserIds collection of the resource item,
show Delete link since the resource item belongs to the user who created the resource,
for Admin role, show Delete link
*@
@if (User.IsInRole("Admin") ||
(User.IsInRole("User") && Model.UserIds.Contains(Convert.ToInt32(User.Claims.SingleOrDefault(c => c.Type == "Id").Value))))
{
<a asp-action="Delete" asp-route-id="@Model.Record.Id">Delete</a>
@:
}
<a asp-action="Index">Back to List</a>
</div>
</div>
</form>
</div>
}
@section Scripts {
<partial name="_DateTimePicker" />
}