Esempio n. 1
0
        public JsonResult DatatablesOcorrencias([ModelBinder(typeof(DataTablesBinder))] DataTables.Mvc.IDataTablesRequest requestModel)
        {
            using (var db = new GuardaDigitalContext())
            {
                IQueryable <Ocorrencia> query = db.Ocorrencia;

                var totalCount = query.Count();

                if (requestModel.Search.Value != String.Empty)
                {
                    decimal valor = 0;
                    decimal.TryParse(requestModel.Search.Value, out valor);

                    var value = requestModel.Search.Value.Trim();
                    query = query.Where(p => p.Nome.ToString().Contains(value));
                    query = query.Where(p => p.Codigo.ToString().Contains(value));
                }

                var filteredCount = query.Count();

                var sortedColumns = requestModel.Columns.GetSortedColumns();
                var orderByString = String.Empty;

                foreach (var column in sortedColumns)
                {
                    orderByString += orderByString != String.Empty ? "," : "";
                    orderByString += (column.Data == "Category" ? "ProductCategory.Name" : column.Data) + (column.SortDirection == Column.OrderDirection.Ascendant ? " asc" : " desc");
                }

                query = query.OrderBy(orderByString == String.Empty ? "name asc" : orderByString);
                query = query.Skip(requestModel.Start).Take(requestModel.Length);

                return(Json(new DataTablesResponse(requestModel.Draw, query.ToList(), filteredCount, totalCount), JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 2
0
        public JsonResult DatatablesUsuarios([ModelBinder(typeof(DataTablesBinder))] DataTables.Mvc.IDataTablesRequest requestModel)
        {
            using (var db = new ApplicationDbContext())
            {
                var query = db.Database.SqlQuery <AspNetUsers>("SELECT * FROM AspNetUsers").ToList();

                return(Json(new DataTablesResponse(requestModel.Draw, query, query.Count, query.Count), JsonRequestBehavior.AllowGet));
            }
        }
        public static PagerItemsII GetPagingParametersII(DataTables.Mvc.IDataTablesRequest requestModel, string defaultSortBy, string defaultsortDirection)
        {
            var pagingParameter = new PagerItemsII();

            pagingParameter.PageSize    = requestModel.Length;
            pagingParameter.CurrentPage = requestModel.Start == 0 ? 1 : (requestModel.Start + 1) / requestModel.Length;
            pagingParameter.PageNumber  = requestModel.Start == 0 ? 1 : ((requestModel.Start + 1) / requestModel.Length) + 1;
            pagingParameter.SortColumns = requestModel.Columns.GetSortedColumns();
            if (pagingParameter.SortColumns == null || pagingParameter.SortColumns.Count() == 0)
            {
                IList <Column> v = new List <Column>();
                var            c = new Column(defaultSortBy, defaultSortBy, true, true, String.Empty, false);
                c.SetColumnOrdering(1, defaultsortDirection.ToLower());
                v.Add(c);
                pagingParameter.SortColumns = (IOrderedEnumerable <Column>)v;
            }
            pagingParameter.SearchColumns = requestModel.Columns.GetFilteredColumns();

            pagingParameter.siteSearch = requestModel.Search.Value;

            return(pagingParameter);
        }