Многие-ко-многим начало

This commit is contained in:
GokaPek 2024-05-28 17:05:02 +04:00
parent 96a5f2c708
commit 74537d905a
2 changed files with 78 additions and 3 deletions

View File

@ -5,7 +5,10 @@ using UniversityClientApp.Models;
using UniversityClientAppStorekeeper;
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityDatabaseImplement.Models;
using UniversityDatabaseImplement;
using UniversityDataModels.Enums;
using UniversityDataModels.Models;
namespace UniversityClientApp.Controllers
{
@ -83,25 +86,77 @@ namespace UniversityClientApp.Controllers
return Redirect("~/Home/Enter");
}
ViewBag.Teachers = APIStorekeeper.GetRequest<List<TeacherViewModel>>($"api/teacher/getteachers?userId={APIStorekeeper.Client.Id}");
ViewBag.Students = APIStorekeeper.GetRequest<List<StudentViewModel>>($"api/student/getstudents?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)
public void Disciplines(string name, string description, DateOnly date, int teacher, List<int> studentIds)
{
if (APIStorekeeper.Client == null)
{
Redirect("~/Home/Enter");
}
APIStorekeeper.PostRequest("api/discipline/creatediscipline", new DisciplineBindingModel
var disciplineModel = new DisciplineBindingModel
{
UserId = APIStorekeeper.Client.Id,
Name = name,
Description = description,
Date = date,
TeacherId = teacher,
});
StudentDisciplines = studentIds.ToDictionary(id => id, id => (IStudentModel)null)
// íå ïðàâèëüíî
};
APIStorekeeper.PostRequest("api/discipline/creatediscipline", disciplineModel);
Response.Redirect("Disciplines");
}
/*public IActionResult Disciplines(string name, string description, DateOnly date, int teacher, List<int> studentIds)
{
if (APIStorekeeper.Client == null)
{
return RedirectToAction("Enter", "Home");
}
// Ïðåäïîëàãàåì, ÷òî ó âàñ åñòü äîñòóï ê êîíòåêñòó áàçû äàííûõ UniversityDatabase
using (var context = new UniversityDatabase())
{
// Ñîçäàåì ñëîâàðü äëÿ õðàíåíèÿ ñòóäåíòîâ
var studentDisciplines = new Dictionary<int, IStudentModel>();
// Èòåðèðóåì ïî ñïèñêó èäåíòèôèêàòîðîâ ñòóäåíòîâ
foreach (var studentId in studentIds)
{
// Ïîëó÷àåì ñòóäåíòà èç áàçû äàííûõ èëè ñîçäàåì íîâûé ýêçåìïëÿð Student
// Âàì íóæíî áóäåò çàïîëíèòü íåîáõîäèìûå ñâîéñòâà, òàêèå êàê UserId, PlanOfStudyId, Name è PhoneNumber
var student = context.Students.Find(studentId);
// Äîáàâëÿåì ñòóäåíòà â ñëîâàðü
studentDisciplines.Add(studentId, student);
}
var disciplineModel = new DisciplineBindingModel
{
UserId = APIStorekeeper.Client.Id,
Name = name,
Description = description,
Date = date,
TeacherId = teacher,
StudentDisciplines = studentDisciplines
};
APIStorekeeper.PostRequest("api/discipline/creatediscipline", disciplineModel);
return RedirectToAction("Disciplines");
}
}*/
[HttpGet]
public IActionResult Statements()

View File

@ -1,5 +1,8 @@
@using UniversityContracts.ViewModels
@model List<DisciplineViewModel>
@{
List<StudentViewModel> students = ViewBag.Students;
}
@{
ViewData["Title"] = "Manage Disciplines";
}
@ -36,6 +39,23 @@
</div>
</div>
<div class="row">
<div class="col-4">Students:</div>
<div class="col-8">
@foreach (var student in students)
{
<div class="form-check">
<input class="form-check-input" type="checkbox" name="studentIds" value="@student.Id" id="student-@student.Id">
<label class="form-check-label" for="student-@student.Id">
@student.Name
</label>
</div>
}
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4">