From 0381c343c65795574d0a437b5f4f3ac6dce743b1 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: Thu, 25 May 2023 12:51:38 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BD=D1=8B=D0=B9=20CRUD=20?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D1=82=D0=B5=D0=B9=20=D0=B7=D0=B0=D1=82=D1=80?= =?UTF-8?q?=D0=B0=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ItemStorage.cs | 2 +- .../Controllers/HomeController.cs | 80 ++++++++++++++++++- CarService/CarServiceWebApp/Program.cs | 2 + .../Views/Home/CreateItem.cshtml | 23 ++++++ .../CarServiceWebApp/Views/Home/Item.cshtml | 28 +++++++ .../CarServiceWebApp/Views/Home/Items.cshtml | 34 ++++++++ .../Views/Shared/_Layout.cshtml | 2 +- 7 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 CarService/CarServiceWebApp/Views/Home/CreateItem.cshtml create mode 100644 CarService/CarServiceWebApp/Views/Home/Item.cshtml create mode 100644 CarService/CarServiceWebApp/Views/Home/Items.cshtml diff --git a/CarService/CarServiceDatabase/Implements/ItemStorage.cs b/CarService/CarServiceDatabase/Implements/ItemStorage.cs index 872afcb..76dad26 100644 --- a/CarService/CarServiceDatabase/Implements/ItemStorage.cs +++ b/CarService/CarServiceDatabase/Implements/ItemStorage.cs @@ -22,7 +22,7 @@ namespace CarServiceDatabase.Implements { using var context = new CarServiceDbContext(); return context.Items - .Where(x => x.Id == model.Id) + .Where(x => x.WorkerId == model.Id) .Include(x => x.Worker) .Select(x => x.GetViewModel) .ToList(); diff --git a/CarService/CarServiceWebApp/Controllers/HomeController.cs b/CarService/CarServiceWebApp/Controllers/HomeController.cs index 2ce9f57..7dd39f3 100644 --- a/CarService/CarServiceWebApp/Controllers/HomeController.cs +++ b/CarService/CarServiceWebApp/Controllers/HomeController.cs @@ -13,12 +13,14 @@ namespace CarServiceWebApp.Controllers private readonly ILogger _logger; private readonly IWorkLogic _workLogic; private readonly IWorkerLogic _workerLogic; + private readonly IItemLogic _itemLogic; - public HomeController(ILogger logger, IWorkLogic workLogic, IWorkerLogic workerLogic) + public HomeController(ILogger logger, IWorkLogic workLogic, IWorkerLogic workerLogic, IItemLogic itemLogic) { _logger = logger; _workLogic = workLogic; _workerLogic = workerLogic; + _itemLogic = itemLogic; } /// /// Главная страница @@ -170,6 +172,82 @@ namespace CarServiceWebApp.Controllers return Redirect("~/Home/Works"); } /// + /// Вывод формы со списком статей затрат + /// + /// + public IActionResult Items() + { + if (CurrentUser.UserId < 1) + { + return Redirect("~/Home/Index"); + } + var Items = _itemLogic.ReadList(new() { Id = CurrentUser.UserId }); + ViewBag.Items = Items; + if (Items?.Count == 0) + { + ViewBag.Exception = "Пока нет запчастей"; + } + return View(); + } + /// + /// Отображение формы CRUD запчасти + /// + /// + /// + [HttpGet] + public IActionResult Item(int Id) + { + ViewBag.Item = _itemLogic.ReadElement(new() { Id = Id }); + return View(); + } + /// + /// Обновление запчасти + /// + /// + /// + [HttpPost] + public IActionResult UpdateItem(ItemBindingModel model) + { + _itemLogic.Update(model); + return Redirect("~/Home/Items"); + } + /// + /// Удаление запчасти + /// + /// + /// + [HttpPost] + public IActionResult DeleteItem(ItemBindingModel model) + { + _itemLogic.Delete(model); + return Redirect("~/Home/Items"); + } + /// + /// Отображение формы добавления запчасти + /// + /// + [HttpGet] + public IActionResult CreateItem() => View(); + /// + /// Добавление запчасти + /// + /// + /// + [HttpPost] + public IActionResult CreateItem(ItemBindingModel model) + { + try + { + _itemLogic.Create(model); + } + catch (Exception ex) + { + ViewBag.Exception = ex.Message; + return View(); + } + return Redirect("~/Home/Items"); + } + /// /// Вывод ошибок /// /// diff --git a/CarService/CarServiceWebApp/Program.cs b/CarService/CarServiceWebApp/Program.cs index c27d6bc..187d902 100644 --- a/CarService/CarServiceWebApp/Program.cs +++ b/CarService/CarServiceWebApp/Program.cs @@ -13,6 +13,8 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); var app = builder.Build(); diff --git a/CarService/CarServiceWebApp/Views/Home/CreateItem.cshtml b/CarService/CarServiceWebApp/Views/Home/CreateItem.cshtml new file mode 100644 index 0000000..bba7f54 --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Home/CreateItem.cshtml @@ -0,0 +1,23 @@ +@{ + ViewData["Title"] = "Создание запчасти"; +} +
+ + +
+
Название:
+
+
+
+
Цена:
+
+
+
+
Количество:
+
+
+
+
+
+
+
@ViewBag.Exception
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Home/Item.cshtml b/CarService/CarServiceWebApp/Views/Home/Item.cshtml new file mode 100644 index 0000000..d9288d9 --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Home/Item.cshtml @@ -0,0 +1,28 @@ +@{ + ViewData["Title"] = "Редактирование запчасти"; +} +
+ + +
+
Название:
+
+
+
+
Цена:
+
+
+
+
Количество:
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/CarService/CarServiceWebApp/Views/Home/Items.cshtml b/CarService/CarServiceWebApp/Views/Home/Items.cshtml new file mode 100644 index 0000000..0137cc7 --- /dev/null +++ b/CarService/CarServiceWebApp/Views/Home/Items.cshtml @@ -0,0 +1,34 @@ +@{ + ViewData["Title"] = "Запчасти"; +} + +
+

Запчасти

+ @if (ViewBag.Items.Count != 0) + { +
+ + + + + + + + + + @foreach (var item in ViewBag.Items) + { + + + + + + + } + +
НазваниеЦена (в рублях)Количество на складе
@item.Name@item.Price@item.CountИзменить
+
+ } + +
@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 2cd2230..42ba7ec 100644 --- a/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml +++ b/CarService/CarServiceWebApp/Views/Shared/_Layout.cshtml @@ -26,7 +26,7 @@ Заявки