Cделал учителей

This commit is contained in:
GokaPek 2024-05-26 23:51:13 +04:00
parent a939803e8c
commit d7753b4c27
5 changed files with 68 additions and 28 deletions

View File

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Reflection.Metadata;
using UniversityClientApp.Models;
using UniversityClientAppStorekeeper;
using UniversityContracts.BindingModels;
@ -81,15 +82,41 @@ namespace UniversityClientApp.Controllers
public IActionResult Statements()
{
return View();
if (APIStorekeeper.Client == null)
{
return Redirect("~/Home/Enter");
}
return View(APIStorekeeper.GetRequest<List<StatementViewModel>>($"api/statement/getstatements?teacherId={0}"));
}
public IActionResult Teachers()
[HttpGet]
public IActionResult Teachers()
{
return View();
}
if (APIStorekeeper.Client == null)
{
return Redirect("~/Home/Enter");
}
//ViewBag.Documents = APIStorekeeper.GetRequest<List<DisciplineViewModel>>("api/main/getdiscipline");
return View(APIStorekeeper.GetRequest<List<TeacherViewModel>>($"api/teacher/getteachers?userId={APIStorekeeper.Client.Id}"));
}
[HttpPost]
public void Teachers(string name, string position, string academicDegree)
{
if (APIStorekeeper.Client == null)
{
Redirect("~/Home/Enter");
}
APIStorekeeper.PostRequest("api/teacher/createteacher", new TeacherBindingModel
{
UserId = APIStorekeeper.Client.Id,
Name = name,
Position = position,
AcademicDegree = academicDegree
});
Response.Redirect("Index");
}
public IActionResult Report() {
public IActionResult Report() {
return View();
}

View File

@ -1,4 +1,6 @@
@{
@using UniversityContracts.ViewModels
@model List<TeacherViewModel>
@{
ViewData["Title"] = "Manage Teachers";
}
@ -43,35 +45,36 @@
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Academic Degree</th>
<th>Position</th>
<th>Disciplines</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@* @foreach (var teacher in Model)
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@teacher.Name</td>
<td>@teacher.AcademicDegree</td>
<td>@teacher.Position</td>
<td>
@foreach (var discipline in teacher.Disciplines)
{
<span>@discipline.Name</span>
}
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
<a asp-action="Edit" asp-route-id="@teacher.Id" class="btn btn-warning">Edit</a>
<a asp-action="Details" asp-route-id="@teacher.Id" class="btn btn-info">Details</a>
<a asp-action="Delete" asp-route-id="@teacher.Id" class="btn btn-danger">Delete</a>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.AcademicDegree)
</td>
<td>
@Html.DisplayFor(modelItem => item.Position)
</td>
<td>
</td>
</tr>
} *@
}
</tbody>
</table>

View File

@ -12,7 +12,6 @@ namespace UniversityContracts.BindingModels
{
public int Id { get; set; }
public int UserId { get; set; }
public int StorekeeperId { get; set; }
public string Name { get; set; } = string.Empty;
public string AcademicDegree { get; set; } = string.Empty;
public string Position { get; set; } = string.Empty;

View File

@ -23,18 +23,23 @@ namespace UniversityDatabaseImplement.Implements
}
public List<TeacherViewModel> GetFilteredList(TeacherSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) || string.IsNullOrEmpty(model.AcademicDegree) || string.IsNullOrEmpty(model.Position))
{
return new();
}
using var context = new UniversityDatabase();
return context.Teachers
if (!string.IsNullOrEmpty(model.Name) || !string.IsNullOrEmpty(model.AcademicDegree) || !string.IsNullOrEmpty(model.Position))
{
return context.Teachers
.Where(x => x.Name.Contains(model.Name))
.Where(x => x.Position.Contains(model.Position))
.Where(x => x.AcademicDegree.Contains(model.AcademicDegree))
.Include(x => x.User)
.Select(x => x.GetViewModel)
.ToList();
}
else { return context.Teachers.Include(x => x.User).Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public TeacherViewModel? GetElement(TeacherSearchModel model)
{

View File

@ -25,6 +25,10 @@ namespace UniversityRestApi.Controllers
{
try
{
if (teacherId == 0)
{
return _logic.ReadList(null);
}
return _logic.ReadList(new StatementSearchModel { TeacherId = teacherId });
}
catch (Exception ex)
@ -33,6 +37,8 @@ namespace UniversityRestApi.Controllers
throw;
}
}
[HttpPost]
public void CreateStatement(StatementBindingModel model)
{