From c7cb3722800bc27e44db3c70b644033e952288b4 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 00:33:16 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=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 | 120 +++++++++++++++++- CarService/CarServiceWebApp/Program.cs | 2 + .../CarServiceWebApp/Views/Home/Enter.cshtml | 15 ++- .../Views/Home/Register.cshtml | 15 ++- .../CarServiceWebApp/Views/Home/Work.cshtml | 24 ++++ .../CarServiceWebApp/Views/Home/Works.cshtml | 39 +++--- .../Views/Shared/_Layout.cshtml | 5 +- 7 files changed, 185 insertions(+), 35 deletions(-) create mode 100644 CarService/CarServiceWebApp/Views/Home/Work.cshtml diff --git a/CarService/CarServiceWebApp/Controllers/HomeController.cs b/CarService/CarServiceWebApp/Controllers/HomeController.cs index 6e70cb8..db8e0bb 100644 --- a/CarService/CarServiceWebApp/Controllers/HomeController.cs +++ b/CarService/CarServiceWebApp/Controllers/HomeController.cs @@ -1,5 +1,7 @@ -using CarServiceBusinessLogic.BusinessLogics; +using CarServiceContracts.BindingModels; using CarServiceContracts.BusinessLogicsContracts; +using CarServiceContracts.SearchModels; +using CarServiceDatabase.Models; using CarServiceWebApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -10,13 +12,18 @@ namespace CarServiceWebApp.Controllers { private readonly ILogger _logger; private readonly IWorkLogic _workLogic; + private readonly IWorkerLogic _workerLogic; - public HomeController(ILogger logger, IWorkLogic workLogic) + public HomeController(ILogger logger, IWorkLogic workLogic, IWorkerLogic workerLogic) { _logger = logger; _workLogic = workLogic; + _workerLogic = workerLogic; } - + /// + /// Главная страница + /// + /// public IActionResult Index() { if (CurrentUser.UserId < 1) @@ -25,18 +32,119 @@ namespace CarServiceWebApp.Controllers } return View(); } - + /// + /// Отображение формы для входа + /// + /// + [HttpGet] public IActionResult Enter() { return View(); } - + /// + /// Ввод данных в форму для входа + /// + /// + /// + [HttpPost] + public IActionResult Enter(WorkerSearchModel model) + { + var existingWorker = _workerLogic.ReadElement(new() { Login = model.Login, Password = model.Password }); + if (existingWorker != null) + { + CurrentUser.UserId = existingWorker.Id; + return Redirect("~/Home/Index"); + } + else + { + ViewBag.Exception = "Неверный логин или пароль"; + return View(); + } + } + /// + /// Список работ + /// + /// public IActionResult Works() { - ViewBag.Works = _workLogic.ReadList(new() { Id = 1 }); + if (CurrentUser.UserId < 1) + { + return Redirect("~/Home/Index"); + } + var Works = _workLogic.ReadList(new() { Id = CurrentUser.UserId }); + ViewBag.Works = Works; + if (Works?.Count == 0) + { + ViewBag.Exception = "Пока нет работ"; + } + return View(); + } + /// + /// Выход из учётной записи + /// + /// + [HttpGet] + public IActionResult Logout() + { + CurrentUser.UserId = 0; + return Redirect("~/Home/Index"); + } + /// + /// Отображение формы для регистрации + /// + /// + [HttpGet] + public IActionResult Register() + { + return View(); + } + /// + /// Ввод данных при регистрации пользователя + /// + /// + [HttpPost] + public IActionResult Register(WorkerBindingModel model) + { + try + { + _workerLogic.Create(model); + } + catch (Exception ex) + { + ViewBag.Exception = ex.Message; + return View(); + } + return Redirect("~/Home/Enter"); + } + [HttpGet] + public IActionResult Work(int Id) + { + ViewBag.Work = _workLogic.ReadElement(new() { Id = Id }); + return View(); + } + [HttpPost] + public IActionResult UpdateWork(Work work) + { + //ViewBag.Work = _workLogic.ReadElement(new() { Id = Id }); + return View(); + } + [HttpPost] + public IActionResult DeleteWork(int Id) + { + ViewBag.Work = _workLogic.ReadElement(new() { Id = Id }); return View(); } + + + + + + + /// + /// Вывод ошибок + /// + /// [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/CarService/CarServiceWebApp/Program.cs b/CarService/CarServiceWebApp/Program.cs index 05a02e7..c27d6bc 100644 --- a/CarService/CarServiceWebApp/Program.cs +++ b/CarService/CarServiceWebApp/Program.cs @@ -11,6 +11,8 @@ builder.Logging.AddLog4Net("log4net.config"); builder.Services.AddControllersWithViews(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); var app = builder.Build(); diff --git a/CarService/CarServiceWebApp/Views/Home/Enter.cshtml b/CarService/CarServiceWebApp/Views/Home/Enter.cshtml index 106d3d5..77a8f67 100644 --- a/CarService/CarServiceWebApp/Views/Home/Enter.cshtml +++ b/CarService/CarServiceWebApp/Views/Home/Enter.cshtml @@ -8,14 +8,19 @@
Логин:
-
+
Пароль:
-
+
-
-
+
-
\ No newline at end of file + +
+
+
+
+
@ViewBag.Exception
+
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Home/Register.cshtml b/CarService/CarServiceWebApp/Views/Home/Register.cshtml index 21095f6..6e22881 100644 --- a/CarService/CarServiceWebApp/Views/Home/Register.cshtml +++ b/CarService/CarServiceWebApp/Views/Home/Register.cshtml @@ -1,5 +1,5 @@ @{ - ViewData["Title"] = "Register"; + ViewData["Title"] = "Регистрация"; }
@@ -8,22 +8,25 @@
Логин:
-
+
Пароль:
-
+
Имя:
-
+
Фамилия:
-
+
-
\ No newline at end of file + +
+
@ViewBag.Exception
+
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Home/Work.cshtml b/CarService/CarServiceWebApp/Views/Home/Work.cshtml new file mode 100644 index 0000000..5661d93 --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Home/Work.cshtml @@ -0,0 +1,24 @@ +
+ +
+
Название:
+
+
+
+
Цена:
+
+
+
+
Длительность:
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Home/Works.cshtml b/CarService/CarServiceWebApp/Views/Home/Works.cshtml index be1ff42..10a5d13 100644 --- a/CarService/CarServiceWebApp/Views/Home/Works.cshtml +++ b/CarService/CarServiceWebApp/Views/Home/Works.cshtml @@ -4,23 +4,28 @@

Работы

- - - - - - - - - - @foreach (var work in ViewBag.Works) - { + @if (ViewBag.Works.Count != 0) + { +
НазваниеЦена (в рублях)Длительность (в часах)
+ - - - + + + - } - -
@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 diff --git a/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml b/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml index 97e4673..2cd2230 100644 --- a/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml +++ b/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml @@ -3,7 +3,7 @@ - @ViewData["Title"] - CarServiceWebApp + @ViewData["Title"] @@ -31,6 +31,9 @@ +