Try impliment of delete product button

This commit is contained in:
2025-06-28 14:52:33 -07:00
parent 8aea7d9713
commit 79593592ae
4 changed files with 49 additions and 3 deletions
@@ -103,7 +103,18 @@ namespace MistoxWebsite.Server.Controllers {
}
}
[Route( "api/product/getall" )]
[Route( "api/product/delete" )]
[HttpPost]
public async Task<ActionResult<bool>> DeleteProduct( [FromBody] int productID ) {
try {
await _databaseService.DeleteProduct(productID);
return true;
} catch {
return false;
}
}
[Route("api/product/getall")]
[HttpPost]
public async Task<Product[]> GetAllProducts() {
try {
@@ -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();
}
}
}
}