public ActionResult ShowAdvanceFilter(string previousFilters = "") { if (!_tokenManager.GenerateToken()) { return(Json(null, JsonRequestBehavior.AllowGet)); } _ISpartan_BR_Presentation_Control_TypeApiConsumer.SetAuthHeader(_tokenManager.Token); var Spartan_BR_Presentation_Control_Types = _ISpartan_BR_Presentation_Control_TypeApiConsumer.SelAll(true); if (Spartan_BR_Presentation_Control_Types != null && Spartan_BR_Presentation_Control_Types.Resource != null) { ViewBag.Spartan_BR_Presentation_Control_Types = Spartan_BR_Presentation_Control_Types.Resource.Select(m => new SelectListItem { Text = m.Description.ToString(), Value = Convert.ToString(m.PresentationControlTypeId) }).ToList(); } var previousFiltersObj = new Spartan_BR_Operator_TypeAdvanceSearchModel(); if (previousFilters != "") { previousFiltersObj = (Spartan_BR_Operator_TypeAdvanceSearchModel)(Session["AdvanceSearch"] ?? new Spartan_BR_Operator_TypeAdvanceSearchModel()); } 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_BR_Operator_TypeAdvanceSearchModel filter) { var where = ""; if (!string.IsNullOrEmpty(filter.FromOperatorTypeId) || !string.IsNullOrEmpty(filter.ToOperatorTypeId)) { if (!string.IsNullOrEmpty(filter.FromOperatorTypeId)) { where += " AND Spartan_BR_Operator_Type.OperatorTypeId >= " + filter.FromOperatorTypeId; } if (!string.IsNullOrEmpty(filter.ToOperatorTypeId)) { where += " AND Spartan_BR_Operator_Type.OperatorTypeId <= " + filter.ToOperatorTypeId; } } if (!string.IsNullOrEmpty(filter.Description)) { switch (filter.DescriptionFilter) { case Models.Filters.BeginWith: where += " AND Spartan_BR_Operator_Type.Description LIKE '" + filter.Description + "%'"; break; case Models.Filters.EndWith: where += " AND Spartan_BR_Operator_Type.Description LIKE '%" + filter.Description + "'"; break; case Models.Filters.Exact: where += " AND Spartan_BR_Operator_Type.Description = '" + filter.Description + "'"; break; case Models.Filters.Contains: where += " AND Spartan_BR_Operator_Type.Description LIKE '%" + filter.Description + "%'"; break; } } if (!string.IsNullOrEmpty(filter.AdvancePresentation_Control_Type)) { switch (filter.Presentation_Control_TypeFilter) { case Models.Filters.BeginWith: where += " AND Spartan_BR_Presentation_Control_Type.Description LIKE '" + filter.AdvancePresentation_Control_Type + "%'"; break; case Models.Filters.EndWith: where += " AND Spartan_BR_Presentation_Control_Type.Description LIKE '%" + filter.AdvancePresentation_Control_Type + "'"; break; case Models.Filters.Exact: where += " AND Spartan_BR_Presentation_Control_Type.Description = '" + filter.AdvancePresentation_Control_Type + "'"; break; case Models.Filters.Contains: where += " AND Spartan_BR_Presentation_Control_Type.Description LIKE '%" + filter.AdvancePresentation_Control_Type + "%'"; break; } } else if (filter.AdvancePresentation_Control_TypeMultiple != null && filter.AdvancePresentation_Control_TypeMultiple.Count() > 0) { var Presentation_Control_TypeIds = string.Join(",", filter.AdvancePresentation_Control_TypeMultiple); where += " AND Spartan_BR_Operator_Type.Presentation_Control_Type In (" + Presentation_Control_TypeIds + ")"; } if (!string.IsNullOrEmpty(filter.Query_for_Fill_Condition)) { switch (filter.Query_for_Fill_ConditionFilter) { case Models.Filters.BeginWith: where += " AND Spartan_BR_Operator_Type.Query_for_Fill_Condition LIKE '" + filter.Query_for_Fill_Condition + "%'"; break; case Models.Filters.EndWith: where += " AND Spartan_BR_Operator_Type.Query_for_Fill_Condition LIKE '%" + filter.Query_for_Fill_Condition + "'"; break; case Models.Filters.Exact: where += " AND Spartan_BR_Operator_Type.Query_for_Fill_Condition = '" + filter.Query_for_Fill_Condition + "'"; break; case Models.Filters.Contains: where += " AND Spartan_BR_Operator_Type.Query_for_Fill_Condition LIKE '%" + filter.Query_for_Fill_Condition + "%'"; break; } } if (!string.IsNullOrEmpty(filter.Code_for_Fill_Condition)) { switch (filter.Code_for_Fill_ConditionFilter) { case Models.Filters.BeginWith: where += " AND Spartan_BR_Operator_Type.Code_for_Fill_Condition LIKE '" + filter.Code_for_Fill_Condition + "%'"; break; case Models.Filters.EndWith: where += " AND Spartan_BR_Operator_Type.Code_for_Fill_Condition LIKE '%" + filter.Code_for_Fill_Condition + "'"; break; case Models.Filters.Exact: where += " AND Spartan_BR_Operator_Type.Code_for_Fill_Condition = '" + filter.Code_for_Fill_Condition + "'"; break; case Models.Filters.Contains: where += " AND Spartan_BR_Operator_Type.Code_for_Fill_Condition LIKE '%" + filter.Code_for_Fill_Condition + "%'"; break; } } if (!string.IsNullOrEmpty(filter.Implementation_Code)) { switch (filter.Implementation_CodeFilter) { case Models.Filters.BeginWith: where += " AND Spartan_BR_Operator_Type.Implementation_Code LIKE '" + filter.Implementation_Code + "%'"; break; case Models.Filters.EndWith: where += " AND Spartan_BR_Operator_Type.Implementation_Code LIKE '%" + filter.Implementation_Code + "'"; break; case Models.Filters.Exact: where += " AND Spartan_BR_Operator_Type.Implementation_Code = '" + filter.Implementation_Code + "'"; break; case Models.Filters.Contains: where += " AND Spartan_BR_Operator_Type.Implementation_Code LIKE '%" + filter.Implementation_Code + "%'"; break; } } where = new Regex(Regex.Escape("AND ")).Replace(where, "", 1); return(where); }