示例#1
0
        private void LoadBindDataParms()
        {
            BindDataParamDto bindDataParam = BindDataParam;

            ViewBag.Sortname  = bindDataParam.Sidx;
            ViewBag.Sortorder = bindDataParam.Sord;
            ViewBag.Page      = bindDataParam.Page;
            ViewBag.RowNum    = bindDataParam.Rows;
            ViewBag.Filters   = bindDataParam.Filters;
            ViewBag.Search    = bindDataParam.Search;
        }
示例#2
0
        public ActionResult BindData(string sidx, string sord, int page, int rows, bool search, string filters)
        {
            BindDataParam = new BindDataParamDto {
                Sidx = sidx, Sord = sord, Page = page, Rows = rows, Filters = filters
            };

            Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
            Response.Cache.SetMaxAge(new TimeSpan(0));

            CustomDataSource <PersonDto> dataSource = personBl.BindData(sidx, sord, page, rows, search, filters);

            // to be able to use ToString() below which is NOT exist in the LINQ to Entity
            // we should include in queryDetails only the properies which we will use below
            var queryDetails = (from item in dataSource.RecordList
                                select new { item.Id, item.FirstName, item.LastName, item.Age }).ToList();
            var retult = new
            {
                total = (dataSource.TotalRecords + rows - 1) / rows,
                page,
                records = dataSource.TotalRecords,
                rows    = (from item in queryDetails
                           select new[] {
                    item.Id + "",
                    item.FirstName,
                    item.LastName,
                    item.Age + ""
                }).ToList()
            };

            // calculate MD5 from the returned data and use it as ETag
            var serializer = new JavaScriptSerializer();
            var str        = serializer.Serialize(retult);

            byte[] inputBytes = Encoding.ASCII.GetBytes(str);
            byte[] hash       = MD5.Create().ComputeHash(inputBytes);
            string newETag    = Convert.ToBase64String(hash);

            Response.Cache.SetETag(newETag);
            // compare ETag of the data which already has the client with ETag of response
            string incomingEtag = Request.Headers["If-None-Match"];

            if (String.Compare(incomingEtag, newETag, StringComparison.Ordinal) == 0)
            {
                // we don't need return the data which the client already have
                Response.SuppressContent = true;
                Response.StatusCode      = (int)HttpStatusCode.NotModified;
                return(null);
            }

            return(Json(retult, JsonRequestBehavior.AllowGet));
        }
示例#3
0
        public ActionResult BindData(string sidx, string sord, int page, int rows, bool search, string filters)
        {
            BindDataParam = new BindDataParamDto { Sidx = sidx, Sord = sord, Page = page, Rows = rows, Filters = filters };

            Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
            Response.Cache.SetMaxAge(new TimeSpan(0));

            CustomDataSource<PersonDto> dataSource = personBl.BindData(sidx, sord, page, rows, search, filters);

            // to be able to use ToString() below which is NOT exist in the LINQ to Entity
            // we should include in queryDetails only the properies which we will use below
            var queryDetails = (from item in dataSource.RecordList
                                select new { item.Id, item.FirstName, item.LastName, item.Age}).ToList();
            var retult = new
            {
                total = (dataSource.TotalRecords + rows - 1) / rows,
                page,
                records = dataSource.TotalRecords,
                rows = (from item in queryDetails
                        select new[] {
                            item.Id + "",
                            item.FirstName,
                            item.LastName,
                            item.Age + ""
                        }).ToList()
            };

            // calculate MD5 from the returned data and use it as ETag
            var serializer = new JavaScriptSerializer();
            var str = serializer.Serialize(retult);
            byte[] inputBytes = Encoding.ASCII.GetBytes(str);
            byte[] hash = MD5.Create().ComputeHash(inputBytes);
            string newETag = Convert.ToBase64String(hash);
            Response.Cache.SetETag(newETag);
            // compare ETag of the data which already has the client with ETag of response
            string incomingEtag = Request.Headers["If-None-Match"];
            if (String.Compare(incomingEtag, newETag, StringComparison.Ordinal) == 0)
            {
                // we don't need return the data which the client already have
                Response.SuppressContent = true;
                Response.StatusCode = (int)HttpStatusCode.NotModified;
                return null;
            }

            return Json(retult, JsonRequestBehavior.AllowGet);
        }