Начало отображение студентов

This commit is contained in:
DyCTaTOR 2024-05-27 17:32:21 +04:00
parent 75ead823e8
commit 974d8946ee
8 changed files with 105 additions and 91 deletions

View File

@ -44,7 +44,33 @@ namespace UniversityClientAppWorker.Controllers
}); });
Response.Redirect("Index"); Response.Redirect("Index");
} }
[HttpGet] [HttpPost]
public void DeletePlanOfStudy(int id)
{
if (id == 0)
{
throw new Exception("id íå ìîæåò áûòü ðàâåí 0");
}
APIClient.PostRequest("api/planofstudys/deleteplanofstudy", new PlanOfStudyBindingModel
{
Id = id
});
Response.Redirect("Index");
}
[HttpPost]
public void UpdatePlanOfStudy(int id)
{
if (id == 0)
{
throw new Exception("id íå ìîæåò áûòü ðàâåí 0");
}
APIClient.PostRequest("api/planofstudys/updateplanofstudy", new PlanOfStudyBindingModel
{
Id = id
});
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Privacy() public IActionResult Privacy()
{ {
if (APIClient.User == null) if (APIClient.User == null)
@ -94,7 +120,7 @@ namespace UniversityClientAppWorker.Controllers
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
return View(); return View(APIClient.GetRequest<List<StudentViewModel>>($"api/student/getstudents?userId={APIClient.User.Id}"));
} }
[HttpGet] [HttpGet]
public IActionResult Enter() public IActionResult Enter()

View File

@ -45,19 +45,20 @@
<td> <td>
@Html.DisplayFor(modelItem => planOfStudy.Id) @Html.DisplayFor(modelItem => planOfStudy.Id)
</td> </td>
<td>
@Html.DisplayFor(modelItem => planOfStudy.Profile)
</td>
<td>
@Html.DisplayFor(modelItem => planOfStudy.FormOfStudy)
</td>
<td>
</td>
<td> <td>
@Html.DisplayFor(modelItem => planOfStudy.Profile)
</td>
<td>
@Html.DisplayFor(modelItem => planOfStudy.FormOfStudy)
</td>
<td>
<a asp-controller="Home" asp-action="InfoPlanOfStudy" asp-route-id="@planOfStudy.Id" class="btn btn-warning">Изменить</a>
<form asp-controller="Home" asp-action="DeletePlanOfStudy" method="post">
<input type="hidden" name="id" value="@planOfStudy.Id" />
<button type="submit" class="btn btn-danger">Удалить</button>
</form>
</td> </td>
</tr> </tr>
}
}
</tbody> </tbody>
</table> </table>

View File

@ -0,0 +1,30 @@
@using UniversityContracts.ViewModels
@model PlanOfStudyViewModel
@{
ViewData["Title"] = "План обучения";
}
<div class="text-center">
<h2 class="display-4">План обучения</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Профиль:</div>
<div class="col-8"><input type="text" name="profile" value="@Model.Profile" /></div>
</div>
<div class="row">
<div class="col-4">Форма обучения:</div>
<div class="col-8"><input type="text" name="formOfStudy" value="@Model.FormOfStudy" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-danger" /></div>
</div>
<thead>
<tr>
<th>Id</th>
<th>name</th>
<th>academic degree</th>
<th>position</th>
</tr>
</thead>
</form>

View File

@ -1,60 +0,0 @@
@{
ViewData["Title"] = "Manage PlansOfStudys";
}
<div class="text-center">
<h2 class="display-4">@ViewData["Title"]</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Profile:</div>
<div class="col-8">
<input type="text" name="profile" id="profile" class="form-control" />
</div>
</div>
<div class="row">
<div class="col-4">FormOfStudy:</div>
<div class="col-8">
<input name="formOfStudy" id="formOfStudy" class="form-control" multiple asp-items="ViewBag.PlanOfStudys"></input>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Create Student" class="btn btn-primary" />
</div>
</div>
</form>
<table class="table">
<thead>
<tr>
<th>Profile</th>
<th>FormOfStudy</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@* @foreach (var discipline in Model)
{
<tr>
<td>@discipline.Name</td>
<td>@discipline.Description</td>
<td>
@foreach (var student in discipline.Students)
{
<span>@student.Name</span>
}
</td>
<td>
<a asp-action="Edit" asp-route-id="@discipline.Id" class="btn btn-warning">Edit</a>
<a asp-action="Details" asp-route-id="@discipline.Id" class="btn btn-info">Details</a>
<a asp-action="Delete" asp-route-id="@discipline.Id" class="btn btn-danger">Delete</a>
</td>
</tr>
} *@
</tbody>
</table>

View File

@ -1,4 +1,6 @@
@{ @using UniversityContracts.ViewModels
@model List<StudentViewModel>
@{
ViewData["Title"] = "Manage Students"; ViewData["Title"] = "Manage Students";
} }
@ -36,6 +38,7 @@
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th>Id</th>
<th>Name</th> <th>Name</th>
<th>Plan of study</th> <th>Plan of study</th>
<th>Phone number</th> <th>Phone number</th>
@ -43,24 +46,30 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@* @foreach (var discipline in Model) @foreach (var student in Model)
{ {
<tr> <tr>
<td>@discipline.Name</td>
<td>@discipline.Description</td>
<td> <td>
@foreach (var student in discipline.Students) @Html.DisplayFor(modelItem => student.Id)
{
<span>@student.Name</span>
}
</td> </td>
<td> <td>
<a asp-action="Edit" asp-route-id="@discipline.Id" class="btn btn-warning">Edit</a> @Html.DisplayFor(modelItem => student.Name)
<a asp-action="Details" asp-route-id="@discipline.Id" class="btn btn-info">Details</a> </td>
<a asp-action="Delete" asp-route-id="@discipline.Id" class="btn btn-danger">Delete</a> <td>
@Html.DisplayFor(modelItem => student.PlanOfStudyId)
</td>
<td>
@Html.DisplayFor(modelItem => student.PhoneNumber)
</td>
<td>
<a asp-controller="Home" asp-action="" asp-route-id="@student.Id" class="btn btn-warning">Изменить</a>
<form asp-controller="Home" asp-action="DeletePlanOfStudy" method="post">
<input type="hidden" name="id" value="@student.Id" />
<button type="submit" class="btn btn-danger">Удалить</button>
</form>
</td> </td>
</tr> </tr>
} *@ }
</tbody> </tbody>
</table> </table>

View File

@ -53,16 +53,24 @@ namespace UniversityDatabaseImplement.Implements
public List<PlanOfStudyViewModel> GetFilteredList(PlanOfStudySearchModel model) public List<PlanOfStudyViewModel> GetFilteredList(PlanOfStudySearchModel model)
{ {
if(model == null)
{
return new();
}
using var context = new UniversityDatabase(); using var context = new UniversityDatabase();
var query = context.PlanOfStudys var query = context.PlanOfStudys
.Include(x => x.Students) .Include(x => x.Students)
.Where(x => x.Id == model.Id) .Include(x => x.User)
.AsQueryable(); .AsQueryable();
if (model.Id.HasValue)
{
query = query.Where(x => x.Id == model.Id.Value);
}
if (model.DateFrom.HasValue && model.DateTo.HasValue) if (model.DateFrom.HasValue && model.DateTo.HasValue)
{ {
query = query.Where(x => model.DateFrom.Value <= x.Date && x.Date <= model.DateTo.Value); query = query.Where(x => model.DateFrom.Value <= x.Date && x.Date <= model.DateTo.Value);
} };
return new(); return query.Select(x => x.GetViewModel).ToList();
} }
public PlanOfStudyViewModel? GetElement(PlanOfStudySearchModel model) public PlanOfStudyViewModel? GetElement(PlanOfStudySearchModel model)

View File

@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
//Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); optionsBuilder.UseSqlServer(@"Data Source=DyCTaTOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }

View File

@ -43,7 +43,7 @@ namespace UniversityRestApi.Controllers
throw; throw;
} }
} }
[HttpPut] [HttpPost]
public void UpdatePlanOfStudy(PlanOfStudyBindingModel model) public void UpdatePlanOfStudy(PlanOfStudyBindingModel model)
{ {
try try
@ -56,7 +56,7 @@ namespace UniversityRestApi.Controllers
throw; throw;
} }
} }
[HttpDelete] [HttpPost]
public void DeletePlanOfStudy(PlanOfStudyBindingModel model) public void DeletePlanOfStudy(PlanOfStudyBindingModel model)
{ {
try try