Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Controller Part
- public IActionResult RestaurantSearch(string RestaurantName)
- {
- var result = _context.RestaurantViewModel.FromSql($"usp_RestaurantSearch @RestaurantName", new SqlParameter("@RestaurantName", RestaurantName)).ToList();
- return Json(result);
- }
- ////JS PArt
- function getData(displayRecords) {
- var restaurants = "";
- for (var i = 0; i < displayRecords.length; i++) {
- var rulename = "";
- if (displayRecords[i].status) {
- rulename = '<div class="card-header bg-dark" >' + displayRecords[i].ruleName + '</div >';
- }
- restaurants +=
- "<div class='col-md-4 searchName'>" +
- "<div class='card text-light bg-light mb-3 text-center' style='max-width: 18rem;' id='searchcard'> " +
- rulename +
- "<div class='card-body text-dark'>" +
- "<h5 class='card-title'>" + displayRecords[i].restaurantName + "</h5>" +
- "<p class='card-text'>" + displayRecords[i].address + "</p>" +
- "<p class='card-text'>" + displayRecords[i].contactNo + "</p>" +
- "<input type='button' class='restaurantCard btn btn-info' id='" + displayRecords[i].restaurantId + "BtnUser' value='Order Now' /input > " +
- "</div>" +
- "</div>" +
- "</div>";
- }
- $('#restaurantList').html("");
- $('#restaurantList').append(restaurants);
- }
- $(document).ready(function () {
- RestaurantList(3);
- $('#selectList').on('change', function () {
- flag = $('#selectList').val();
- RestaurantList(flag);
- });
- var $pagination = $('#pagination'),
- totalRecords = 0,
- records = [],
- displayRecords = [],
- recPerPage = 3,
- page = 1,
- totalPages = 0;
- function RestaurantList(flag) {
- $.ajax({
- url: location.origin + '/Restaurant/GetList',
- method: 'GET',
- data: { flag: flag },
- success: function (data) {
- console.log(data);
- records = data;
- totalRecords = records.length;
- totalPages = Math.ceil(totalRecords / recPerPage);
- apply_pagination();
- }
- });
- }
- //$.ajax({
- // url: location.origin + "/Restaurant/GetList",
- // async: true,
- // dataType: 'json',
- // success: function (data) {
- // records = data;
- // totalRecords = records.length;
- // totalPages = Math.ceil(totalRecords / recPerPage);
- // apply_pagination();
- // }
- //});
- function generate_table() {
- // console.log(displayRecords)
- getData(displayRecords);
- $('.restaurantCard').click(function () {
- // console.log(this.id);
- var id = this.id.split("BtnUser");
- //console.log(id[0]);
- $.ajax({
- url: location.origin + '/Restaurant/RestaurantList',
- method: 'GET',
- data: { RestaurantId: id[0] },
- async: false,
- success: function () {
- location.assign(location.origin + "/Restaurant/RestaurantList/" + id[0]);
- }
- }).responseJSON;
- });
- }
- function apply_pagination() {
- $pagination.twbsPagination({
- totalPages: totalPages,
- visiblePages: 6,
- onPageClick: function (event, page) {
- displayRecordsIndex = Math.max(page - 1, 0) * recPerPage;
- endRec = (displayRecordsIndex) + recPerPage;
- displayRecords = records.slice(displayRecordsIndex, endRec);
- generate_table();
- }
- });
- }
- $("#filterrestro").on("keyup", function () {
- $("#clear").show();
- });
- $('#clear').on("click", function () {
- $('#filterrestro').val('');
- $("#clear").hide();
- generate_table();
- $('#noRecord').html('');
- });
- $("#findRestaurant").on("click", function () {
- var value = $('#filterrestro').val().toLowerCase();
- $.ajax({
- url: location.origin + '/Restaurant/RestaurantSearch',
- method: 'GET',
- data: { RestaurantName: value },
- success: function (data) {
- if (data == '') {
- $('#noRecord').html("No results found with your search criteria. Please try again !!");
- }
- getData(data);
- }
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement