Дисциплины

This commit is contained in:
GokaPek 2024-05-27 23:53:45 +04:00
parent 669f02e5aa
commit 0d7809310a
6 changed files with 54 additions and 31 deletions

View File

@ -75,9 +75,32 @@ namespace UniversityClientApp.Controllers
return; return;
} }
[HttpGet]
public IActionResult Disciplines() public IActionResult Disciplines()
{ {
return View(); if (APIStorekeeper.Client == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Teachers = APIStorekeeper.GetRequest<List<TeacherViewModel>>($"api/teacher/getteachers?userId={APIStorekeeper.Client.Id}");
return View(APIStorekeeper.GetRequest<List<DisciplineViewModel>>($"api/discipline/getdisciplines?teacherId={0}"));
}
[HttpPost]
public void Disciplines(string name, string description, DateOnly date, int teacher)
{
if (APIStorekeeper.Client == null)
{
Redirect("~/Home/Enter");
}
APIStorekeeper.PostRequest("api/discipline/creatediscipline", new DisciplineBindingModel
{
UserId = APIStorekeeper.Client.Id,
Name = name,
Description = description,
Date = date,
TeacherId = teacher,
});
Response.Redirect("Disciplines");
} }
[HttpGet] [HttpGet]

View File

@ -1,4 +1,6 @@
@{ @using UniversityContracts.ViewModels
@model List<DisciplineViewModel>
@{
ViewData["Title"] = "Manage Disciplines"; ViewData["Title"] = "Manage Disciplines";
} }
@ -20,12 +22,20 @@
<textarea name="description" id="description" class="form-control"></textarea> <textarea name="description" id="description" class="form-control"></textarea>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Students:</div> <div class="col-4">Date:</div>
<div class="col-8"> <div class="col-8">
<select id="students" name="students" class="form-control" multiple asp-items="ViewBag.Students"></select> <input type="date" name="date" id="date" class="form-control" />
</div> </div>
</div> </div>
<div class="row">
<div class="col-4">Teacher:</div>
<div class="col-8">
<select id="teacher" name="teacher" class="form-control" asp-items="@(new SelectList(@ViewBag.Teachers,"Id", "Name"))"></select>
</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">
@ -39,29 +49,29 @@
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Description</th> <th>Description</th>
<th>Students</th> <th>Date</th>
<th>Teacher Name</th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@* @foreach (var discipline in Model) @foreach (var item in Model)
{ {
<tr> <tr>
<td>@discipline.Name</td>
<td>@discipline.Description</td>
<td> <td>
@foreach (var student in discipline.Students) @Html.DisplayFor(modelItem => item.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 => item.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 => item.Date)
</td>
<td>
@Html.DisplayFor(modelItem => item.TeacherName)
</td> </td>
</tr> </tr>
} *@ }
</tbody> </tbody>
</table> </table>

View File

@ -28,12 +28,6 @@
<input type="text" name="position" id="position" class="form-control" /> <input type="text" name="position" id="position" class="form-control" />
</div> </div>
</div> </div>
<div class="row">
<div class="col-4">Disciplines:</div>
<div class="col-8">
<select id="disciplines" name="disciplines" class="form-control" multiple asp-items="ViewBag.Disciplines"></select>
</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">
@ -49,7 +43,6 @@
<th>Name</th> <th>Name</th>
<th>Academic Degree</th> <th>Academic Degree</th>
<th>Position</th> <th>Position</th>
<th>Disciplines</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -67,11 +60,6 @@
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => item.Position) @Html.DisplayFor(modelItem => item.Position)
</td>
<td>
</td> </td>
</tr> </tr>
} }

View File

@ -13,6 +13,7 @@ namespace UniversityContracts.ViewModels
public int Id { get; set; } public int Id { get; set; }
public int UserId { get; set; } public int UserId { get; set; }
public int TeacherId { get; set; } public int TeacherId { get; set; }
public string TeacherName { get; set; } = string.Empty;
[DisplayName("Название дисциплины")] [DisplayName("Название дисциплины")]
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
[DisplayName("Описание дисциплины")] [DisplayName("Описание дисциплины")]

View File

@ -105,6 +105,7 @@ namespace UniversityDatabaseImplement.Models
Id = Id, Id = Id,
UserId = UserId, UserId = UserId,
TeacherId = TeacherId, TeacherId = TeacherId,
TeacherName = Teacher.Name,
Name = Name, Name = Name,
Description = Description, Description = Description,
StudentDisciplines = StudentDisciplines, StudentDisciplines = StudentDisciplines,

View File

@ -8,11 +8,11 @@ namespace UniversityRestApi.Controllers
{ {
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
public class DisciplinesController : Controller public class DisciplineController : Controller
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IDisciplineLogic _logic; private readonly IDisciplineLogic _logic;
public DisciplinesController(IDisciplineLogic logic, ILogger<DisciplinesController> logger) public DisciplineController(IDisciplineLogic logic, ILogger<DisciplineController> logger)
{ {
_logic = logic; _logic = logic;
_logger = logger; _logger = logger;