Круд дисциплин готово Егор
This commit is contained in:
parent
d75f7d7ae5
commit
aec627bbcd
@ -381,6 +381,55 @@ namespace UniversityClientApp.Controllers
|
||||
|
||||
// Äèñöèïëèíà
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> InfoDiscipline(int id)
|
||||
{
|
||||
if (APIStorekeeper.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
var obj1 = APIStorekeeper.GetRequest<List<StudentViewModel>>($"api/student/getallstudents");
|
||||
ViewBag.Students = obj1;
|
||||
var obj2 = APIStorekeeper.GetRequest<List<TeacherViewModel>>($"api/teacher/getteachers?userId={APIStorekeeper.Client.Id}");
|
||||
ViewBag.Teachers = obj2;
|
||||
var obj = await APIStorekeeper.GetRequestDisciplineAsync<DisciplineViewModel>($"api/discipline/getdiscipline?id={id}&userId={APIStorekeeper.Client.Id}");
|
||||
return View(obj);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteDiscipline(int id)
|
||||
{
|
||||
if (id == 0)
|
||||
{
|
||||
throw new Exception("id íå ìîæåò áûòü ðàâåí 0");
|
||||
}
|
||||
APIStorekeeper.PostRequest("api/discipline/deletediscipline", new DisciplineBindingModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
Response.Redirect("Disciplines");
|
||||
}
|
||||
[HttpPost]
|
||||
public void UpdateDiscipline(int id, string name, string description, int teacher, List<int> studentIds, DateOnly date)
|
||||
{
|
||||
if (id == 0)
|
||||
{
|
||||
throw new Exception("id íå ìîæåò áûòü ðàâåí 0");
|
||||
}
|
||||
var disciplineStudents = studentIds.ToDictionary(id => id, id => (IStudentModel)null);
|
||||
APIStorekeeper.PostRequest("api/discipline/updatediscipline", new DisciplineBindingModel
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
Description = description,
|
||||
TeacherId = teacher,
|
||||
StudentDisciplines = disciplineStudents,
|
||||
Date = date
|
||||
});
|
||||
Response.Redirect("Disciplines");
|
||||
}
|
||||
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
|
@ -73,7 +73,7 @@
|
||||
<th>Описание</th>
|
||||
<th>Дата</th>
|
||||
<th>Имя учителя</th>
|
||||
<th>Действие</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -91,6 +91,15 @@
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.TeacherName)
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
<a asp-controller="Home" asp-action="InfoDiscipline" asp-route-id="@item.Id" class="btn btn-warning">Изменить</a>
|
||||
<form asp-controller="Home" asp-action="DeleteDiscipline" method="post">
|
||||
<input type="hidden" name="id" value="@item.Id" />
|
||||
<button type="submit" class="btn btn-danger">Удалить</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
@using UniversityContracts.ViewModels
|
||||
@model DisciplineViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Дисциплина";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">@ViewData["Title"] - @Model.Id</h2>
|
||||
</div>
|
||||
<form asp-action="UpdateDiscipline" method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Название:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" name="name" id="name" class="form-control" value="@Model.Name"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Описание:</div>
|
||||
<div class="col-8">
|
||||
<input name="description" id="description" class="form-control" value="@Model.Description"></input>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-4">Дата:</div>
|
||||
<div class="col-8">
|
||||
<input type="date" name="date" id="date" class="form-control" value="@Model.Date" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Преподаватель:</div>
|
||||
<div class="col-8">
|
||||
<select id="teacher" name="teacher" class="form-control" asp-items="@(new SelectList(@ViewBag.Teachers,"Id", "Name"))" value="@Model.TeacherId"></select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-4">Студенты:</div>
|
||||
<div class="col-8">
|
||||
<div class="scrollable-list">
|
||||
@foreach (var student in ViewBag.Students)
|
||||
{
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="studentIds" value="@student.Id" id="student-@student.Id" /
|
||||
checked="@(Model.StudentDisciplines.ContainsKey(student.Id))">
|
||||
<label class="form-check-label" for="student-@student.Id">
|
||||
@student.Name
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4">
|
||||
<form asp-action="Disciplines">
|
||||
<input type="submit" value="Отмена" class="btn btn-primary" />
|
||||
</form>
|
||||
<input type="hidden" name="id" value="@Model.Id" />
|
||||
<input type="submit" value="Сохранить" class="btn btn-danger" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
@ -25,12 +25,6 @@
|
||||
<input type="text" name="position" id="position" class="form-control" value="@Model.Position" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4">
|
||||
<input type="submit" value="Create Teacher" class="btn btn-primary" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4 mt-2">
|
||||
|
@ -67,7 +67,6 @@ namespace UniversityDatabaseImplement.Models
|
||||
return;
|
||||
}
|
||||
Id = model.Id;
|
||||
UserId = model.UserId;
|
||||
TeacherId = model.TeacherId;
|
||||
Name = model.Name;
|
||||
Description = model.Description;
|
||||
|
@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
//Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR
|
||||
optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-DYCTATOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
@ -23,20 +23,22 @@ namespace UniversityRestApi.Controllers
|
||||
_reportLogic = reportLogic;
|
||||
_mailWorker = mailWorker;
|
||||
}
|
||||
/*[HttpGet]
|
||||
public List<DisciplineViewModel>? GetDisciplines(int userId)
|
||||
|
||||
[HttpGet]
|
||||
public DisciplineViewModel? GetDiscipline(int id, int userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadList(new DisciplineSearchModel { UserId = userId });
|
||||
return _logic.ReadElement(new DisciplineSearchModel { Id = id, UserId = userId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка дисциплин");
|
||||
_logger.LogError(ex, "Ошибка получения списка планов обучения");
|
||||
throw;
|
||||
}
|
||||
}*/
|
||||
[HttpGet]
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<DisciplineViewModel>? GetDisciplines()
|
||||
{
|
||||
try
|
||||
@ -89,7 +91,7 @@ namespace UniversityRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPut]
|
||||
[HttpPost]
|
||||
public void UpdateDiscipline(DisciplineBindingModel model)
|
||||
{
|
||||
try
|
||||
@ -102,7 +104,7 @@ namespace UniversityRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpDelete]
|
||||
[HttpPost]
|
||||
public void DeleteDiscipline(DisciplineBindingModel model)
|
||||
{
|
||||
try
|
||||
|
@ -31,6 +31,19 @@ namespace UniversityRestApi.Controllers
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<StudentViewModel>? GetAllStudents()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка ");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public StudentViewModel? GetStudent(int userId, int studentId)
|
||||
{
|
||||
try
|
||||
|
Loading…
Reference in New Issue
Block a user