Готовые студенты

This commit is contained in:
DyCTaTOR 2024-05-27 22:35:38 +04:00
parent 0c5cb4e121
commit b4e85ced88
6 changed files with 62 additions and 29 deletions

View File

@ -120,8 +120,31 @@ namespace UniversityClientAppWorker.Controllers
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
ViewBag.PlanOfStudys = APIClient.GetRequest<List<PlanOfStudyViewModel>>
($"api/planofstudys/getplanofstudys?userId={APIClient.User.Id}");
return View(APIClient.GetRequest<List<StudentViewModel>>($"api/student/getstudents?userId={APIClient.User.Id}")); return View(APIClient.GetRequest<List<StudentViewModel>>($"api/student/getstudents?userId={APIClient.User.Id}"));
} }
[HttpPost]
public void CreateStudent(string name, int planOfStudy, string phoneNumber)
{
if (APIClient.User == null)
{
throw new Exception("Âõîä òîëüêî àâòîðèçîâàííûì");
}
if (string.IsNullOrEmpty(name) || planOfStudy == 0 || string.IsNullOrEmpty(phoneNumber))
{
throw new Exception("Ââåäèòå ÔÈÎ, ïëàí îáó÷åíèÿ è òåëåôîí");
}
APIClient.PostRequest("api/student/createstudent", new StudentBindingModel
{
UserId = APIClient.User.Id,
Name = name,
PlanOfStudyId = planOfStudy,
PhoneNumber = phoneNumber,
});
Response.Redirect("Students");
}
[HttpGet] [HttpGet]
public IActionResult Enter() public IActionResult Enter()
{ {

View File

@ -24,7 +24,7 @@
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4 mt-2"> <div class="col-4 mt-2">
<input type="submit" value="Создать план обучения" class="btn btn-danger" /> <input type="submit" value="Создать план обучения" class="btn btn-primary" />
</div> </div>
</div> </div>
</form> </form>
@ -52,11 +52,13 @@
@Html.DisplayFor(modelItem => planOfStudy.FormOfStudy) @Html.DisplayFor(modelItem => planOfStudy.FormOfStudy)
</td> </td>
<td> <td>
<div class="btn-group">
<a asp-controller="Home" asp-action="InfoPlanOfStudy" asp-route-id="@planOfStudy.Id" class="btn btn-warning">Изменить</a> <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"> <form asp-controller="Home" asp-action="DeletePlanOfStudy" method="post">
<input type="hidden" name="id" value="@planOfStudy.Id" /> <input type="hidden" name="id" value="@planOfStudy.Id" />
<button type="submit" class="btn btn-danger">Удалить</button> <button type="submit" class="btn btn-danger">Удалить</button>
</form> </form>
</div>
</td> </td>
</tr> </tr>
} }

View File

@ -1,36 +1,36 @@
@using UniversityContracts.ViewModels @using UniversityContracts.ViewModels
@model List<StudentViewModel> @model List<StudentViewModel>
@{ @{
ViewData["Title"] = "Manage Students"; ViewData["Title"] = "Управление студентами";
} }
<div class="text-center"> <div class="text-center">
<h2 class="display-4">@ViewData["Title"]</h2> <h2 class="display-4">@ViewData["Title"]</h2>
</div> </div>
<form method="post"> <form asp-action="CreateStudent" method="post">
<div class="row"> <div class="row">
<div class="col-4">Name:</div> <div class="col-4">ФИО:</div>
<div class="col-8"> <div class="col-8">
<input type="text" name="name" id="name" class="form-control" /> <input type="text" name="name" id="name" class="form-control" />
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Plan Of Study:</div> <div class="col-4">План обучения:</div>
<div class="col-8"> <div class="col-8">
<select name="planOfStudy" id="planOfStudy" class="form-control" multiple asp-items="ViewBag.PlanOfStudys"></select> <select name="planOfStudy" id="planOfStudy" class="form-control" asp-items="@(new SelectList(ViewBag.PlanOfStudys, "Id", "Profile"))"></select>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Phone number:</div> <div class="col-4">Номер телефона:</div>
<div class="col-8"> <div class="col-8">
<textarea id="phoneNumber" name="phoneNumber" class="form-control"></textarea> <textarea id="phoneNumber" name="phoneNumber" class="form-control"></textarea>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4"> <div class="col-4 mt-2">
<input type="submit" value="Create Student" class="btn btn-primary" /> <input type="submit" value="Добавить студента" class="btn btn-primary" />
</div> </div>
</div> </div>
</form> </form>
@ -39,10 +39,10 @@
<thead> <thead>
<tr> <tr>
<th>Id</th> <th>Id</th>
<th>Name</th> <th>ФИО</th>
<th>Plan of study</th> <th>План обучения</th>
<th>Phone number</th> <th>Номер телефона</th>
<th>Actions</th> <th>Действия</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -62,11 +62,13 @@
@Html.DisplayFor(modelItem => student.PhoneNumber) @Html.DisplayFor(modelItem => student.PhoneNumber)
</td> </td>
<td> <td>
<div class="btn-group">
<a asp-controller="Home" asp-action="" asp-route-id="@student.Id" class="btn btn-warning">Изменить</a> <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"> <form asp-controller="Home" asp-action="DeletePlanOfStudy" method="post">
<input type="hidden" name="id" value="@student.Id" /> <input type="hidden" name="id" value="@student.Id" />
<button type="submit" class="btn btn-danger">Удалить</button> <button type="submit" class="btn btn-danger">Удалить</button>
</form> </form>
</div>
</td> </td>
</tr> </tr>
} }

View File

@ -25,7 +25,7 @@ namespace UniversityDatabaseImplement.Implements
public List<StudentViewModel> GetFilteredList(StudentSearchModel model) public List<StudentViewModel> GetFilteredList(StudentSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Name)) if (model == null)
{ {
return new(); return new();
} }
@ -34,8 +34,7 @@ namespace UniversityDatabaseImplement.Implements
return context.Students return context.Students
.Include(x => x.User) .Include(x => x.User)
.Where(x => x.Name .Include(x => x.PlanOfStudy)
.Contains(model.Name))
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }

View File

@ -8,7 +8,6 @@ using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels; using UniversityContracts.ViewModels;
using UniversityDataModels.Enums; using UniversityDataModels.Enums;
using UniversityDataModels.Models; using UniversityDataModels.Models;
using static System.Formats.Asn1.AsnWriter;
namespace UniversityDatabaseImplement.Models namespace UniversityDatabaseImplement.Models
{ {

View File

@ -20,7 +20,6 @@ namespace UniversityRestApi.Controllers
_logger = logger; _logger = logger;
} }
[HttpGet] [HttpGet]
public UserViewModel? LoginWorker(string login, string password) public UserViewModel? LoginWorker(string login, string password)
{ {
@ -124,5 +123,14 @@ namespace UniversityRestApi.Controllers
throw; throw;
} }
} }
[HttpGet]
public List<UserViewModel> GetAll(UserSearchModel? model)
{
try
{
return _logic.ReadList(model);
}
catch (Exception ex) { throw new Exception(); }
}
} }
} }