// GET: api/Contacts
        //public ContactsVM GetContacts(string sidx, string sord, int page, int rows)
        //{
        //    var products = _db.Contacts as IEnumerable<Contact>;
        //    var pageIndex = Convert.ToInt32(page) - 1;
        //    var pageSize = rows;
        //    var totalRecords = products.Count();
        //    var totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
        //    products = products.Skip(pageIndex * pageSize).Take(pageSize);
        //    var vm = new ContactsVM
        //    {
        //        Contact = products,
        //        page = page,
        //        records = totalRecords,
        //        total_pages = totalPages
        //    };
        //    return vm;
        //}


        //search
        public ContactsVM GetContacts([ModelBinder(typeof(JqgridBinder))] JQGridRequest request)
        {
            var products     = _db.Contacts as IEnumerable <Contact>;
            var pageIndex    = Convert.ToInt32(request.page) - 1;
            var pageSize     = request.rows;
            var totalRecords = products.Count();
            var totalPages   = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

            products = products.Skip(pageIndex * pageSize).Take(pageSize);
            var vm = new ContactsVM
            {
                Contact     = products,
                page        = request.page,
                records     = totalRecords,
                total_pages = totalPages
            };

            return(vm);
        }
Exemple #2
0
        public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
        {
            NameValueCollection requestQuery = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.Query);
            // JQGridRequest coDto = TypeAdapter.Adapt<NameValueCollection, JQGridRequest>(qu);


            var coDto = new JQGridRequest
            {
                _search     = !string.IsNullOrEmpty(requestQuery["_search"]) && bool.Parse(requestQuery["_search"]),
                filters     = string.IsNullOrEmpty(requestQuery["filters"]) ? "" : requestQuery["filters"],
                nd          = string.IsNullOrEmpty(requestQuery["nd"]) ? 0 : long.Parse(requestQuery["nd"]),
                page        = string.IsNullOrEmpty(requestQuery["page"]) ? 0 : int.Parse(requestQuery["page"]),
                rows        = string.IsNullOrEmpty(requestQuery["rows"]) ? 0 : int.Parse(requestQuery["rows"]),
                seachString = string.IsNullOrEmpty(requestQuery["searchString"]) ? "" : requestQuery["searchString"],
                searchField = string.IsNullOrEmpty(requestQuery["searchField"]) ? "" : requestQuery["searchField"],
                searchOper  = string.IsNullOrEmpty(requestQuery["searchOper"]) ? "" : requestQuery["searchOper"],
                sidx        = string.IsNullOrEmpty(requestQuery["sidx"]) ? 0 : int.Parse(requestQuery["sidx"]),
                sord        = string.IsNullOrEmpty(requestQuery["sord"]) ? "" : requestQuery["sord"]
            };

            bindingContext.Model = coDto;
            return(true);
        }