Exemplo n.º 1
0
        //   [Helper.Security.AttributeHelpers.ValidateAjaxAntiForgeryToken]
        public JsonResult GetLogView(JQGridViewModel jqGridViewModel)
        {
            JQGridHelper helper = new JQGridHelper();

            var model = unitOfWork.IISLogRepository.GetMany()
                        .Select(r => new IisLogViewModel
            {
                cIp             = r.cIp,
                csCookie        = r.csCookie,
                csMethod        = r.csMethod,
                csReferer       = r.csReferer,
                csUriQuery      = r.csUriQuery,
                csUriStem       = r.csUriStem,
                csUserAgent     = r.csUserAgent,
                date            = r.date,
                Id              = r.Id,
                scStatus        = r.scStatus.ToString(),
                sPort           = r.sPort,
                IsBlocked       = r.IsBlocked,
                BlockHit        = r.BlockHit,
                ApplicationName = r.ApplicationName
            });

            return(helper.GetResult <IisLogViewModel>(jqGridViewModel, model));
        }
Exemplo n.º 2
0
        /// <summary>
        /// get the dataset with the filter from the grid
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="jqGridViewModel"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        public IQueryable <T> GetFilteredDataSet <T>(JQGridViewModel jqGridViewModel, IQueryable <T> source)
        {
            if (string.IsNullOrEmpty(jqGridViewModel.sord))
            {
                jqGridViewModel.sord = "desc";
            }

            //direction of sort
            bool dir = jqGridViewModel.sord.ToLower().Equals("desc", StringComparison.CurrentCultureIgnoreCase) ? true : false;

            if (jqGridViewModel._search)
            {
                //get the filter
                string filterCriteria = JQGridFilterHelper.FilterQuery <T>(jqGridViewModel);

                return(source.Where(filterCriteria).OrderBy(jqGridViewModel.sidx, dir));
            }
            else
            {
                //get the paged result without filter
                return(source.OrderBy(jqGridViewModel.sidx, dir));
            }
        }
Exemplo n.º 3
0
        public static string FilterQuery <T>(JQGridViewModel jqGridViewModel)
        {
            StringBuilder        sb         = new StringBuilder();
            int                  counter    = 0;
            string               rtRule     = string.Empty;
            string               rtWhere    = string.Empty;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            JQGridFilterModel    filters    = serializer.Deserialize <JQGridFilterModel>(
                jqGridViewModel.filters
                );

            foreach (RuleModel rule in filters.rules)
            {
                if (rule.data == "ALL")
                {
                    rtRule = "1=1";
                }
                else
                {
                    rtRule = LinqDynamicConditionHelper.GetCondition <T>(rule);
                }

                if (rtRule.Length > 0)
                {
                    counter++;
                    sb.Append(rtRule);

                    //check if needed operator at the end
                    if (filters.rules.Count() > counter)
                    {
                        sb.Append(filters.groupOp.ToLower() == "and" ? " && " : " || ");
                    }
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 4
0
        public JsonResult GetResult <T>(JQGridViewModel jqGridViewModel, IQueryable <T> source)
        {
            //get the default page size from web.config
            int pageSize = 0;

            if (jqGridViewModel.rows == 0)
            {
                int.TryParse(ApplicationSetting.JqGridDefaultPageSize, out pageSize);
            }
            else
            {
                pageSize = jqGridViewModel.rows;
            }

            if (string.IsNullOrEmpty(jqGridViewModel.sord))
            {
                jqGridViewModel.sord = "desc";
            }

            //direction of sort
            bool dir       = jqGridViewModel.sord.ToLower().Equals("desc", StringComparison.CurrentCultureIgnoreCase) ? true : false;
            var  totalRows = 0;

            var result = new List <T>();

            if (jqGridViewModel._search)
            {
                //get the filter
                string filterCriteria = JQGridFilterHelper.FilterQuery <T>(jqGridViewModel);

                // result = source.Where(filterCriteria).OrderBy(jqGridViewModel.sidx, dir).ToList();

                //total rows in table
                totalRows = source.Where(filterCriteria).OrderBy(jqGridViewModel.sidx, dir).Count();

                result = source.Where(filterCriteria).OrderBy(jqGridViewModel.sidx, dir)
                         .Skip((jqGridViewModel.page - 1) * pageSize)
                         .Take(pageSize)
                         .ToList();
            }
            else
            {
                //result = source.OrderBy(jqGridViewModel.sidx, dir).ToList();
                //total rows in table
                totalRows = source.OrderBy(jqGridViewModel.sidx, dir).Count();

                //get the paged result without filter
                result = source.OrderBy(jqGridViewModel.sidx, dir)
                         .Skip((jqGridViewModel.page - 1) * pageSize)
                         .Take(pageSize)
                         .ToList();
            }

            var jsonResult = Json(new
            {
                // colName = result[0].GetType().GetProperties().Select(s => s.Name).ToArray(),
                page    = jqGridViewModel.page,
                rows    = result.ToArray(),
                records = totalRows,
                total   = Convert.ToInt32(Math.Ceiling(Convert.ToSingle(totalRows) / Convert.ToSingle(pageSize)))
            }, JsonRequestBehavior.AllowGet);

            return(jsonResult);
        }