From 97178360636f64800faa9511ced57ef14cf6fcd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Tue, 23 May 2023 01:18:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BD=D1=8B=D0=B9=20crud=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 68 +++++++++++++------ .../Views/Home/CreateWork.cshtml | 20 ++++++ .../CarServiceWebApp/Views/Home/Enter.cshtml | 2 +- .../CarServiceWebApp/Views/Home/Work.cshtml | 5 +- .../CarServiceWebApp/Views/Home/Works.cshtml | 39 ++++++----- 5 files changed, 93 insertions(+), 41 deletions(-) create mode 100644 CarService/CarServiceWebApp/Views/Home/CreateWork.cshtml diff --git a/CarService/CarServiceWebApp/Controllers/HomeController.cs b/CarService/CarServiceWebApp/Controllers/HomeController.cs index db8e0bb..5c3f2f6 100644 --- a/CarService/CarServiceWebApp/Controllers/HomeController.cs +++ b/CarService/CarServiceWebApp/Controllers/HomeController.cs @@ -38,9 +38,7 @@ namespace CarServiceWebApp.Controllers /// [HttpGet] public IActionResult Enter() - { - return View(); - } + => View(); /// /// Ввод данных в форму для входа /// @@ -94,10 +92,7 @@ namespace CarServiceWebApp.Controllers /// /// [HttpGet] - public IActionResult Register() - { - return View(); - } + public IActionResult Register() => View(); /// /// Ввод данных при регистрации пользователя /// @@ -116,31 +111,64 @@ namespace CarServiceWebApp.Controllers } return Redirect("~/Home/Enter"); } + /// + /// Отображение формы CRUD работы + /// + /// + /// [HttpGet] public IActionResult Work(int Id) { ViewBag.Work = _workLogic.ReadElement(new() { Id = Id }); return View(); } + /// + /// Обновление работы + /// + /// + /// [HttpPost] - public IActionResult UpdateWork(Work work) + public IActionResult UpdateWork(WorkBindingModel model) { - //ViewBag.Work = _workLogic.ReadElement(new() { Id = Id }); - return View(); + _workLogic.Update(model); + return Redirect("~/Home/Works"); } + /// + /// Удаление работы + /// + /// + /// [HttpPost] - public IActionResult DeleteWork(int Id) + public IActionResult DeleteWork(WorkBindingModel model) { - ViewBag.Work = _workLogic.ReadElement(new() { Id = Id }); - return View(); + _workLogic.Delete(model); + return Redirect("~/Home/Works"); + } + /// + /// Отображение формы добавления работы + /// + /// + //[HttpGet] + public IActionResult CreateWork() => View(); + /// + /// Добавление работы + /// + /// + /// + [HttpPost] + public IActionResult CreateWork(WorkBindingModel model) + { + try + { + _workLogic.Create(model); + } + catch (Exception ex) + { + ViewBag.Exception = ex.Message; + return View(); + } + return Redirect("~/Home/Works"); } - - - - - - - /// /// Вывод ошибок /// diff --git a/CarService/CarServiceWebApp/Views/Home/CreateWork.cshtml b/CarService/CarServiceWebApp/Views/Home/CreateWork.cshtml new file mode 100644 index 0000000..7b30578 --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Home/CreateWork.cshtml @@ -0,0 +1,20 @@ +
+ + +
+
Название:
+
+
+
+
Цена:
+
+
+
+
Длительность:
+
+
+
+
+
+
+
@ViewBag.Exception
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Home/Enter.cshtml b/CarService/CarServiceWebApp/Views/Home/Enter.cshtml index 77a8f67..463ef5b 100644 --- a/CarService/CarServiceWebApp/Views/Home/Enter.cshtml +++ b/CarService/CarServiceWebApp/Views/Home/Enter.cshtml @@ -1,5 +1,5 @@ @{ - ViewData["Title"] = "Enter"; + ViewData["Title"] = "Вход"; }
diff --git a/CarService/CarServiceWebApp/Views/Home/Work.cshtml b/CarService/CarServiceWebApp/Views/Home/Work.cshtml index 5661d93..4973cf6 100644 --- a/CarService/CarServiceWebApp/Views/Home/Work.cshtml +++ b/CarService/CarServiceWebApp/Views/Home/Work.cshtml @@ -1,5 +1,6 @@ 
+
Название:
@@ -13,10 +14,10 @@
-
+
-
+
diff --git a/CarService/CarServiceWebApp/Views/Home/Works.cshtml b/CarService/CarServiceWebApp/Views/Home/Works.cshtml index 10a5d13..20d02d1 100644 --- a/CarService/CarServiceWebApp/Views/Home/Works.cshtml +++ b/CarService/CarServiceWebApp/Views/Home/Works.cshtml @@ -6,26 +6,29 @@

Работы

@if (ViewBag.Works.Count != 0) { - - - - - - - - - - @foreach (var work in ViewBag.Works) - { +
+
НазваниеЦена (в рублях)Длительность (в часах)
+ - - - - + + + - } - -
@work.Name@work.Price@work.DurationИзменитьНазваниеЦена (в рублях)Длительность (в часах)
+ + + @foreach (var work in ViewBag.Works) + { + + @work.Name + @work.Price + @work.Duration + Изменить + + } + + + } +
Добавить
@ViewBag.Exception
\ No newline at end of file