SHARE
TWEET

Untitled

a guest Nov 14th, 2019 165 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///Controller Part
  2. public IActionResult RestaurantSearch(string RestaurantName)
  3.         {
  4.             var result = _context.RestaurantViewModel.FromSql($"usp_RestaurantSearch @RestaurantName", new SqlParameter("@RestaurantName", RestaurantName)).ToList();
  5.             return Json(result);
  6.         }
  7. ////JS PArt
  8. function getData(displayRecords) {
  9.     var restaurants = "";
  10.     for (var i = 0; i < displayRecords.length; i++) {
  11.         var rulename = "";
  12.         if (displayRecords[i].status) {
  13.             rulename = '<div class="card-header bg-dark" >' + displayRecords[i].ruleName + '</div >';
  14.         }
  15.         restaurants +=
  16.             "<div class='col-md-4 searchName'>" +
  17.             "<div class='card text-light bg-light mb-3 text-center' style='max-width: 18rem;' id='searchcard'> " +
  18.             rulename +
  19.             "<div class='card-body text-dark'>" +
  20.             "<h5 class='card-title'>" + displayRecords[i].restaurantName + "</h5>" +
  21.             "<p class='card-text'>" + displayRecords[i].address + "</p>" +
  22.             "<p class='card-text'>" + displayRecords[i].contactNo + "</p>" +
  23.             "<input type='button' class='restaurantCard btn btn-info' id='" + displayRecords[i].restaurantId + "BtnUser' value='Order Now' /input > " +
  24.             "</div>" +
  25.             "</div>" +
  26.             "</div>";
  27.     }
  28.     $('#restaurantList').html("");
  29.     $('#restaurantList').append(restaurants);
  30. }
  31. $(document).ready(function () {
  32.     RestaurantList(3);
  33.     $('#selectList').on('change', function () {
  34.         flag = $('#selectList').val();
  35.         RestaurantList(flag);
  36.     });
  37.     var $pagination = $('#pagination'),
  38.         totalRecords = 0,
  39.         records = [],
  40.         displayRecords = [],
  41.         recPerPage = 3,
  42.         page = 1,
  43.         totalPages = 0;
  44.     function RestaurantList(flag) {
  45.         $.ajax({
  46.             url: location.origin + '/Restaurant/GetList',
  47.             method: 'GET',
  48.             data: { flag: flag },
  49.             success: function (data) {
  50.                 console.log(data);
  51.                 records = data;
  52.                 totalRecords = records.length;
  53.                 totalPages = Math.ceil(totalRecords / recPerPage);
  54.                 apply_pagination();
  55.             }
  56.         });
  57.     }
  58.     //$.ajax({
  59.     //    url: location.origin + "/Restaurant/GetList",
  60.     //    async: true,      
  61.     //    dataType: 'json',
  62.     //    success: function (data) {
  63.     //        records = data;
  64.     //        totalRecords = records.length;
  65.     //        totalPages = Math.ceil(totalRecords / recPerPage);
  66.     //        apply_pagination();
  67.     //    }
  68.     //});
  69.     function generate_table() {
  70.        // console.log(displayRecords)
  71.         getData(displayRecords);
  72.         $('.restaurantCard').click(function () {
  73.             // console.log(this.id);
  74.             var id = this.id.split("BtnUser");
  75.             //console.log(id[0]);
  76.             $.ajax({
  77.                 url: location.origin + '/Restaurant/RestaurantList',
  78.                 method: 'GET',
  79.                 data: { RestaurantId: id[0] },
  80.                 async: false,
  81.                 success: function () {
  82.                     location.assign(location.origin + "/Restaurant/RestaurantList/" + id[0]);
  83.                 }
  84.             }).responseJSON;
  85.         });
  86.     }
  87.  
  88.     function apply_pagination() {
  89.         $pagination.twbsPagination({
  90.             totalPages: totalPages,
  91.             visiblePages: 6,
  92.             onPageClick: function (event, page) {
  93.                 displayRecordsIndex = Math.max(page - 1, 0) * recPerPage;
  94.                 endRec = (displayRecordsIndex) + recPerPage;
  95.                 displayRecords = records.slice(displayRecordsIndex, endRec);
  96.                 generate_table();
  97.             }
  98.         });
  99.     }
  100.  
  101.     $("#filterrestro").on("keyup", function () {
  102.         $("#clear").show();
  103.     });
  104.  
  105.     $('#clear').on("click", function () {
  106.         $('#filterrestro').val('');
  107.         $("#clear").hide();
  108.         generate_table();
  109.         $('#noRecord').html('');
  110.     });
  111.  
  112.     $("#findRestaurant").on("click", function () {
  113.         var value = $('#filterrestro').val().toLowerCase();
  114.         $.ajax({
  115.             url: location.origin + '/Restaurant/RestaurantSearch',
  116.             method: 'GET',
  117.             data: { RestaurantName: value },
  118.             success: function (data) {
  119.                 if (data == '') {
  120.                     $('#noRecord').html("No results found with your search criteria. Please try again !!");
  121.                 }
  122.                 getData(data);
  123.             }
  124.         });
  125.  
  126.     });
  127. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top