added scripts to all tables
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Customers</title>
|
<title>Customers</title>
|
||||||
<link rel="stylesheet" type="text/css" href="style.css">
|
<link rel="stylesheet" type="text/css" href="style.css">
|
||||||
|
<script src="customers.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Customers</h1>
|
<h1>Customers</h1>
|
||||||
@@ -45,9 +46,9 @@
|
|||||||
<td class="inputcell"><input type="text" id="in_service_id"></td>
|
<td class="inputcell"><input type="text" id="in_service_id"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2"><button onclick="addService()">Save</button></td>
|
<td colspan="2"><button onclick="addcustomer()">Save</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<div id="addresult"></div>
|
<h2 id="addresult"></h2>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
113
WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/customers.js
Normal file
113
WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/customers.js
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
let customers = [];
|
||||||
|
getcustomers();
|
||||||
|
|
||||||
|
async function getcustomers()
|
||||||
|
{
|
||||||
|
await fetch('https://localhost:5001/api/Customer')
|
||||||
|
.then(x => x.json())
|
||||||
|
.then(y => {
|
||||||
|
customers = y;
|
||||||
|
console.log(customers);
|
||||||
|
display();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function display()
|
||||||
|
{
|
||||||
|
document.getElementById('resultarea').innerHTML = '';
|
||||||
|
|
||||||
|
customers.forEach(t => {
|
||||||
|
document.getElementById('resultarea').innerHTML +=
|
||||||
|
'<tr><td>'
|
||||||
|
+ t.id +
|
||||||
|
'</td><td>'
|
||||||
|
+ t.name +
|
||||||
|
'</td><td>'
|
||||||
|
+ '<button type="button" onclick="deletecustomer(' + t.id + ')">Delete</button>'
|
||||||
|
+ '</td><td>'
|
||||||
|
+ '<button type="button" onclick="updatecustomer(' + t.id + ')">Edit</button>'
|
||||||
|
+ '</td></tr>';
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('resultarea').innerHTML +=
|
||||||
|
'<tr>' +
|
||||||
|
'<td colspan="4">' +
|
||||||
|
'<a class="bookmark" href="#add">Add new</a>' +
|
||||||
|
'</td>' +
|
||||||
|
'</tr>';
|
||||||
|
}
|
||||||
|
|
||||||
|
function updatecustomer(id)
|
||||||
|
{
|
||||||
|
let customer_id = document.getElementById('in_id').value;
|
||||||
|
let customer_name = document.getElementById('in_name').value;
|
||||||
|
let customer_email = document.getElementById('in_email').value;
|
||||||
|
let customer_phone = document.getElementById('in_phone').value;
|
||||||
|
let customer_service_id = document.getElementById('in_service_id').value;
|
||||||
|
|
||||||
|
fetch ('https://localhost:5001/api/Customer/' + id, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
id: customer_id,
|
||||||
|
name: customer_name,
|
||||||
|
email: customer_email,
|
||||||
|
phone: customer_phone,
|
||||||
|
service_id: customer_service_id
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function addcustomer()
|
||||||
|
{
|
||||||
|
let customer_id = document.getElementById('in_id').value;
|
||||||
|
let customer_name = document.getElementById('in_name').value;
|
||||||
|
let customer_email = document.getElementById('in_email').value;
|
||||||
|
let customer_phone = document.getElementById('in_phone').value;
|
||||||
|
let customer_service_id = document.getElementById('in_service_id').value;
|
||||||
|
|
||||||
|
fetch('https://localhost:5001/api/Customer', {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
id: customer_id,
|
||||||
|
name: customer_name,
|
||||||
|
email: customer_email,
|
||||||
|
phone: customer_phone,
|
||||||
|
service_id: customer_service_id
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(response => response)
|
||||||
|
.then(data => {
|
||||||
|
console.log("Success: ", data)
|
||||||
|
|
||||||
|
document.getElementById('addresult').innerHTML = '';
|
||||||
|
document.getElementById('addresult').innerHTML +=
|
||||||
|
'Added customer ' + customer_name + ' successfully';
|
||||||
|
|
||||||
|
getcustomers();
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error("Error: ", error);
|
||||||
|
|
||||||
|
document.getElementById('addresult').innerHTML = '';
|
||||||
|
document.getElementById('addresult').innerHTML +=
|
||||||
|
'Failed to add customer ' + customer_name;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deletecustomer(id)
|
||||||
|
{
|
||||||
|
fetch('https://localhost:5001/api/Customer/' + id, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
})
|
||||||
|
.then(response => response)
|
||||||
|
.then(data =>
|
||||||
|
{
|
||||||
|
console.log("Success: ", data)
|
||||||
|
getcustomers();
|
||||||
|
})
|
||||||
|
.catch(error => console.error("Error: ", error));
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Employees</title>
|
<title>Employees</title>
|
||||||
<link rel="stylesheet" type="text/css" href="style.css">
|
<link rel="stylesheet" type="text/css" href="style.css">
|
||||||
|
<script src="employees.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Employees</h1>
|
<h1>Employees</h1>
|
||||||
@@ -45,9 +46,13 @@
|
|||||||
<td class="inputcell"><input type="text" id="in_maintainer_id"></td>
|
<td class="inputcell"><input type="text" id="in_maintainer_id"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2"><button onclick="addService()">Save</button></td>
|
<td>Manager ID</td>
|
||||||
|
<td class="inputcell"><input type="text" id="in_manager_id"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2"><button onclick="addemployee()">Save</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<div id="addresult"></div>
|
<h2 id="addresult"></h2>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
117
WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/employees.js
Normal file
117
WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/employees.js
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
let employees = [];
|
||||||
|
getemployees();
|
||||||
|
|
||||||
|
async function getemployees()
|
||||||
|
{
|
||||||
|
await fetch('https://localhost:5001/api/Employee')
|
||||||
|
.then(x => x.json())
|
||||||
|
.then(y => {
|
||||||
|
employees = y;
|
||||||
|
console.log(employees);
|
||||||
|
display();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function display()
|
||||||
|
{
|
||||||
|
document.getElementById('resultarea').innerHTML = '';
|
||||||
|
|
||||||
|
employees.forEach(t => {
|
||||||
|
document.getElementById('resultarea').innerHTML +=
|
||||||
|
'<tr><td>'
|
||||||
|
+ t.id +
|
||||||
|
'</td><td>'
|
||||||
|
+ t.name +
|
||||||
|
'</td><td>'
|
||||||
|
+ '<button type="button" onclick="deleteemployee(' + t.id + ')">Delete</button>'
|
||||||
|
+ '</td><td>'
|
||||||
|
+ '<button type="button" onclick="updateemployee(' + t.id + ')">Edit</button>'
|
||||||
|
+ '</td></tr>';
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('resultarea').innerHTML +=
|
||||||
|
'<tr>' +
|
||||||
|
'<td colspan="4">' +
|
||||||
|
'<a class="bookmark" href="#add">Add new</a>' +
|
||||||
|
'</td>' +
|
||||||
|
'</tr>';
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateemployee(id)
|
||||||
|
{
|
||||||
|
let employee_id = document.getElementById('in_id').value;
|
||||||
|
let employee_name = document.getElementById('in_name').value;
|
||||||
|
let employee_email = document.getElementById('in_email').value;
|
||||||
|
let employee_phone = document.getElementById('in_phone').value;
|
||||||
|
let employee_manager_id = document.getElementById('in_manager_id').value;
|
||||||
|
let employee_maintainer_id = document.getElementById('in_maintainer_id').value;
|
||||||
|
|
||||||
|
fetch ('https://localhost:5001/api/Employee/' + id, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
id: employee_id,
|
||||||
|
name: employee_name,
|
||||||
|
email: employee_email,
|
||||||
|
phone: employee_phone,
|
||||||
|
manager_id: employee_manager_id,
|
||||||
|
maintainer_id: employee_maintainer_id
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function addemployee()
|
||||||
|
{
|
||||||
|
let employee_id = document.getElementById('in_id').value;
|
||||||
|
let employee_name = document.getElementById('in_name').value;
|
||||||
|
let employee_email = document.getElementById('in_email').value;
|
||||||
|
let employee_phone = document.getElementById('in_phone').value;
|
||||||
|
let employee_manager_id = document.getElementById('in_manager_id').value;
|
||||||
|
let employee_maintainer_id = document.getElementById('in_maintainer_id').value;
|
||||||
|
|
||||||
|
fetch('https://localhost:5001/api/Employee', {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
id: employee_id,
|
||||||
|
name: employee_name,
|
||||||
|
email: employee_email,
|
||||||
|
phone: employee_phone,
|
||||||
|
manager_id: employee_manager_id,
|
||||||
|
maintainer_id: employee_maintainer_id
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(response => response)
|
||||||
|
.then(data => {
|
||||||
|
console.log("Success: ", data)
|
||||||
|
|
||||||
|
document.getElementById('addresult').innerHTML = '';
|
||||||
|
document.getElementById('addresult').innerHTML +=
|
||||||
|
'Added employee ' + employee_name + ' successfully';
|
||||||
|
|
||||||
|
getemployees();
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error("Error: ", error);
|
||||||
|
|
||||||
|
document.getElementById('addresult').innerHTML = '';
|
||||||
|
document.getElementById('addresult').innerHTML +=
|
||||||
|
'Failed to add maintainer team ' + employee_name;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteemployee(id)
|
||||||
|
{
|
||||||
|
fetch('https://localhost:5001/api/Employee/' + id, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
})
|
||||||
|
.then(response => response)
|
||||||
|
.then(data =>
|
||||||
|
{
|
||||||
|
console.log("Success: ", data)
|
||||||
|
getemployees();
|
||||||
|
})
|
||||||
|
.catch(error => console.error("Error: ", error));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user