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

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");
}
[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()
{
if (APIClient.User == null)
@ -94,7 +120,7 @@ namespace UniversityClientAppWorker.Controllers
{
return Redirect("~/Home/Enter");
}
return View();
return View(APIClient.GetRequest<List<StudentViewModel>>($"api/student/getstudents?userId={APIClient.User.Id}"));
}
[HttpGet]
public IActionResult Enter()

View File

@ -45,19 +45,20 @@
<td>
@Html.DisplayFor(modelItem => planOfStudy.Id)
</td>
<td>
@Html.DisplayFor(modelItem => planOfStudy.Profile)
</td>
<td>
@Html.DisplayFor(modelItem => planOfStudy.FormOfStudy)
</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>
</tr>
}
}
</tbody>
</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";
}
@ -36,6 +38,7 @@
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Plan of study</th>
<th>Phone number</th>
@ -43,24 +46,30 @@
</tr>
</thead>
<tbody>
@* @foreach (var discipline in Model)
@foreach (var student in Model)
{
<tr>
<td>@discipline.Name</td>
<td>@discipline.Description</td>
<td>
@foreach (var student in discipline.Students)
{
<span>@student.Name</span>
}
@Html.DisplayFor(modelItem => student.Id)
</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>
@Html.DisplayFor(modelItem => student.Name)
</td>
<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>
</tr>
} *@
}
</tbody>
</table>

View File

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

View File

@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement
if (optionsBuilder.IsConfigured == false)
{
//Возможно понадобится писать вместо (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);
}

View File

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