-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Small addition to BaseODataController, reusable JS code in MVC OData …
…demo and updated some NuGet packages.
- Loading branch information
1 parent
10df0f3
commit 3e99016
Showing
13 changed files
with
156 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
Demos/Demo.AspNetCore.Mvc.OData/wwwroot/js/odata-helpers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
async function getOData(url) { | ||
return await fetch(url) | ||
.then(response => response.json()) | ||
.catch(error => { | ||
$.notify({ message: "Error when trying to retrieve record!", icon: 'fa fa-exclamation-triangle' }, { type: 'danger' }); | ||
console.error('Error: ', error); | ||
}); | ||
} | ||
|
||
async function deleteOData(url) { | ||
if (confirm("Are you sure that you want to delete this record?")) { | ||
await fetch(url, { method: 'DELETE' }) | ||
.then(response => { | ||
if (response.ok) { | ||
refreshODataGrid(); | ||
$.notify({ message: "Successfully deleted record!", icon: 'fa fa-check' }, { type: 'success' }); | ||
} else { | ||
$.notify({ message: "Error when trying to retrieve record!", icon: 'fa fa-exclamation-triangle' }, { type: 'danger' }); | ||
} | ||
}) | ||
.catch(error => { | ||
$.notify({ message: "Error when trying to retrieve record!", icon: 'fa fa-exclamation-triangle' }, { type: 'danger' }); | ||
console.error('Error: ', error); | ||
}); | ||
} | ||
} | ||
|
||
async function postOData(url, record) { | ||
return await fetch(url, { | ||
method: "POST", | ||
headers: { | ||
'Content-type': 'application/json; charset=utf-8' | ||
}, | ||
body: JSON.stringify(record) | ||
}) | ||
.then(response => { | ||
if (response.ok) { | ||
refreshODataGrid(); | ||
switchSection($("#grid-section")); | ||
$.notify({ message: "Successfully inserted record!", icon: 'fa fa-check' }, { type: 'success' }); | ||
} | ||
else { | ||
$.notify({ message: "Error when trying to insert record!", icon: 'fa fa-exclamation-triangle' }, { type: 'danger' }); | ||
} | ||
return response; | ||
}) | ||
.catch(error => { | ||
$.notify({ message: "Error when trying to insert record!", icon: 'fa fa-exclamation-triangle' }, { type: 'danger' }); | ||
console.error('Error: ', error); | ||
}); | ||
} | ||
|
||
async function putOData(url, record) { | ||
return await fetch(url, { | ||
method: "PUT", | ||
headers: { | ||
'Content-type': 'application/json; charset=utf-8' | ||
}, | ||
body: JSON.stringify(record) | ||
}) | ||
.then(response => { | ||
if (response.ok) { | ||
refreshODataGrid(); | ||
switchSection($("#grid-section")); | ||
$.notify({ message: "Successfully updated record!", icon: 'fa fa-check' }, { type: 'success' }); | ||
} | ||
else { | ||
$.notify({ message: "Error when trying to update record!", icon: 'fa fa-exclamation-triangle' }, { type: 'danger' }); | ||
} | ||
return response; | ||
}) | ||
.catch(error => { | ||
$.notify({ message: "Error when trying to update record!", icon: 'fa fa-exclamation-triangle' }, { type: 'danger' }); | ||
console.error('Error: ', error); | ||
}); | ||
} | ||
|
||
async function patchOData(url, patch) { | ||
return await fetch(url, { | ||
method: "PATCH", | ||
headers: { | ||
'Content-type': 'application/json; charset=utf-8' | ||
}, | ||
body: JSON.stringify(patch) | ||
}) | ||
.then(response => { | ||
if (response.ok) { | ||
refreshODataGrid(); | ||
$.notify({ message: "Successfully updated record!", icon: 'fa fa-check' }, { type: 'success' }); | ||
} | ||
else { | ||
$.notify({ message: "Error when trying to update record!", icon: 'fa fa-exclamation-triangle' }, { type: 'danger' }); | ||
} | ||
return response; | ||
}) | ||
.catch(error => { | ||
$.notify({ message: "Error when trying to update record!", icon: 'fa fa-exclamation-triangle' }, { type: 'danger' }); | ||
console.error('Error: ', error); | ||
}); | ||
} | ||
|
||
function refreshODataGrid() { | ||
$('#grid').data('kendoGrid').dataSource.read(); | ||
$('#grid').data('kendoGrid').refresh(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
// Write your JavaScript code. | ||
// Write your JavaScript code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.