Try impliment of delete product button
This commit is contained in:
@@ -16,9 +16,12 @@
|
|||||||
<h2 class="gameCard-Price">${{ (product.cost/100).toFixed(2) }}</h2>
|
<h2 class="gameCard-Price">${{ (product.cost/100).toFixed(2) }}</h2>
|
||||||
<button class="gameCard-Button" disabled="">Add To Cart</button>
|
<button class="gameCard-Button" disabled="">Add To Cart</button>
|
||||||
<div *ngIf="auth.loggedInUser.siteData.role == 'Admin'">
|
<div *ngIf="auth.loggedInUser.siteData.role == 'Admin'">
|
||||||
<button style="width: calc(100% - 10px); margin: 5px;" onclick="">
|
<button style="width: calc(50% - 10px); margin: 5px;" onclick="">
|
||||||
Edit
|
Edit
|
||||||
</button>
|
</button>
|
||||||
|
<button style="width: calc(50% - 10px); margin: 5px;" (click)="DeleteItem(product.id)" >
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="auth.loggedInUser.siteData.role == 'Admin'">
|
<div *ngIf="auth.loggedInUser.siteData.role == 'Admin'">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Component, NgZone } from '@angular/core';
|
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 { FormsModule, NgModel } from '@angular/forms';
|
||||||
import { Router, ActivatedRoute, RouterModule } from '@angular/router';
|
import { Router, ActivatedRoute, RouterModule } from '@angular/router';
|
||||||
import { Title } from '@angular/platform-browser';
|
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<boolean>( "https://mistox.com/api/product/delete", body, { headers } ).subscribe({
|
||||||
|
next: data => {
|
||||||
|
if (data){
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -103,6 +103,17 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[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")]
|
[Route("api/product/getall")]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<Product[]> GetAllProducts() {
|
public async Task<Product[]> GetAllProducts() {
|
||||||
|
|||||||
@@ -134,5 +134,22 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
await AddAllImages(Item);
|
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