полный crud работ
This commit is contained in:
parent
c7cb372280
commit
9717836063
@ -38,9 +38,7 @@ namespace CarServiceWebApp.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult Enter()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
=> View();
|
||||
/// <summary>
|
||||
/// Ввод данных в форму для входа
|
||||
/// </summary>
|
||||
@ -94,10 +92,7 @@ namespace CarServiceWebApp.Controllers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
public IActionResult Register() => View();
|
||||
/// <summary>
|
||||
/// Ввод данных при регистрации пользователя
|
||||
/// </summary>
|
||||
@ -116,31 +111,64 @@ namespace CarServiceWebApp.Controllers
|
||||
}
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
/// <summary>
|
||||
/// Отображение формы CRUD работы
|
||||
/// </summary>
|
||||
/// <param name="Id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult Work(int Id)
|
||||
{
|
||||
ViewBag.Work = _workLogic.ReadElement(new() { Id = Id });
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// Обновление работы
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult UpdateWork(Work work)
|
||||
public IActionResult UpdateWork(WorkBindingModel model)
|
||||
{
|
||||
//ViewBag.Work = _workLogic.ReadElement(new() { Id = Id });
|
||||
_workLogic.Update(model);
|
||||
return Redirect("~/Home/Works");
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление работы
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult DeleteWork(WorkBindingModel model)
|
||||
{
|
||||
_workLogic.Delete(model);
|
||||
return Redirect("~/Home/Works");
|
||||
}
|
||||
/// <summary>
|
||||
/// Отображение формы добавления работы
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
//[HttpGet]
|
||||
public IActionResult CreateWork() => View();
|
||||
/// <summary>
|
||||
/// Добавление работы
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult CreateWork(WorkBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_workLogic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ViewBag.Exception = ex.Message;
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public IActionResult DeleteWork(int Id)
|
||||
{
|
||||
ViewBag.Work = _workLogic.ReadElement(new() { Id = Id });
|
||||
return View();
|
||||
return Redirect("~/Home/Works");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Вывод ошибок
|
||||
/// </summary>
|
||||
|
20
CarService/CarServiceWebApp/Views/Home/CreateWork.cshtml
Normal file
20
CarService/CarServiceWebApp/Views/Home/CreateWork.cshtml
Normal file
@ -0,0 +1,20 @@
|
||||
<form method="post">
|
||||
<div hidden><input type="text" name="Id" /></div>
|
||||
<div hidden><input type="text" name="WorkerId" value="@CurrentUser.UserId" /></div>
|
||||
<div class="row">
|
||||
<div class="col-4">Название:</div>
|
||||
<div class="col-8"><input type="text" name="Name" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Цена:</div>
|
||||
<div class="col-8"><input type="text" name="Price" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Длительность:</div>
|
||||
<div class="col-8"><input type="text" name="Duration" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div><button asp-controller="Home" asp-action="CreateWork" class="btn btn-primary">Добавить</button></div>
|
||||
</div>
|
||||
</form>
|
||||
<div>@ViewBag.Exception</div>
|
@ -1,5 +1,5 @@
|
||||
@{
|
||||
ViewData["Title"] = "Enter";
|
||||
ViewData["Title"] = "Вход";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
|
@ -1,5 +1,6 @@
|
||||
<form method="post">
|
||||
<div hidden><input type="text" name="Id" value="@ViewBag.Work.Id" /></div>
|
||||
<div hidden><input type="text" name="WorkerId" value="@ViewBag.Work.WorkerId" /></div>
|
||||
<div class="row">
|
||||
<div class="col-4">Название:</div>
|
||||
<div class="col-8"><input type="text" name="Name" value="@ViewBag.Work.Name" /></div>
|
||||
|
@ -6,6 +6,7 @@
|
||||
<h1 class="display-4">Работы</h1>
|
||||
@if (ViewBag.Works.Count != 0)
|
||||
{
|
||||
<center>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@ -26,6 +27,8 @@
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</center>
|
||||
}
|
||||
<div><center><a asp-controller="Home" asp-action="CreateWork" class="btn btn-primary">Добавить</a></center></div>
|
||||
<div>@ViewBag.Exception</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user