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