CRUD для поделки

This commit is contained in:
Володя 2023-05-17 21:15:18 +03:00
parent acbc8696a9
commit 524ef743f3
2 changed files with 45 additions and 3 deletions

View File

@ -205,7 +205,7 @@ namespace StudentWebClient.Controllers
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
return View(_diy.ReadList(new DiySearchModel { Id = APIClient.Student.Id})); return View(_diy.ReadList(new DiySearchModel { StudentId = APIClient.Student.Id}));
} }
[HttpGet] [HttpGet]
public IActionResult CreateDiy() public IActionResult CreateDiy()
@ -250,7 +250,7 @@ namespace StudentWebClient.Controllers
public IActionResult DiySetting(int id) public IActionResult DiySetting(int id)
{ {
var diy = _diy.ReadElement(new DiySearchModel { Id = id }); var diy = _diy.ReadElement(new DiySearchModel { Id = id });
var interests = _interest.ReadList(null).Select(x => new {InterestId = x.Id, InterestName = x.Title}).ToList(); var interests = _interest.ReadList(new InterestSearchModel { StudentId = APIClient.Student.Id}).Select(x => new {InterestId = x.Id, InterestName = x.Title}).ToList();
var selectedInterests = diy.DiyInterests.Select(x => x.Key).ToArray(); var selectedInterests = diy.DiyInterests.Select(x => x.Key).ToArray();
ViewBag.Interests = new MultiSelectList(interests, "InterestId", "InterestName", selectedInterests); ViewBag.Interests = new MultiSelectList(interests, "InterestId", "InterestName", selectedInterests);
ViewBag.Tasks = _task.ReadList(null); ViewBag.Tasks = _task.ReadList(null);
@ -287,8 +287,9 @@ namespace StudentWebClient.Controllers
{ {
diyInterests.Add(id, _interest.ReadElement(new InterestSearchModel { Id = id })); diyInterests.Add(id, _interest.ReadElement(new InterestSearchModel { Id = id }));
} }
_diy.Create(new DiyBindingModel _diy.Update(new DiyBindingModel
{ {
Id = idDiy,
StudentId = APIClient.Student.Id, StudentId = APIClient.Student.Id,
StudentName = APIClient.Student.Name, StudentName = APIClient.Student.Name,
Title = title, Title = title,

View File

@ -0,0 +1,41 @@
@using SchoolAgainStudyContracts.ViewModel;
@model DiyViewModel
@{
ViewData["Title"] = "Setting";
}
<div class="text-center">
<h2 class="display-4">@Model.Title</h2>
</div>
<form method="post" action="@Url.Action("UpdateDiy", "Home", new{idDiy=Model.Id,title="#title",description="#description", dateCreate="#dateCreate",task="#task",interests="#interests"})">
<div class="row m-3">
<div class="col-8">
<input type="submit" value="Обновить" class="col-md-4 btn btn-primary" />
<input type="button" class="col-md-4 ms-auto btn btn-danger" value="Удалить" onclick="location.href='@Url.Action("DeleteDiy","Home", new {id=Model.Id })'" />
</div>
</div>
<div class="row m-3">
<div class="col-4">Название:</div>
<div class="col-8"><input type="text" name="title" id="title" value="@Model.Title" /></div>
</div>
<div class="row m-3">
<div class="col-4">Описание:</div>
<div class="col-8"><textarea cols="50" id="description" name="description" rows="5">@Model.Description</textarea>:</div>
</div>
<div class="row">
<div class="col-4">Дата создания:</div>
<div class="col-8">@Html.TextBox("dateCreate" ,"" ,new {type="Date"})</div>
</div>
<div class="row">
<div class="col-4">Задание:</div>
<div class="col-8">
<select id="task" name="task" class="form-control" asp-items="@(new SelectList(@ViewBag.Tasks,"Id", "Title"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Интересы:</div>
<div class="col-8">
@Html.ListBox("interests", (MultiSelectList)ViewBag.Interests)
</div>
</div>
</form>