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 @@
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();
+ }
+ }
}
}