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 @@ +