Example #1
0
        public JsonResult List()
        {
            IQueryable <DocFile>       docfiles = context.DocFile;
            DataTablesParser <DocFile> parser   = new DataTablesParser <DocFile>(Request, docfiles);
            FormatedList <DocFile>     list     = parser.Parse();

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public JsonResult List(bool isExpired)
        {
            IQueryable <PurchasedProducts> productList = null;

            if (isExpired)
            {
                productList = context.PurchasedProducts.Where(q => q.PurchasedDueDate < DateTime.Today).OrderByDescending(q => q.PurchasedDate);
            }
            else
            {
                productList = context.PurchasedProducts.Where(q => q.PurchasedDueDate == null || q.PurchasedDueDate >= DateTime.Today).OrderByDescending(q => q.PurchasedDate);
            }
            DataTablesParser <PurchasedProducts> parser = new DataTablesParser <PurchasedProducts>(Request, productList);
            FormatedList <PurchasedProducts>     list   = parser.Parse();

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
Example #3
0
            /// <summary>
            /// Parses the <see cref="HttpRequestBase"/> parameter values for the accepted
            /// DataTable request values
            /// </summary>
            /// <returns>Formated output for DataTables, which should be serialized to JSON</returns>
            /// <example>
            ///     In an ASP.NET MVC from a controller, you can call the Json method and return this result.
            ///
            ///     public ActionResult List()
            ///     {
            ///         // change the following line per your data configuration
            ///         IQueriable<User> users = datastore.Linq();
            ///
            ///         if (Request["sEcho"] != null) // always test to see if the request is from DataTables
            ///         {
            ///             var parser = new DataTableParser<User>(Request, users);
            ///             return Json(parser.Parse());
            ///         }
            ///         return Json(_itemController.CachedValue);
            ///     }
            ///
            ///     If you're not using MVC, you can create a web service and write the JSON output as such:
            ///
            ///     using System.Web.Script.Serialization;
            ///     public class MyWebservice : System.Web.Services.WebService
            ///     {
            ///         public string MyMethod()
            ///         {
            ///             // change the following line per your data configuration
            ///             IQueriable<User> users = datastore.Linq();
            ///
            ///             response.ContentType = "application/json";
            ///
            ///             JavaScriptSerializer serializer = new JavaScriptSerializer();
            ///             var parser = new DataTableParser<User>(Request, users);
            ///             return new JavaScriptSerializer().Serialize(parser.Parse());
            ///         }
            ///     }
            /// </example>
            public FormatedList Parse()
            {
                var list = new FormatedList();

                // import property names
                list.Import(_properties.Select(x => x.Name).ToArray());

                // parse the echo property (must be returned as int to prevent XSS-attack)
                list.sEcho = int.Parse(_httpRequest[ECHO]);

                // count the record BEFORE filtering
                list.iTotalRecords = _queriable.Count();

                // apply the sort, if there is one
                ApplySort();

                // parse the paging values
                int skip = 0, take = 10;

                int.TryParse(_httpRequest[DISPLAY_START], out skip);
                int.TryParse(_httpRequest[DISPLAY_LENGTH], out take);

                // setup the data with individual property search, all fields search,
                // paging, and property list selection
                list.aaData = _queriable.Where(ApplyGenericSearch)
                              .Where(IndividualPropertySearch)
                              .Skip(skip)
                              .Take(take)
                              .Select(SelectProperties)
                              .ToList();

                // total records that are displayed
                list.iTotalDisplayRecords = list.aaData.Count;

                return(list);
            }