From 7eae092b06702a9734e7c5cc04d2a2ceaf771c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miskolczi=20Rich=C3=A1rd?= Date: Tue, 30 Apr 2024 13:09:39 +0200 Subject: [PATCH] added scripts to all tables --- .../wwwroot/customers.html | 5 +- .../wwwroot/customers.js | 113 +++++++++++++++++ .../wwwroot/employees.html | 9 +- .../wwwroot/employees.js | 117 ++++++++++++++++++ 4 files changed, 240 insertions(+), 4 deletions(-) create mode 100644 WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/customers.js create mode 100644 WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/employees.js diff --git a/WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/customers.html b/WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/customers.html index bd64a66..e6d8e94 100644 --- a/WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/customers.html +++ b/WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/customers.html @@ -4,6 +4,7 @@ Customers +

Customers

@@ -45,9 +46,9 @@ - + -
+

\ No newline at end of file diff --git a/WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/customers.js b/WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/customers.js new file mode 100644 index 0000000..7598a70 --- /dev/null +++ b/WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/customers.js @@ -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 += + '' + + t.id + + '' + + t.name + + '' + + '' + + '' + + '' + + ''; + }); + + document.getElementById('resultarea').innerHTML += + '' + + '' + + 'Add new' + + '' + + ''; +} + +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)); +} \ No newline at end of file diff --git a/WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/employees.html b/WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/employees.html index 130ce0d..da20c6e 100644 --- a/WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/employees.html +++ b/WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/employees.html @@ -4,6 +4,7 @@ Employees +

Employees

@@ -45,9 +46,13 @@ - + Manager ID + + + + -
+

\ No newline at end of file diff --git a/WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/employees.js b/WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/employees.js new file mode 100644 index 0000000..df43a4d --- /dev/null +++ b/WD7UVN_SzTGUI_2023242.Client.JS/wwwroot/employees.js @@ -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 += + '' + + t.id + + '' + + t.name + + '' + + '' + + '' + + '' + + ''; + }); + + document.getElementById('resultarea').innerHTML += + '' + + '' + + 'Add new' + + '' + + ''; +} + +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)); +} \ No newline at end of file