Try impliment of delete product button
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user