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

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");
}
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}"));
}
[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]
public IActionResult Enter()
{

View File

@ -24,7 +24,7 @@
<div class="row">
<div class="col-8"></div>
<div class="col-4 mt-2">
<input type="submit" value="Создать план обучения" class="btn btn-danger" />
<input type="submit" value="Создать план обучения" class="btn btn-primary" />
</div>
</div>
</form>
@ -52,11 +52,13 @@
@Html.DisplayFor(modelItem => planOfStudy.FormOfStudy)
</td>
<td>
<div class="btn-group">
<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>
</div>
</td>
</tr>
}

View File

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

View File

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

View File

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

View File

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