// GET: AutoComplete


        /// <summary>
        /// AutoComplete Book Suggestions
        /// </summary>
        /// <param>term</param>
        ///   <returns>JsonResult</returns>
        public JsonResult AutoCompleteBook(string term)
        {
            try
            {
                BooksModel     obj   = new BooksModel();
                SearchCriteria sc    = new SearchCriteria();
                SearchCriteria Count = new SearchCriteria();
                Count.Text    = string.Empty;
                sc.Text       = term;
                sc.StartIndex = 0;
                sc.EndIndex   = obj.TotalBooks(Count);
                return(Json(obj.GetAllBooks(sc), JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Logging.Error(ex.Message);
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Brings The DataBack to Books Table Based on Filter
        /// </summary>
        /// <param> Table Parameters</param>
        ///   <param> Search Criteria</param>
        ///   <returns>JqDataTable</returns>
        private JqDataTable <object[]> SearchInBooks(jQueryDataTableParamModel param, string searchCriteria)
        {
            try
            {
                SearchCriteria criteria = ConvertFromJsonToObject <SearchCriteria>(searchCriteria);

                int startIndex = 0;
                if (param.iDisplayStart > 0)
                {
                    startIndex = param.iDisplayStart + 1;
                }
                else
                {
                    startIndex = param.iDisplayStart;
                }

                criteria.StartIndex = startIndex;
                criteria.EndIndex   = param.iDisplayStart + param.iDisplayLength;
                criteria.SortOrder  = param.sSortDir_0;
                criteria.SortingCol = param.iSortCol_0;

                if (String.IsNullOrWhiteSpace(criteria.Text))
                {
                    criteria.Text = String.Empty;
                }

                BooksModel obj   = new BooksModel();
                int        count = obj.TotalBooks(criteria);

                var data = new List <object[]>();

                IList <BooksModel> bModel = new List <BooksModel>();
                bModel = obj.GetAllBooks(criteria);


                foreach (BooksModel item in bModel)
                {
                    var array = new object[7];
                    array[0] = item.ID;
                    array[1] = item.Title;
                    array[2] = item.Author;
                    array[3] = (item.TotalInStock - item.TotalAssigned > 0) ? "Y" : "N";
                    array[4] = item.TotalInStock;
                    array[5] = item.TotalAssigned;
                    array[6] = item.ID;

                    data.Add(array);
                }

                return(new JqDataTable <object[]>
                {
                    sEcho = param.sEcho,
                    iTotalRecords = count,
                    iTotalDisplayRecords = count,
                    aaData = data
                });
            }

            catch (Exception ex)
            {
                Logging.Error(ex.Message);
                return(null);
            }
        }