From 8caf2860a622c0cbd0cf07642f816143ccc0f770 Mon Sep 17 00:00:00 2001 From: "DozorovaA.A" Date: Thu, 18 May 2023 16:22:24 +0400 Subject: [PATCH] add scope and materials --- .../Implements/MaterialStorage.cs | 2 + .../Models/Material.cs | 4 +- .../Controllers/MaterialController.cs | 10 +- .../Controllers/ScopeController.cs | 10 +- .../Controllers/HomeController.cs | 178 +++++++++++++++++- .../Program.cs | 4 +- .../Views/Home/CreateMaterial.cshtml | 54 ++++++ .../Views/Home/CreateScope.cshtml | 18 ++ .../Views/Home/DeleteMaterial.cshtml | 27 +++ .../Views/Home/DeleteScope.cshtml | 27 +++ .../Views/Home/GetFurnitureList.cshtml | 5 + .../Views/Home/GetMaterialsList.cshtml | 64 +++++++ .../Views/Home/GetScopeList.cshtml | 47 +++++ .../Views/Home/Register.cshtml | 23 ++- .../Views/Home/UpdateMaterial.cshtml | 66 +++++++ .../Views/Home/UpdateScope.cshtml | 34 ++++ .../Views/Shared/_Layout.cshtml | 11 +- .../appsettings.json | 1 + 18 files changed, 563 insertions(+), 22 deletions(-) create mode 100644 FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/CreateMaterial.cshtml create mode 100644 FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/CreateScope.cshtml create mode 100644 FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/DeleteMaterial.cshtml create mode 100644 FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/DeleteScope.cshtml create mode 100644 FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetFurnitureList.cshtml create mode 100644 FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetMaterialsList.cshtml create mode 100644 FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetScopeList.cshtml create mode 100644 FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateMaterial.cshtml create mode 100644 FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateScope.cshtml diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/MaterialStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/MaterialStorage.cs index 6689452..3a40b4f 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/MaterialStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/MaterialStorage.cs @@ -78,6 +78,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements { using var context = new FurnitureAssemblyDatabase(); var material = context.Materials + .Include(x => x.Scope) .Include(x => x.User) .FirstOrDefault(x => x.Id == model.Id); if (material == null) @@ -93,6 +94,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements using var context = new FurnitureAssemblyDatabase(); var element = context.Materials .Include(x => x.User) + .Include(x => x.Scope) .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Material.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Material.cs index ea7f956..7082fb0 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Material.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Material.cs @@ -58,9 +58,9 @@ namespace FurnitureAssemblyDatabaseImplement.Models Name = Name, Cost = Cost, ScopeId = ScopeId, - ScopeName = Scope.Name, + ScopeName = Scope?.Name, UserId = UserId, - UserName = User.Name + UserName = User?.Name }; } } diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/MaterialController.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/MaterialController.cs index fcbc415..e39cd41 100644 --- a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/MaterialController.cs +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/MaterialController.cs @@ -30,7 +30,7 @@ namespace FurnitureAssemblyRestApi.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения списка мебельных модулей"); + _logger.LogError(ex, "Ошибка получения списка материалов"); throw; } } @@ -43,7 +43,7 @@ namespace FurnitureAssemblyRestApi.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения мебельного модуля по id={Id}", Id); + _logger.LogError(ex, "Ошибка получения материала по id={Id}", Id); throw; } } @@ -56,7 +56,7 @@ namespace FurnitureAssemblyRestApi.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка создания мебельного модуля"); + _logger.LogError(ex, "Ошибка создания материала"); throw; } } @@ -69,7 +69,7 @@ namespace FurnitureAssemblyRestApi.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка обновления мебельного модуля"); + _logger.LogError(ex, "Ошибка обновления материала"); throw; } } @@ -82,7 +82,7 @@ namespace FurnitureAssemblyRestApi.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления мебельного модуля"); + _logger.LogError(ex, "Ошибка удаления материала"); throw; } } diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ScopeController.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ScopeController.cs index 5f214af..196cf07 100644 --- a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ScopeController.cs +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ScopeController.cs @@ -30,7 +30,7 @@ namespace FurnitureAssemblyRestApi.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения списка мебельных модулей"); + _logger.LogError(ex, "Ошибка получения списка областей"); throw; } } @@ -43,7 +43,7 @@ namespace FurnitureAssemblyRestApi.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения мебельного модуля по id={Id}", Id); + _logger.LogError(ex, "Ошибка получения области по id={Id}", Id); throw; } } @@ -56,7 +56,7 @@ namespace FurnitureAssemblyRestApi.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка создания мебельного модуля"); + _logger.LogError(ex, "Ошибка создания области"); throw; } } @@ -69,7 +69,7 @@ namespace FurnitureAssemblyRestApi.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка обновления мебельного модуля"); + _logger.LogError(ex, "Ошибка обновления области"); throw; } } @@ -82,7 +82,7 @@ namespace FurnitureAssemblyRestApi.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления мебельного модуля"); + _logger.LogError(ex, "Ошибка удаления области"); throw; } } diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Controllers/HomeController.cs b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Controllers/HomeController.cs index d516e5c..6ccc947 100644 --- a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Controllers/HomeController.cs +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Controllers/HomeController.cs @@ -80,7 +80,7 @@ namespace FurnitureAssemblyStoreKeeperClientApp.Controllers return View(APIClient.GetRequest>($"api/role/getrolelist")); } [HttpPost] - public void Register(string login, string password, string name, int roleId) + public void Register(string login, string password, string name, int roleid) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(name)) { @@ -91,10 +91,184 @@ namespace FurnitureAssemblyStoreKeeperClientApp.Controllers Name = name, Login = login, Password = password, - RoleId = roleId + RoleId = roleid }); Response.Redirect("Enter"); return; } + [HttpGet] + public IActionResult GetScopeList() + { + return View(APIClient.GetRequest>($"api/scope/GetScopeList")); + } + + [HttpGet] + public IActionResult CreateScope() + { + return View(); + } + + [HttpPost] + public void CreateScope(string name) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали?"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Название не указано"); + } + + APIClient.PostRequest("api/scope/addscope", new ScopeBindingModel + { + Name = name + }); + Response.Redirect("GetScopeList"); + } + + [HttpGet] + public IActionResult UpdateScope() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/scope/GetScopeList")); + } + [HttpPost] + public void UpdateScope(int scope, string name) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали?"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Название не указано"); + } + + APIClient.PostRequest("api/scope/updatescope", new ScopeBindingModel + { + Id = scope, + Name = name + }); + Response.Redirect("GetScopeList"); + } + [HttpGet] + public IActionResult DeleteScope() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/scope/GetScopeList")); + } + [HttpPost] + public void DeleteScope(int scope) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали"); + } + APIClient.PostRequest("api/scope/deletescope", new ScopeViewModel + { + Id = scope, + }); + Response.Redirect("GetScopeList"); + } + + [HttpGet] + public IActionResult GetMaterialsList() + { + + return View(APIClient.GetRequest>($"api/material/getmateriallist")); + } + + [HttpGet] + public IActionResult CreateMaterial() + { + return View(); + } + + [HttpPost] + public void CreateMaterial(string name, double cost, int scopeId,int UserId) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали?"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Название не указано"); + } + if (cost <= 0) + { + throw new Exception("Цена должна быть положительной"); + } + APIClient.PostRequest("api/material/addmaterial", new MaterialBindingModel + { + Name = name, + Cost = cost, + ScopeId = scopeId, + UserId = UserId + }); + Response.Redirect("GetMaterialsList"); + } + + [HttpGet] + public IActionResult UpdateMaterial() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/material/GetMaterialList")); + } + [HttpPost] + public void UpdateMaterial(int material, string name, double cost, int scope, int user) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали?"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Название не указано"); + } + + APIClient.PostRequest("api/material/updatematerial", new MaterialBindingModel + { + Id = material, + Name = name, + Cost = cost, + ScopeId = scope, + UserId = user + }); + Response.Redirect("GetMaterialsList"); + } + [HttpGet] + public IActionResult DeleteMaterial() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/material/GetMaterialList")); + } + [HttpPost] + public void DeleteMaterial(int material) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали"); + } + APIClient.PostRequest("api/material/deletematerial", new MaterialBindingModel + { + Id = material, + }); + Response.Redirect("GetMaterialsList"); + } + } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Program.cs b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Program.cs index 0727468..d34a381 100644 --- a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Program.cs +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Program.cs @@ -1,10 +1,12 @@ +using FurnitureAssemblyStoreKeeperClientApp; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); var app = builder.Build(); - +APIClient.Connect(builder.Configuration); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/CreateMaterial.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/CreateMaterial.cshtml new file mode 100644 index 0000000..75b06fa --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/CreateMaterial.cshtml @@ -0,0 +1,54 @@ +@using FurnitureAssemblyContracts.ViewModels +@{ + ViewData["Title"] = "Добавление материала"; + var userList = APIClient.GetRequest>($"api/user/GetUserList"); + var scopeList = APIClient.GetRequest>($"api/scope/GetScopeList"); +} + +
+

Добавление материала

+
+
+
+
Название:
+
+
+
+
Стоимость:
+
+
+
+
Область применения:
+ +
+ +
+
+
+
Производитель:
+ +
+ +
+
+
+
+
+
+
diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/CreateScope.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/CreateScope.cshtml new file mode 100644 index 0000000..da05d64 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/CreateScope.cshtml @@ -0,0 +1,18 @@ +@using FurnitureAssemblyContracts.ViewModels +@{ + ViewData["Title"] = "Добавление области"; +} +
+

Добавление области применения

+
+
+
+
Название:
+
+
+
+
+
+
+ +
diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/DeleteMaterial.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/DeleteMaterial.cshtml new file mode 100644 index 0000000..ddcc812 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/DeleteMaterial.cshtml @@ -0,0 +1,27 @@ +@using FurnitureAssemblyContracts.ViewModels; +@{ + ViewData["Title"] = "Удаление области"; +} +@model List +
+

Удаление материала

+
+
+
+
Выбранный материал:
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/DeleteScope.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/DeleteScope.cshtml new file mode 100644 index 0000000..06cdafe --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/DeleteScope.cshtml @@ -0,0 +1,27 @@ +@using FurnitureAssemblyContracts.ViewModels; +@{ + ViewData["Title"] = "Удаление области"; +} +@model List +
+

Удаление области применения

+
+
+
+
Выбранная область:
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetFurnitureList.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetFurnitureList.cshtml new file mode 100644 index 0000000..e1dd794 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetFurnitureList.cshtml @@ -0,0 +1,5 @@ +@* + For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 +*@ +@{ +} diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetMaterialsList.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetMaterialsList.cshtml new file mode 100644 index 0000000..0b17a58 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetMaterialsList.cshtml @@ -0,0 +1,64 @@ +@using FurnitureAssemblyContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Материалы"; +} + +
+

Материалы

+
+ +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
+ Название + + Стоимость + + Область применения + + Изготовитель +
+ @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.Cost) + + @Html.DisplayFor(modelItem => item.ScopeName) + + @Html.DisplayFor(modelItem => item.UserName) +
+ } +
\ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetScopeList.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetScopeList.cshtml new file mode 100644 index 0000000..ad8e005 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetScopeList.cshtml @@ -0,0 +1,47 @@ +@using FurnitureAssemblyContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Области"; +} + +
+

Области применения

+
+ +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + + + + + + + + + + @foreach (var item in Model) + { + + + + + } + +
+ Название +
+ @Html.DisplayFor(modelItem => item.Name) +
+ } +
\ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/Register.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/Register.cshtml index 13589c9..2042706 100644 --- a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/Register.cshtml +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/Register.cshtml @@ -1,5 +1,7 @@ -@{ -ViewData["Title"] = "Register"; +@using FurnitureAssemblyContracts.ViewModels; +@model List +@{ + ViewData["Title"] = "Регистрация"; }

Регистрация

@@ -15,7 +17,22 @@ ViewData["Title"] = "Register";
ФИО:
-
+
+
+
+
Роль:
+ +
+ +
diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateMaterial.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateMaterial.cshtml new file mode 100644 index 0000000..7641f6f --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateMaterial.cshtml @@ -0,0 +1,66 @@ +@using FurnitureAssemblyContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Изменение материала"; + var scopeList = APIClient.GetRequest>($"api/scope/GetScopeList"); + var userList = APIClient.GetRequest>($"api/user/GetUserList"); +} +
+

Изменение материала

+
+
+
+
Материал:
+
+ +
+
+
+
Название:
+
+
+
+
Стоимость:
+
+
+
+
+
+
+
+
Область применения:
+
+ +
+
+
+
Производитель:
+
+ +
+
+
+ diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateScope.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateScope.cshtml new file mode 100644 index 0000000..46e9bb4 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateScope.cshtml @@ -0,0 +1,34 @@ +@using FurnitureAssemblyContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Изменение области"; +} +
+

Изменение области применения

+
+
+
+
Область применения:
+
+ +
+
+
+
Название:
+
+
+
+
+
+
+
+ diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Shared/_Layout.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Shared/_Layout.cshtml index 306b7b9..12c4571 100644 --- a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Shared/_Layout.cshtml +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Shared/_Layout.cshtml @@ -28,15 +28,16 @@ Регистрация } - - + } +
diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/appsettings.json b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/appsettings.json index fe71643..7b25573 100644 --- a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/appsettings.json +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/appsettings.json @@ -6,5 +6,6 @@ } }, "AllowedHosts": "*", + "IPAddress": "https://localhost:7181" }