Student model: Andmed
using System.ComponentModel.DataAnnotations;
namespace TallinnaRakenduslikKolledz.Models
{
public class Student
{
[Key]
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime EnrollmentDate { get; set; }
public ICollection<Enrollment>? Enrollments { get; set; }
public string? Address { get; set; }
public string? Group { get; set; }
public string? Email { get; set; }
}
}
Student View kasutas on 5 vaadet: Index, Create, Delete, Details, Edit.
Student Index on pea vaade kui lähed “õpilased” lehele
@model IEnumerable<TallinnaRakenduslikKolledz.Models.Student>
@{
ViewData["Title"] = "Õpilased";
}
<h1>Õpilaste Loend</h1>
<p>
<a asp-action="Create">Sisesta Õpilane</a>
</p>
<Table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(Model => Model.LastName)
</th>
<th>
@Html.DisplayNameFor(Model => Model.FirstName)
</th>
<th>
@Html.DisplayNameFor(Model => Model.EnrollmentDate)
</th>
<th>
@Html.DisplayNameFor(Model => Model.Email)
<th/>
<th>
Tööristad
</th>
</tr>
</thead>
<tbody>
@foreach (var student in Model)
{
<tr>
<td>
@Html.DisplayFor(modelitem => student.LastName)
</td>
<td>
@Html.DisplayFor(modelitem => student.FirstName)
</td>
<td>
@Html.DisplayFor(modelitem => student.EnrollmentDate)
</td>
<td>
@Html.DisplayFor(modelitem => student.Email)
</td>
<td>
<a asp-action="EditConfirmed" asp-route-id="@student.Id">Muuda</a>
<a asp-action="Details" asp-route-id="@student.Id">Vaata</a>
<a asp-action="Delete" asp-route-id="@student.Id">Kustuta</a>
</td>
</tr>
}
</tbody>
</Table>
Student Create vaade laseb õpilasi lisada Indexi.
@model TallinnaRakenduslikKolledz.Models.Student
@{
ViewData["Title"] = "Loo uus õpilane";
}
<h1>Loo uus Õpilane</h1>
<hr/>
<div class ="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="=text-danger"></div>
<div class="form-group" >
<label asp-for="LastName" class="control-label"></label>
<input asp-for="LastName" class="form-control"/>
<span asp-validation-for="LastName" class="text-danger"></span>
</div>
<div
class="form-group" >
<label asp-for="FirstName" class="control-label"></label>
<input asp-for="FirstName" class="form-control" />
<span asp-validation-for="FirstName" class="text-danger"></span>
</div>
<div
class="form-group" >
<label asp-for="EnrollmentDate" class="control-label"></label>
<input asp-for="EnrollmentDate" class="form-control" />
<span asp-validation-for="EnrollmentDate" class="text-danger"></span>
</div>
<div
class="form-group" >
<label asp-for="Address" class="control-label"></label>
<input asp-for="Address" class="form-control" />
<span asp-validation-for="Address" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Sisesta" class="btn btn-primary"/>
</div>
</form>
</div>
</div>
<div>
<a asp-action="Index">Mine tagasi loendisse</a>
</div>
Student Delete vaade laseb õpilasi kustutada.
@model TallinnaRakenduslikKolledz.Models.Student
@{
ViewData["Title"] = "Kustuta õpilane";
}
<h1>Kustuta õpilane</h1>
<h3>
Kas oled kindel, et tahad õpilast @Model.FirstName @Model.LastName eemaldada?
</h3>
<div>
<h4>Õpilane @Model.FirstName @Model.LastName</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">@Html.DisplayNameFor(model => model.LastName)</dt>
<dd class="col-sm-10">@Html.DisplayFor(model => model.LastName)</dd>
</dl>
<dl
class="row">
<dt class="col-sm-2">@Html.DisplayNameFor(model => model.FirstName)</dt>
<dd class="col-sm-10">@Html.DisplayFor(model => model.FirstName)</dd>
</dl>
<dl
class="row">
<dt class="col-sm-2">@Html.DisplayNameFor(model => model.EnrollmentDate)</dt>
<dd class="col-sm-10">@Html.DisplayFor(model => model.EnrollmentDate)</dd>
</dl>
<dl
class="row">
<dt class="col-sm-2">@Html.DisplayNameFor(model => model.Address)</dt>
<dd class="col-sm-10">@Html.DisplayFor(model => model.Address)</dd>
</dl>
@if (Model.Enrollments != null)
{
foreach (var courseEnrollment in Model.Enrollments)
{
<dl class="row">
<dd class="col-sm-10">@(courseEnrollment)</dd>
</dl>
}
}
@if (Model.Address != null)
{
@Model.Address;
}
@if (Model.Email != null)
{
@Model.Email;
}
@if (Model.Group != null)
{
@Model.Group;
}
</div>
<form asp-action="Delete">
<input type="hidden" asp-for="Id"/>
<input type="submit" value="kustuta õpilane" class="btn-danger"/> | <a asp-action="Index">Tühista</a>
</form>
Student Details vaade laseb õpilase admeid vaatada.
@model TallinnaRakenduslikKolledz.Models.Student
@{
ViewData["Title"] = "Õpilase vaade";
}
<h1>Õpilase vaade</h1>
<div>
<h4>Õpilane @Model.FirstName @Model.LastName</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">@Html.DisplayNameFor(model => model.LastName)</dt>
<dd class="col-sm-10">@Html.DisplayFor(model => model.LastName)</dd>
</dl>
<dl class="row">
<dt class="col-sm-2">@Html.DisplayNameFor(model => model.FirstName)</dt>
<dd class="col-sm-10">@Html.DisplayFor(model => model.FirstName)</dd>
</dl>
<dl class="row">
<dt class="col-sm-2">@Html.DisplayNameFor(model => model.EnrollmentDate)</dt>
<dd class="col-sm-10">@Html.DisplayFor(model => model.EnrollmentDate)</dd>
</dl>
<dl class="row">
<dt class="col-sm-2">@Html.DisplayNameFor(model => model.Address)</dt>
<dd class="col-sm-10">@Html.DisplayFor(model => model.Address)</dd>
</dl>
@if (Model.Enrollments != null)
{
foreach (var courseEnrollment in Model.Enrollments)
{
<dl class="row">
<dd class="col-sm-10">@(courseEnrollment)</dd>
</dl>
}
}
@if (Model.Address != null)
{
@Model.Address
;
}
@if (Model.Email != null)
{
@Model.Email
;
}
@if (Model.Group != null)
{
@Model.Group
;
}
</div>
<div>
<a asp-action="Index">Mine tagasi loendisse</a>
</div>
Student Edit vaade laseb õpilase andmeid muuta.
@model TallinnaRakenduslikKolledz.Models.Student
@{
ViewData["Title"] = "Õpilase vaade";
}
<h1>Õpilase vaade</h1>
<div>
<h4>Õpilane @Model.FirstName @Model.LastName</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">@Html.DisplayNameFor(model => model.LastName)</dt>
<dd class="col-sm-10">@Html.DisplayFor(model => model.LastName)</dd>
</dl>
<dl class="row">
<dt class="col-sm-2">@Html.DisplayNameFor(model => model.FirstName)</dt>
<dd class="col-sm-10">@Html.DisplayFor(model => model.FirstName)</dd>
</dl>
<dl class="row">
<dt class="col-sm-2">@Html.DisplayNameFor(model => model.EnrollmentDate)</dt>
<dd class="col-sm-10">@Html.DisplayFor(model => model.EnrollmentDate)</dd>
</dl>
<dl class="row">
<dt class="col-sm-2">@Html.DisplayNameFor(model => model.Address)</dt>
<dd class="col-sm-10">@Html.DisplayFor(model => model.Address)</dd>
</dl>
@if (Model.Enrollments != null)
{
foreach (var courseEnrollment in Model.Enrollments)
{
<dl class="row">
<dd class="col-sm-10">@(courseEnrollment)</dd>
</dl>
}
}
@if (Model.Address != null)
{
@Model.Address
;
}
@if (Model.Email != null)
{
@Model.Email
;
}
@if (Model.Group != null)
{
@Model.Group
;
}
</div>
<div>
<a asp-action="Index">Mine tagasi loendisse</a>
</div>
Controllers:
Seda kasutatakse, et kutsuda välja meetodid Student view’s