private string ProcessFilterOperation(FilterOperation filterOp, string sql, string paramName, bool isRange, DynamicParameters paramsList) { if (filterOp.value == null && !IsUnaryOperator(filterOp.valueOperator)) { return(""); } var parsedSQl = sql.Replace("{{operator}}", QueryInfoHelper.GetSQLOperator(filterOp.valueOperator)); parsedSQl = parsedSQl.Replace("{{parameter}}", IsUnaryOperator(filterOp.valueOperator) ? "" : filterOp.ProcessParamName(paramName, isRange) ); var paramNamesList = filterOp.GetParamNames(paramName, isRange); if (filterOp.valueOperator == OperatorType.In) { int indexAt = 0; var valueCommaSeperated = filterOp.GetValue <string>(); var valueList = valueCommaSeperated.Split(','); foreach (var p in paramNamesList) { ProcessParameterValueForInOperator(paramsList, filterOp, p, valueList[indexAt]); indexAt++; } } else { ProcessParameterValue(paramsList, filterOp, paramNamesList[0]); } return(parsedSQl); }
private void ProcessParameterValue(DynamicParameters paramsList, FilterOperation filterOp, string paramName) { switch (filterOp.valueType) { case ValueDataType.String: paramsList.Add(paramName, filterOp.GetValue <string>()); break; case ValueDataType.Number: paramsList.Add(paramName, filterOp.GetValue <int>()); break; case ValueDataType.Date: var dateValue = filterOp.GetValue <DateTime>(); dateValue = new DateTime(dateValue.Year, dateValue.Month, dateValue.Day); paramsList.Add(paramName, dateValue); break; case ValueDataType.Boolean: var boolValue = filterOp.GetValue <bool>(); paramsList.Add(paramName, boolValue); break; case ValueDataType.NullableBoolean: var value = filterOp.GetValue <string>(); var newValue = value == "False" || value == "false" || value == "No" || value == "no" || value == "0" || string.IsNullOrEmpty(value) ? 0 : 1; paramsList.Add(paramName, newValue); break; default: paramsList.Add(paramName, filterOp.GetValue <string>()); break; } }