delete added
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
|
<th>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="resultarea">
|
<tbody id="resultarea">
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ async function getCustomers()
|
|||||||
console.log(customers);
|
console.log(customers);
|
||||||
display();
|
display();
|
||||||
});
|
});
|
||||||
}
|
} customers.forEach(customer => {
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
function display()
|
function display()
|
||||||
{
|
{
|
||||||
@@ -22,6 +25,8 @@ function display()
|
|||||||
+ t.id +
|
+ t.id +
|
||||||
'</td><td>'
|
'</td><td>'
|
||||||
+ t.name +
|
+ t.name +
|
||||||
|
'</td><td>'
|
||||||
|
+ '<button type="button" onclick="deleteCustomer(' + t.id + ')">Delete</button>' +
|
||||||
'</td></tr>';
|
'</td></tr>';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -33,7 +38,24 @@ function addCustomer()
|
|||||||
fetch('https://localhost:5001/api/Customer', {
|
fetch('https://localhost:5001/api/Customer', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ name: customerName })
|
body: JSON.stringify({
|
||||||
|
name: customerName,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(response => response)
|
||||||
|
.then(data =>
|
||||||
|
{
|
||||||
|
console.log("Success: ", data)
|
||||||
|
getCustomers();
|
||||||
|
})
|
||||||
|
.catch(error => console.error("Error: ", error));
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteCustomer(id)
|
||||||
|
{
|
||||||
|
fetch('https://localhost:5001/api/Customer/' + id, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
})
|
})
|
||||||
.then(response => response)
|
.then(response => response)
|
||||||
.then(data =>
|
.then(data =>
|
||||||
|
|||||||
Reference in New Issue
Block a user