From 6aa55f1c115c7680cc589ef11a03a2b80401e0b4 Mon Sep 17 00:00:00 2001 From: dex_moth Date: Wed, 29 May 2024 18:48:47 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B4=D1=83=D0=BA=D1=82?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/ProductBindingModel.cs | 2 +- .../ViewModels/ProductViewModel.cs | 2 +- .../Models/IProductModel.cs | 2 +- .../Models/Product.cs | 5 +- .../Controllers/HomeController.cs | 150 +++++++++++------- .../StoreKeeperClient/Program.cs | 2 +- .../Views/Home/CreateProduct.cshtml | 93 +++++++++++ .../StoreKeeperClient/Views/Home/Index.cshtml | 49 +----- .../Views/Home/Products.cshtml | 91 +++++------ .../Views/Shared/_Layout.cshtml | 3 - .../Controllers/HomeController.cs | 79 ++++++++- 11 files changed, 315 insertions(+), 163 deletions(-) diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/BindingModels/ProductBindingModel.cs b/ComputerHardwareStore/ComputerHardwareStoreContracts/BindingModels/ProductBindingModel.cs index 7c032c7..bcfa87b 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreContracts/BindingModels/ProductBindingModel.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/BindingModels/ProductBindingModel.cs @@ -8,6 +8,6 @@ namespace ComputerHardwareStoreContracts.BindingModels public string Name { get; set; } = string.Empty; public double Price { get; set; } public Dictionary ProductComponents { get; set; } = new(); - public IStoreKeeperModel StoreKeeper { get; set; } + public int StoreKeeperId { get; set; } } } diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/ViewModels/ProductViewModel.cs b/ComputerHardwareStore/ComputerHardwareStoreContracts/ViewModels/ProductViewModel.cs index 024c70d..9bea048 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreContracts/ViewModels/ProductViewModel.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/ViewModels/ProductViewModel.cs @@ -11,6 +11,6 @@ namespace ComputerHardwareStoreContracts.ViewModels [DisplayName("Цена")] public double Price { get; set; } public Dictionary ProductComponents { get; set; } = new(); - public IStoreKeeperModel StoreKeeper { get; set; } + public int StoreKeeperId { get; set; } } } diff --git a/ComputerHardwareStore/ComputerHardwareStoreDataModels/Models/IProductModel.cs b/ComputerHardwareStore/ComputerHardwareStoreDataModels/Models/IProductModel.cs index 5f033a9..69baa87 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDataModels/Models/IProductModel.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDataModels/Models/IProductModel.cs @@ -4,7 +4,7 @@ { string Name { get; } double Price { get; } - public IStoreKeeperModel StoreKeeper { get; } + public int StoreKeeperId { get; } public Dictionary ProductComponents { get; } } } diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs index 44cc5f1..8fcbbf3 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Product.cs @@ -14,8 +14,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models public string Name { get; set; } = string.Empty; [Required] public double Price { get; set; } - [NotMapped] - IStoreKeeperModel IProductModel.StoreKeeper => StoreKeeper; + public int StoreKeeperId { get; set; } public virtual StoreKeeper StoreKeeper {get; set;} = new(); private Dictionary? _productComponents = null; [NotMapped] @@ -65,7 +64,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models Name = Name, Price = Price, ProductComponents = ProductComponents, - StoreKeeper = StoreKeeper, + StoreKeeperId = StoreKeeperId, }; public static void UpdateComponents(ComputerHardwareStoreDBContext context, ProductBindingModel model) diff --git a/ComputerHardwareStore/StoreKeeperClient/Controllers/HomeController.cs b/ComputerHardwareStore/StoreKeeperClient/Controllers/HomeController.cs index 231229a..1a3f927 100644 --- a/ComputerHardwareStore/StoreKeeperClient/Controllers/HomeController.cs +++ b/ComputerHardwareStore/StoreKeeperClient/Controllers/HomeController.cs @@ -18,47 +18,8 @@ namespace StoreKeeperClient.Controllers [HttpGet] public IActionResult Index() { - if (APIClient.Client == null) - { - return Redirect("~/Home/Enter"); - } - - return View(APIClient.GetRequest>($"api/main/getpurchases?storekeeperId={APIClient.Client.Id}")); - } - - [HttpGet] - public IActionResult Privacy() - { - if (APIClient.Client == null) - { - return Redirect("~/Home/Enter"); - } - return View(APIClient.Client); - } - - [HttpPost] - public void Privacy(string login, string password, string fio) - { - if (APIClient.Client == null) - { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); - } - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) - { - throw new Exception("Введите логин, пароль и ФИО"); - } - APIClient.PostRequest("api/storekeeper/updatedata", new StoreKeeperBindingModel - { - Id = APIClient.Client.Id, - Name = fio, - Login = login, - Password = password - }); - APIClient.Client.Name = fio; - APIClient.Client.Login = login; - APIClient.Client.Password = password; - Response.Redirect("Index"); - } + return View(); + } [HttpGet] public IActionResult Enter() @@ -78,7 +39,7 @@ namespace StoreKeeperClient.Controllers { throw new Exception("Неверные почта и/или пароль"); } - Response.Redirect("Index"); + Response.Redirect("Home/Index"); return; } @@ -104,6 +65,7 @@ namespace StoreKeeperClient.Controllers Response.Redirect("Enter"); return; } + [HttpGet] public IActionResult AddBuildToPurchase() { @@ -195,13 +157,103 @@ namespace StoreKeeperClient.Controllers } [HttpGet] - public IActionResult ProductsList() + public IActionResult Products() { if (APIClient.Client == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - return View(new List()); + return View(new List()); + } + + public IActionResult CreateProduct() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Components = APIClient.GetRequest>($"api/component/getcomponents?userId={APIClient.Client.Id}"); + return View(); + } + + [HttpPost] + public void CreateProduct([FromBody] ProductBindingModel productModel) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(productModel.Name)) + { + throw new Exception("Название не должно быть пустым"); + } + if (productModel.Price <= 0) + { + throw new Exception("Цена должна быть больше 0"); + } + productModel.StoreKeeperId = APIClient.Client.Id; + APIClient.PostRequest("api/product/createproduct", productModel); + } + + public IActionResult UpdateProduct(int productid) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + ViewBag.Components = APIClient.GetRequest>($"api/component/getcomponents?userId={APIClient.Client.Id}"); + return View(productid); + } + + [HttpPost] + public void UpdateProduct([FromBody] ProductBindingModel productModel) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(productModel.Name)) + { + throw new Exception("Название не должно быть пустым"); + } + if (productModel.Price <= 0) + { + throw new Exception("Цена должна быть больше 0"); + } + productModel.StoreKeeperId = APIClient.Client.Id; + APIClient.PostRequest("api/product/updatedata", productModel); + } + + [HttpPost] + public void DeleteGood(int model) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (model <= 0) + { + throw new Exception($"Идентификатор товара не может быть меньше или равен 0"); + } + APIClient.PostRequest("api/product/deleteproduct", new ProductBindingModel + { + Id = model + }); + } + + [HttpGet] + public ProductViewModel? GetProduct(int Id) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (Id <= 0) + { + throw new Exception($"Идентификатор товара не может быть меньше или равен 0"); + } + var result = APIClient.GetRequest($"api/product/getproduct?id={Id}"); + return result; } [HttpGet] @@ -234,16 +286,6 @@ namespace StoreKeeperClient.Controllers return View(new List()); } - [HttpGet] - public IActionResult PurchaseUpdate() - { - if (APIClient.Client == null) - { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); - } - return View(); - } - [HttpGet] public IActionResult Report() { diff --git a/ComputerHardwareStore/StoreKeeperClient/Program.cs b/ComputerHardwareStore/StoreKeeperClient/Program.cs index 91cc58d..f83b5a0 100644 --- a/ComputerHardwareStore/StoreKeeperClient/Program.cs +++ b/ComputerHardwareStore/StoreKeeperClient/Program.cs @@ -20,6 +20,6 @@ app.UseAuthorization(); app.MapControllerRoute( name: "default", -pattern: "{controller=Home}/{action=Index}/{id?}"); +pattern: "{controller=Home}/{action=Enter}/{id?}"); app.Run(); diff --git a/ComputerHardwareStore/StoreKeeperClient/Views/Home/CreateProduct.cshtml b/ComputerHardwareStore/StoreKeeperClient/Views/Home/CreateProduct.cshtml index 27fde07..7191538 100644 --- a/ComputerHardwareStore/StoreKeeperClient/Views/Home/CreateProduct.cshtml +++ b/ComputerHardwareStore/StoreKeeperClient/Views/Home/CreateProduct.cshtml @@ -34,3 +34,96 @@ + +@section Scripts + { + +} \ No newline at end of file diff --git a/ComputerHardwareStore/StoreKeeperClient/Views/Home/Index.cshtml b/ComputerHardwareStore/StoreKeeperClient/Views/Home/Index.cshtml index f8bd19a..5ffcdd3 100644 --- a/ComputerHardwareStore/StoreKeeperClient/Views/Home/Index.cshtml +++ b/ComputerHardwareStore/StoreKeeperClient/Views/Home/Index.cshtml @@ -1,5 +1,4 @@ @using ComputerHardwareStoreContracts.ViewModels -@model List @{ ViewData["Title"] = "Home Page"; } @@ -11,54 +10,8 @@ @{ if (Model == null) { -

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

+

Добро пожаловать

return; } -

- Создать заказ -

- - - - - - - - - - - - - @foreach (var item in Model) - { - - - - - - - } - -
- Номер - - Изделие - - Дата создания - - Количество - - Сумма - - Статус -
- @Html.DisplayFor(modelItem => item.Id) - - @Html.DisplayFor(modelItem => item.DateCreate) - - @Html.DisplayFor(modelItem => item.Sum) - - @Html.DisplayFor(modelItem => item.Status) -
} \ No newline at end of file diff --git a/ComputerHardwareStore/StoreKeeperClient/Views/Home/Products.cshtml b/ComputerHardwareStore/StoreKeeperClient/Views/Home/Products.cshtml index 6a028f6..07fa8a8 100644 --- a/ComputerHardwareStore/StoreKeeperClient/Views/Home/Products.cshtml +++ b/ComputerHardwareStore/StoreKeeperClient/Views/Home/Products.cshtml @@ -7,52 +7,53 @@

Товары

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

Надо войти!

- return; - } -

- Создать товар - Изменить товар - Удалить товар -

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

Надо войти!

+ return; + } +

+ Создать товар + Изменить товар + Удалить товар +

- - - - - - +
- Номер - - Название - - Цена -
+ + + + - - - - - @foreach (var Product in Model) - { - - - - - - } - - -
+ Номер + + Название +
- @Html.DisplayFor(modelItem => Product.Id) - - @Html.DisplayFor(modelItem => Product.Name) - - @Html.DisplayFor(modelItem => Product.Price) -
- } + + Цена + + + + + + + @foreach (var Product in Model) + { + + + @Html.DisplayFor(modelItem => Product.Id) + + + @Html.DisplayFor(modelItem => Product.Name) + + + @Html.DisplayFor(modelItem => Product.Price) + + + } + + + + }
diff --git a/ComputerHardwareStore/StoreKeeperClient/Views/Shared/_Layout.cshtml b/ComputerHardwareStore/StoreKeeperClient/Views/Shared/_Layout.cshtml index 93d0db2..2ab157b 100644 --- a/ComputerHardwareStore/StoreKeeperClient/Views/Shared/_Layout.cshtml +++ b/ComputerHardwareStore/StoreKeeperClient/Views/Shared/_Layout.cshtml @@ -19,9 +19,6 @@