public ActionResult ShowAdvanceFilter(string previousFilters = "") { if (!_tokenManager.GenerateToken()) { return(Json(null, JsonRequestBehavior.AllowGet)); } _ISpartan_Traduction_Object_TypeApiConsumer.SetAuthHeader(_tokenManager.Token); var Spartan_Traduction_Object_Types_Object_Type = _ISpartan_Traduction_Object_TypeApiConsumer.SelAll(true); if (Spartan_Traduction_Object_Types_Object_Type != null && Spartan_Traduction_Object_Types_Object_Type.Resource != null) { ViewBag.Spartan_Traduction_Object_Types_Object_Type = Spartan_Traduction_Object_Types_Object_Type.Resource.OrderBy(m => m.Object_Type_Description).Select(m => new SelectListItem { Text = m.Object_Type_Description.ToString(), Value = Convert.ToString(m.IdType) }).ToList(); } var previousFiltersObj = new Spartan_Traduction_ObjectAdvanceSearchModel(); if (previousFilters != "") { previousFiltersObj = (Spartan_Traduction_ObjectAdvanceSearchModel)(Session["AdvanceSearch"] ?? new Spartan_Traduction_ObjectAdvanceSearchModel()); } ViewBag.Filter = new List <SelectListItem> { new SelectListItem() { Text = Resources.Resources.BeginWith, Value = "1" }, new SelectListItem() { Text = Resources.Resources.EndWith, Value = "2" }, new SelectListItem() { Text = Resources.Resources.Contains, Value = "4" }, new SelectListItem() { Text = Resources.Resources.Exact, Value = "3" }, }; return(View(previousFiltersObj)); }
public string GetAdvanceFilter(Spartan_Traduction_ObjectAdvanceSearchModel filter) { var where = ""; if (!string.IsNullOrEmpty(filter.FromIdObject) || !string.IsNullOrEmpty(filter.ToIdObject)) { if (!string.IsNullOrEmpty(filter.FromIdObject)) { where += " AND Spartan_Traduction_Object.IdObject >= " + filter.FromIdObject; } if (!string.IsNullOrEmpty(filter.ToIdObject)) { where += " AND Spartan_Traduction_Object.IdObject <= " + filter.ToIdObject; } } if (!string.IsNullOrEmpty(filter.Object_Description)) { switch (filter.Object_DescriptionFilter) { case Models.Filters.BeginWith: where += " AND Spartan_Traduction_Object.Object_Description LIKE '" + filter.Object_Description + "%'"; break; case Models.Filters.EndWith: where += " AND Spartan_Traduction_Object.Object_Description LIKE '%" + filter.Object_Description + "'"; break; case Models.Filters.Exact: where += " AND Spartan_Traduction_Object.Object_Description = '" + filter.Object_Description + "'"; break; case Models.Filters.Contains: where += " AND Spartan_Traduction_Object.Object_Description LIKE '%" + filter.Object_Description + "%'"; break; } } if (!string.IsNullOrEmpty(filter.AdvanceObject_Type)) { switch (filter.Object_TypeFilter) { case Models.Filters.BeginWith: where += " AND Spartan_Traduction_Object_Type.Object_Type_Description LIKE '" + filter.AdvanceObject_Type + "%'"; break; case Models.Filters.EndWith: where += " AND Spartan_Traduction_Object_Type.Object_Type_Description LIKE '%" + filter.AdvanceObject_Type + "'"; break; case Models.Filters.Exact: where += " AND Spartan_Traduction_Object_Type.Object_Type_Description = '" + filter.AdvanceObject_Type + "'"; break; case Models.Filters.Contains: where += " AND Spartan_Traduction_Object_Type.Object_Type_Description LIKE '%" + filter.AdvanceObject_Type + "%'"; break; } } else if (filter.AdvanceObject_TypeMultiple != null && filter.AdvanceObject_TypeMultiple.Count() > 0) { var Object_TypeIds = string.Join(",", filter.AdvanceObject_TypeMultiple); where += " AND Spartan_Traduction_Object.Object_Type In (" + Object_TypeIds + ")"; } where = new Regex(Regex.Escape("AND ")).Replace(where, "", 1); return(where); }