From 61758e57371b45befded3a2f1116a7c92162a29b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Wed, 17 May 2023 23:03:47 +0300 Subject: [PATCH] =?UTF-8?q?CRUD=20=D0=B4=D0=BB=D1=8F=20=D0=B8=D0=B7=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 108 +++++++++++++++++- .../Views/Home/CreateProduct.cshtml | 32 ++++++ .../Views/Home/DiySetting.cshtml | 4 +- .../StudentWebClient/Views/Home/Diyes.cshtml | 6 + .../Views/Home/ProductSetting.cshtml | 35 ++++++ .../Views/Home/Products.cshtml | 62 ++++++++++ .../Views/Shared/_Layout.cshtml | 3 + 7 files changed, 246 insertions(+), 4 deletions(-) create mode 100644 SchoolAgainStudy/StudentWebClient/Views/Home/CreateProduct.cshtml create mode 100644 SchoolAgainStudy/StudentWebClient/Views/Home/ProductSetting.cshtml create mode 100644 SchoolAgainStudy/StudentWebClient/Views/Home/Products.cshtml diff --git a/SchoolAgainStudy/StudentWebClient/Controllers/HomeController.cs b/SchoolAgainStudy/StudentWebClient/Controllers/HomeController.cs index ebac057..9367922 100644 --- a/SchoolAgainStudy/StudentWebClient/Controllers/HomeController.cs +++ b/SchoolAgainStudy/StudentWebClient/Controllers/HomeController.cs @@ -4,6 +4,7 @@ using SchoolAgainStudyContracts.BindingModel; using SchoolAgainStudyContracts.BusinessLogicContracts; using SchoolAgainStudyContracts.SearchModel; using SchoolAgainStudyContracts.ViewModel; +using SchoolAgainStudyDataBaseImplements.Models; using SchoolAgainStudyDataModels.Models; using StudentWebClient.Models; using System.Diagnostics; @@ -223,7 +224,7 @@ namespace StudentWebClient.Controllers { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description) || string.IsNullOrEmpty(dateCreate) && task <=0 || interests.Length==0) + if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description) || string.IsNullOrEmpty(dateCreate) || task <=0 || interests.Length==0) { throw new Exception("Введите название и описане"); } @@ -244,7 +245,7 @@ namespace StudentWebClient.Controllers DiyInterests = diyInterests }) ; - Response.Redirect("Interests"); + Response.Redirect("Diyes"); } [HttpGet] public IActionResult DiySetting(int id) @@ -312,6 +313,109 @@ namespace StudentWebClient.Controllers }); Response.Redirect("/Home/Diyes"); } + [HttpGet] + public IActionResult Products() + { + if (APIClient.Student == null) + { + return Redirect("~/Home/Enter"); + } + return View(_product.ReadList(new ProductSearchModel { StudentId = APIClient.Student.Id })); + } + [HttpGet] + public IActionResult CreateProduct() + { + var list = _interest.ReadList(new InterestSearchModel { StudentId = APIClient.Student.Id }); + var simpInterest = list.Select(x => new { InterestId = x.Id, InterestName = x.Title }); + ViewBag.Interests = new MultiSelectList(simpInterest, "InterestId", "InterestName"); + return View(); + } + [HttpPost] + public void CreateProduct(string title, string description, string dateCreate, int[] interests) + { + if (APIClient.Student == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description) || string.IsNullOrEmpty(dateCreate)|| interests.Length == 0) + { + throw new Exception("Введите название и описане"); + } + Dictionary productInterests = new Dictionary(); + foreach (int id in interests) + { + productInterests.Add(id, _interest.ReadElement(new InterestSearchModel { Id = id })); + } + _product.Create(new ProductBindingModel + { + StudentId = APIClient.Student.Id, + StudentName = APIClient.Student.Name, + Title = title, + Description = description, + DateCreate = DateTime.SpecifyKind(DateTime.Parse(dateCreate), DateTimeKind.Utc), + ProductInterests = productInterests + }); + Response.Redirect("Products"); + } + [HttpGet] + public IActionResult ProductSetting(int id) + { + var product = _product.ReadElement(new ProductSearchModel { Id = id }); + var interests = _interest.ReadList(new InterestSearchModel { StudentId = APIClient.Student.Id }).Select(x => new { InterestId = x.Id, InterestName = x.Title }).ToList(); + var selectedInterests = product.ProductInterests.Select(x => x.Key).ToArray(); + ViewBag.Interests = new MultiSelectList(interests, "InterestId", "InterestName", selectedInterests); + return View(product); + } + [HttpPost] + public void UpdateProduct(int idDiy, string title, string description, string dateCreate, int[] interests) + { + + + if (string.IsNullOrEmpty(title)) + { + throw new Exception("Нет названия"); + } + if (string.IsNullOrEmpty(description)) + { + throw new Exception("Нет описания"); + } + if (string.IsNullOrEmpty(dateCreate)) + { + throw new Exception("Нет даты"); + } + if (interests.Length == 0) + { + throw new Exception("Нет интересов"); + } + + Dictionary productInterests = new Dictionary(); + foreach (int id in interests) + { + productInterests.Add(id, _interest.ReadElement(new InterestSearchModel { Id = id })); + } + _product.Update(new ProductBindingModel + { + Id = idDiy, + StudentId = APIClient.Student.Id, + StudentName = APIClient.Student.Name, + Title = title, + Description = description, + DateCreate = DateTime.SpecifyKind(DateTime.Parse(dateCreate), DateTimeKind.Utc), + ProductInterests = productInterests + + }); + Response.Redirect("/Home/Products"); + } + + public void DeleteProduct(int id) + { + + _product.Delete(new ProductBindingModel + { + Id = id, + }); + Response.Redirect("/Home/Products"); + } } } \ No newline at end of file diff --git a/SchoolAgainStudy/StudentWebClient/Views/Home/CreateProduct.cshtml b/SchoolAgainStudy/StudentWebClient/Views/Home/CreateProduct.cshtml new file mode 100644 index 0000000..c6cb1e0 --- /dev/null +++ b/SchoolAgainStudy/StudentWebClient/Views/Home/CreateProduct.cshtml @@ -0,0 +1,32 @@ +@{ + ViewData["Title"] = "CreateProduct"; +} +
+

Создание изделия

+
+
+ +
+
Название:
+
+
+
+
Описание:
+
:
+
+
+
Дата создания:
+
@Html.TextBox("dateCreate" ,"" ,new {type="Date"})
+
+
+
Интересы:
+
+ @Html.ListBox("interests", (MultiSelectList)ViewBag.Interests) +
+
+
+
+
+
+ +
\ No newline at end of file diff --git a/SchoolAgainStudy/StudentWebClient/Views/Home/DiySetting.cshtml b/SchoolAgainStudy/StudentWebClient/Views/Home/DiySetting.cshtml index c6ef3eb..8c08905 100644 --- a/SchoolAgainStudy/StudentWebClient/Views/Home/DiySetting.cshtml +++ b/SchoolAgainStudy/StudentWebClient/Views/Home/DiySetting.cshtml @@ -19,11 +19,11 @@
Описание:
-
:
+
Дата создания:
-
@Html.TextBox("dateCreate" ,"" ,new {type="Date"})
+
@Html.TextBox("dateCreate", Model.DateCreate.Date.ToString("yyyy-MM-dd"),new {type="Date"})
Задание:
diff --git a/SchoolAgainStudy/StudentWebClient/Views/Home/Diyes.cshtml b/SchoolAgainStudy/StudentWebClient/Views/Home/Diyes.cshtml index e79a395..17d7619 100644 --- a/SchoolAgainStudy/StudentWebClient/Views/Home/Diyes.cshtml +++ b/SchoolAgainStudy/StudentWebClient/Views/Home/Diyes.cshtml @@ -34,6 +34,9 @@ Задание + + Интересы + @@ -50,6 +53,9 @@ @Html.DisplayFor(modelItem => item.TaskName) + + + U diff --git a/SchoolAgainStudy/StudentWebClient/Views/Home/ProductSetting.cshtml b/SchoolAgainStudy/StudentWebClient/Views/Home/ProductSetting.cshtml new file mode 100644 index 0000000..d64a307 --- /dev/null +++ b/SchoolAgainStudy/StudentWebClient/Views/Home/ProductSetting.cshtml @@ -0,0 +1,35 @@ +@using SchoolAgainStudyContracts.ViewModel; +@model ProductViewModel +@{ + ViewData["Title"] = "Setting"; +} +
+

@Model.Title

+
+
+
+
+ + +
+
+
+
Название:
+
+
+
+
Описание:
+
:
+
+
+
Дата создания:
+
@Html.TextBox("dateCreate" ,Model.DateCreate.Date.ToString("yyyy-MM-dd") ,new {type="Date"})
+
+
+
Интересы:
+
+ @Html.ListBox("interests", (MultiSelectList)ViewBag.Interests) +
+
+ +
diff --git a/SchoolAgainStudy/StudentWebClient/Views/Home/Products.cshtml b/SchoolAgainStudy/StudentWebClient/Views/Home/Products.cshtml new file mode 100644 index 0000000..7220779 --- /dev/null +++ b/SchoolAgainStudy/StudentWebClient/Views/Home/Products.cshtml @@ -0,0 +1,62 @@ +@using SchoolAgainStudyContracts.ViewModel; + +@model List + +@{ + ViewData["Title"] = "Home Page"; +} + +
+

Изделия

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

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

+ return; + } + +

+ Создать изделие +

+ + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + } + +
+ Название + + Дата создания + + Интересы +
+ @Html.DisplayFor(modelItem => item.Title) + + @Html.DisplayFor(modelItem => item.DateCreate) + + + + U +
+ } +
\ No newline at end of file diff --git a/SchoolAgainStudy/StudentWebClient/Views/Shared/_Layout.cshtml b/SchoolAgainStudy/StudentWebClient/Views/Shared/_Layout.cshtml index f136e27..dd979d8 100644 --- a/SchoolAgainStudy/StudentWebClient/Views/Shared/_Layout.cshtml +++ b/SchoolAgainStudy/StudentWebClient/Views/Shared/_Layout.cshtml @@ -38,6 +38,9 @@ +