Ejemplo n.º 1
0
        //[ObjectAuth(ObjectId = ModuleObjectId.EMPLEADOS_OBJECT, PermissionType = PermissionTypes.Export)]
        public ActionResult Print(string format, int pageIndex, int pageSize, string iSortCol, string sSortDir, string where, string order)
        {
            var exportFormatType = (ExportFormatType)Enum.Parse(
                typeof(ExportFormatType), format, true);

            where = HttpUtility.UrlEncode(where);

            if (!_tokenManager.GenerateToken())
            {
                return(null);
            }

            _IOjosApiConsumer.SetAuthHeader(_tokenManager.Token);

            NameValueCollection filter = Request.QueryString;

            var configuration = new GridConfiguration()
            {
                OrderByClause = "", WhereClause = ""
            };

            if (filter != null)
            {
                configuration = GridQueryHelper.GetDataTableConfiguration(filter, new OjosPropertyMapper());
            }


            if (!String.IsNullOrEmpty(where))
            {
                configuration.WhereClause = configuration.WhereClause == "" ? where : "(" + configuration.WhereClause + " AND " + where + ")";
            }
            if (Session["AdvanceSearch"] != null && pageSize != 0)
            {
                var advanceFilter =
                    (OjosAdvanceSearchModel)Session["AdvanceSearch"];
                configuration.WhereClause = configuration.WhereClause == "" ? GetAdvanceFilter(advanceFilter) : configuration.WhereClause + " AND " + GetAdvanceFilter(advanceFilter);
            }

            string sortDirection = "asc";

            OjosPropertyMapper oOjosPropertyMapper = new OjosPropertyMapper();

            if (Request.QueryString["sSortDir"] != null)
            {
                sortDirection = Request.QueryString["sSortDir"];
            }
            configuration.OrderByClause = oOjosPropertyMapper.GetPropertyName(iSortCol) + " " + sortDirection;

            if (!String.IsNullOrEmpty(order))
            {
                configuration.OrderByClause = order;
            }
            pageSize = pageSize == 0 ? int.MaxValue : pageSize;

            var result = _IOjosApiConsumer.ListaSelAll((pageIndex * pageSize) - pageSize + 1, pageSize + ((pageIndex * pageSize) - pageSize), configuration.WhereClause, configuration.OrderByClause ?? "").Resource;

            if (result.Ojoss == null)
            {
                result.Ojoss = new List <Ojos>();
            }

            var data = result.Ojoss.Select(m => new OjosGridModel
            {
                Clave         = m.Clave
                , Descripcion = m.Descripcion
            }).ToList();

            return(PartialView("_Print", data));
        }