Ведомости круд вроде готово

This commit is contained in:
GokaPek 2024-05-30 04:16:38 +04:00
parent ad24e2c38c
commit d3acce8dd5
5 changed files with 122 additions and 5 deletions

View File

@ -314,7 +314,7 @@ namespace UniversityClientApp.Controllers
}
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(academicdegree) || string.IsNullOrEmpty(position))
{
throw new Exception("Введите форму оценивания и выберите студента");
throw new Exception("Ââåäèòå");
}
APIStorekeeper.PostRequest("api/teacher/updateteacher", new TeacherBindingModel
@ -328,6 +328,59 @@ namespace UniversityClientApp.Controllers
}
// Âåäîìîñòü
[HttpPost]
public void DeleteStatement(int id)
{
if (id == 0)
{
throw new Exception("id íå ìîæåò áûòü ðàâåí 0");
}
APIStorekeeper.PostRequest("api/statement/deletestatement", new StatementBindingModel
{
Id = id
});
Response.Redirect("Statements");
}
[HttpGet]
public IActionResult InfoStatement(int id)
{
if (APIStorekeeper.Client == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Teachers = APIStorekeeper.GetRequest<List<TeacherViewModel>>($"api/teacher/getteachers?userId={APIStorekeeper.Client.Id}");
var obj = APIStorekeeper.GetRequest<StatementViewModel>($"api/statement/getstatement?userId={APIStorekeeper.Client.Id}&id={id}");
return View(obj);
}
[HttpPost]
public void UpdateStatement(int id, string name, DateTime date, int teacher)
{
if (APIStorekeeper.Client == null)
{
throw new Exception("Âõîä òîëüêî àâòîðèçîâàííûì");
}
if (string.IsNullOrEmpty(name) || teacher == 0)
{
throw new Exception("Ââåäèòå");
}
APIStorekeeper.PostRequest("api/statement/updatestatement", new StatementBindingModel
{
Id = id,
Name = name,
Date = date,
TeacherId = teacher
});
Response.Redirect("Statements");
}
// Äèñöèïëèíà
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{

View File

@ -0,0 +1,41 @@
@using UniversityContracts.ViewModels
@model StatementViewModel
@{
ViewData["Title"] = "Ведомость";
}
<div class="text-center">
<h2 class="display-4">@ViewData["Title"] - @Model.Id</h2>
</div>
<form asp-action="UpdateStatement" 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 type="datetime-local" 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-8"></div>
<div class="col-4 mt-2">
<form asp-action="Statements">
<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>

View File

@ -44,6 +44,7 @@
<th>Название</th>
<th>Дата</th>
<th>Преподаватель</th>
<th>Действие</th>
</tr>
</thead>
<tbody>@foreach (var item in Model)
@ -61,6 +62,15 @@
<td>
@Html.DisplayFor(modelItem => item.TeacherName)
</td>
<td>
<div class="btn-group">
<a asp-controller="Home" asp-action="InfoStatement" asp-route-id="@item.Id" class="btn btn-warning">Изменить</a>
<form asp-controller="Home" asp-action="DeleteStatement" method="post">
<input type="hidden" name="id" value="@item.Id" />
<button type="submit" class="btn btn-danger">Удалить</button>
</form>
</div>
</td>
</tr>
}
</tbody>

View File

@ -58,8 +58,7 @@ namespace UniversityDatabaseImplement.Models
return;
}
Id = model.Id;
UserId = model.UserId;
TeacherId = model.Id;
//TeacherId = model.Id;
Name = model.Name;
Date = model.Date;
}

View File

@ -38,6 +38,20 @@ namespace UniversityRestApi.Controllers
}
}
[HttpGet]
public StatementViewModel? GetStatement(int userId, int id)
{
try
{
return _logic.ReadElement(new StatementSearchModel { UserId = userId, Id = id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения ведомости id={Id}", userId);
throw;
}
}
[HttpPost]
public void CreateStatement(StatementBindingModel model)
{
@ -50,7 +64,7 @@ namespace UniversityRestApi.Controllers
throw;
}
}
[HttpPut]
[HttpPost]
public void UpdateStatement(StatementBindingModel model)
{
try
@ -63,7 +77,7 @@ namespace UniversityRestApi.Controllers
throw;
}
}
[HttpDelete]
[HttpPost]
public void DeleteStatement(StatementBindingModel model)
{
try