From 79593592aeca2ba984a1e6ad2b643a8043e0698e Mon Sep 17 00:00:00 2001 From: Derek Holloway Date: Sat, 28 Jun 2025 14:52:33 -0700 Subject: [PATCH] Try impliment of delete product button --- .../pages/store/catalog/catalog.component.html | 5 ++++- .../pages/store/catalog/catalog.component.ts | 17 ++++++++++++++++- .../Controllers/ProductController.cs | 13 ++++++++++++- .../Services/DatabaseService/Product.cs | 17 +++++++++++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/MistoxWebsite.Client/src/app/pages/store/catalog/catalog.component.html b/src/MistoxWebsite.Client/src/app/pages/store/catalog/catalog.component.html index dc4e4eb..178b0a5 100644 --- a/src/MistoxWebsite.Client/src/app/pages/store/catalog/catalog.component.html +++ b/src/MistoxWebsite.Client/src/app/pages/store/catalog/catalog.component.html @@ -16,9 +16,12 @@

${{ (product.cost/100).toFixed(2) }}

- +
diff --git a/src/MistoxWebsite.Client/src/app/pages/store/catalog/catalog.component.ts b/src/MistoxWebsite.Client/src/app/pages/store/catalog/catalog.component.ts index 5460c28..2899efb 100644 --- a/src/MistoxWebsite.Client/src/app/pages/store/catalog/catalog.component.ts +++ b/src/MistoxWebsite.Client/src/app/pages/store/catalog/catalog.component.ts @@ -1,5 +1,5 @@ import { Component, NgZone } from '@angular/core'; -import { HttpClient } from '@angular/common/http'; +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { FormsModule, NgModel } from '@angular/forms'; import { Router, ActivatedRoute, RouterModule } from '@angular/router'; import { Title } from '@angular/platform-browser'; @@ -39,4 +39,19 @@ export class CatalogComponent { } ) }; + + DeleteItem( ProductID: number ) { + const body = new HttpParams() + .set("productID", ProductID); + const headers = new HttpHeaders({ + 'Content-Type': 'application/x-www-form-urlencoded', + }); + this.http.post( "https://mistox.com/api/product/delete", body, { headers } ).subscribe({ + next: data => { + if (data){ + window.location.reload(); + } + } + }) + } } \ No newline at end of file diff --git a/src/MistoxWebsite.Server/Controllers/ProductController.cs b/src/MistoxWebsite.Server/Controllers/ProductController.cs index ebc0c4c..a36f4a0 100755 --- a/src/MistoxWebsite.Server/Controllers/ProductController.cs +++ b/src/MistoxWebsite.Server/Controllers/ProductController.cs @@ -103,7 +103,18 @@ namespace MistoxWebsite.Server.Controllers { } } - [Route( "api/product/getall" )] + [Route( "api/product/delete" )] + [HttpPost] + public async Task> DeleteProduct( [FromBody] int productID ) { + try { + await _databaseService.DeleteProduct(productID); + return true; + } catch { + return false; + } + } + + [Route("api/product/getall")] [HttpPost] public async Task GetAllProducts() { try { diff --git a/src/MistoxWebsite.Server/Services/DatabaseService/Product.cs b/src/MistoxWebsite.Server/Services/DatabaseService/Product.cs index 8ca96b4..d42a046 100755 --- a/src/MistoxWebsite.Server/Services/DatabaseService/Product.cs +++ b/src/MistoxWebsite.Server/Services/DatabaseService/Product.cs @@ -134,5 +134,22 @@ namespace MistoxWebsite.Server.Services.DatabaseService { await AddAllImages(Item); } } + + public async Task DeleteProduct(int ProductID) { + using (MySqlConnection connection = GetConnection()) { + + await DeleteAllImages(ProductID); + + connection.Open(); + string command = @" + DELETE FROM Product + WHERE ID = @ID; + "; + MySqlCommand cmd = new MySqlCommand(command, connection); + cmd.Parameters.AddWithValue("@ID", ProductID); + + await cmd.ExecuteNonQueryAsync(); + } + } } }