Skip to content

Commit

Permalink
Delete Book
Browse files Browse the repository at this point in the history
  • Loading branch information
bhrugen committed Oct 4, 2019
1 parent 8f3c476 commit f8e4151
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion BookListRazor/Controllers/BookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<IActionResult> Delete(int id)
}
_db.Book.Remove(bookFromDb);
await _db.SaveChangesAsync();
return Json(new { succues = true, message = "Delete successful" });
return Json(new { success = true, message = "Delete successful" });
}
}
}
3 changes: 2 additions & 1 deletion BookListRazor/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css" />
</head>
<body>
<header>
Expand Down Expand Up @@ -50,7 +51,7 @@
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
<script type="text/javascript" src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>


@RenderSection("Scripts", required: false)
Expand Down
29 changes: 28 additions & 1 deletion BookListRazor/wwwroot/js/bookList.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ function loadDataTable() {
Edit
</a>
&nbsp;
<a class='btn btn-danger text-white' style='cursor:pointer; width:70px;'>
<a class='btn btn-danger text-white' style='cursor:pointer; width:70px;'
onclick=Delete('/api/book?id='+${data})>
Delete
</a>
</div>`;
Expand All @@ -36,3 +37,29 @@ function loadDataTable() {
"width": "100%"
});
}

function Delete(url) {
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover",
icon: "warning",
buttons: true,
dangerMode: true
}).then((willDelete) => {
if (willDelete) {
$.ajax({
type: "DELETE",
url: url,
success: function (data) {
if (data.success) {
toastr.success(data.message);
dataTable.ajax.reload();
}
else {
toastr.error(data.message);
}
}
});
}
});
}

0 comments on commit f8e4151

Please sign in to comment.