Skip to content

Commit

Permalink
hotel delete req
Browse files Browse the repository at this point in the history
  • Loading branch information
PathumChinthaka committed Oct 29, 2023
1 parent ecc6e1a commit 77af628
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
2 changes: 1 addition & 1 deletion AddHotelpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ <h1>Manage Hotel Details</h1>
</section>
<Section class="container-fluid p-5">
<div>
<table class="table table-hover rounded-1 w-100">
<table class="table table-hover rounded-1 w-100" id="hotel-details-tbl">
<thead class="table-secondary">
<tr class="hotel-tr">
<th scope="col">HotelID</th>
Expand Down
79 changes: 78 additions & 1 deletion controller/HotelDetailsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

//create hotel details object
function hotelDetails(){

const hotelId = $('#hotel_Id').val();
const hotelName = $('#hotel_Name').val();
const hotelCategory = $('#hotel_Category').val();
Expand Down Expand Up @@ -46,6 +46,7 @@ function hotelDetails(){
return hotelDetails;
}

//hotel details save event
$("#hotel-save-btn").click(function (e) {

//get returned hotel Details object
Expand All @@ -67,4 +68,80 @@ $("#hotel-save-btn").click(function (e) {
alert("An error occurred: " + error);
}
});
});

//get all hotel details
function getAllHotelDetails(){
$.ajax({
url: baseURL + "hotel/getAll",
method: "GET",
success: function (response) {
$("#hotel-details-tbl tbody").empty();
response.forEach(element => {
let rawData = `<tr>
<td class="d-none"> ${element.data.}</td>
<td>${element.data.}</td>
<td> ${element.data.}</td>
<td> ${element.data.}</td>
<td> ${element.data.}</td>
<td> ${element.data.}</td>
<td> ${element.data.}</td>
<td> ${element.data.}</td>
<td> ${element.data.}</td>
<td> ${element.data.}</td>
</tr>`;
$("#Guide-Details-table tbody").append(rawData);
});
},
error: function (xhr, status, error) {
alert("An error occurred: " + error);
}
});
}

$("#hotel-update-btn").click(function (e) {

//get returned hotel Details object
const hotelDetailsObj=hotelDetails();

// Create Put Request
$.ajax({
url: baseURL + "hotel/update",
method: "put",
data: JSON.stringify(hotelDetailsObj),
contentType: "application/json",
dataType: "json",
success: function (response) {
if (response.code == 200) {
alert(response.message);
};
},
error: function (xhr, status, error) {
console.error(error);
alert("An error occurred: " + error);
}
});
});

//delete hotel details event
$("#hotel-delete-btn").click(function (e) {
const hotelId = $('#hotel_Id').val();
const choice = confirm("Do you want to delete this Data ?");
if(hotelId==""){
alert("Hotel Id is Empty");
return;
}else if(choice == true){
$.ajax({
url: baseURL + "hotel/" + hotelId,
method: "delete",
dataType: "json",
success: function (response) {
alert(response.message);
},
error: function (xhr, status, error) {
alert("Package Deleted Succesfully");
}
});
}else{
}
});

0 comments on commit 77af628

Please sign in to comment.