private static string GetDataTableCurrentQueryNew(UrlParametersModel param, ISqlPropertyMapper mapper) { NameValueCollection request = HttpUtility.ParseQueryString(param.filters); string query = ""; var keyValue = ""; for (int i = 1; i < request.Keys.Count - 1; i++) { if (!string.IsNullOrEmpty(param.columns[i].name)) { keyValue = Convert.ToString(request[i]); //if (keyValue == "sortOrder" || keyValue == "sortField" || keyValue == "pageIndex" || keyValue == "format" || keyValue == "pageSize" || keyValue == "_" || keyValue == "-") // continue; if (keyValue != "undefined" && keyValue != "on") { var newQuery = mapper.GetOperatorString(keyValue, param.columns[i].name); if (!string.IsNullOrEmpty(newQuery)) { query += ((query != "") ? " AND " : "") + newQuery; } } } } return(query); }
public static GridConfiguration GetDataTableConfigurationNew(UrlParametersModel param, ISqlPropertyMapper mapper) { return(new GridConfiguration { OrderByClause = "", WhereClause = GetUrlCompatibleString(GetDataTableCurrentQueryNew(param, mapper)) }); }
/* * [HttpGet] * public ActionResult GetArticuloAll() * { * try * { * if (!_tokenManager.GenerateToken()) * return Json(null, JsonRequestBehavior.AllowGet); * _IArticuloApiConsumer.SetAuthHeader(_tokenManager.Token); * var result = _IArticuloApiConsumer.SelAll(false).Resource; * * return Json(result.OrderBy(m => m.).Select(m => new SelectListItem * { * Text = CultureHelper.GetTraductionNew(Convert.ToString(m.Clave), "Articulo", m.), * Value = Convert.ToString(m.Clave) * }).ToArray(), JsonRequestBehavior.AllowGet); * } * catch (ServiceException ex) * { * return Json(null, JsonRequestBehavior.AllowGet); * } * } */ /// <summary> /// Get List of Articulo from Web API. /// </summary> /// <param name="draw"></param> /// <param name="start"></param> /// <param name="length"></param> /// <returns>Return List of Articulo Entity</returns> public ActionResult GetArticuloList(UrlParametersModel param) { int sEcho = param.sEcho; int iDisplayStart = param.iDisplayStart; int iDisplayLength = param.iDisplayLength; string where = param.where; string order = param.order; where = HttpUtility.UrlEncode(where); int sortColumn = -1; string sortDirection = "asc"; if (iDisplayLength == -1) { //length = TOTAL_ROWS; iDisplayLength = Int32.MaxValue; } // note: we only sort one column at a time if (param.sortColumn != null) { sortColumn = int.Parse(param.sortColumn); } if (param.sortDirection != null) { sortDirection = param.sortDirection; } if (!_tokenManager.GenerateToken()) { return(null); } _IArticuloApiConsumer.SetAuthHeader(_tokenManager.Token); NameValueCollection filter = HttpUtility.ParseQueryString(param.filters); var configuration = new GridConfiguration() { OrderByClause = "", WhereClause = "" }; if (filter != null) { configuration = GridQueryHelper.GetDataTableConfigurationNew(param, new ArticuloPropertyMapper()); } if (!String.IsNullOrEmpty(where)) { configuration.WhereClause = configuration.WhereClause == "" ? where : "(" + configuration.WhereClause + " AND " + where + ")"; } if (!String.IsNullOrEmpty(order)) { configuration.OrderByClause = order; } //Adding Advance Search if (param.AdvanceSearch != null && param.AdvanceSearch == true && Session["AdvanceSearch"] != null) { if (Session["AdvanceSearch"].GetType() == typeof(ArticuloAdvanceSearchModel)) { var advanceFilter = (ArticuloAdvanceSearchModel)Session["AdvanceSearch"]; configuration.WhereClause = configuration.WhereClause == "" ? GetAdvanceFilter(advanceFilter) : configuration.WhereClause + " AND " + GetAdvanceFilter(advanceFilter); } else { Session.Remove("AdvanceSearch"); } } ArticuloPropertyMapper oArticuloPropertyMapper = new ArticuloPropertyMapper(); if (String.IsNullOrEmpty(order)) { if (sortColumn != -1) { configuration.OrderByClause = oArticuloPropertyMapper.GetPropertyName(param.columns[sortColumn].name) + " " + sortDirection; } } var pageSize = iDisplayLength; var pageIndex = (iDisplayStart / iDisplayLength) + 1; var result = _IArticuloApiConsumer.ListaSelAll((pageIndex * pageSize) - pageSize + 1, pageSize + ((pageIndex * pageSize) - pageSize), configuration.WhereClause, configuration.OrderByClause ?? "").Resource; if (result.Articulos == null) { result.Articulos = new List <Articulo>(); } return(Json(new { aaData = result.Articulos.Select(m => new ArticuloGridModel { Clave = m.Clave , Descripcion = m.Descripcion }).ToList(), iTotalRecords = result.RowCount, iTotalDisplayRecords = result.RowCount, sEcho = sEcho }, JsonRequestBehavior.AllowGet)); }