C# code to evaluate the rules produced by query builder

Just working on a proof of concept project that makes use of Query Builder. My backend is .NET and I'm looking for the best way evaluate the rules that are generated by Query Builder against a C# object. So in other words, is there any pre-built library that would accept the rules output from the query builder and the target C# object and return true/false if the object meets the query builder rules?

I can build it myself, I was just hoping to save a bit of time if there is something like that exists already.


Thanks,

Nick


1 Reply

KV Keerthikaran Venkatachalam Syncfusion Team December 29, 2023 04:30 PM UTC

Hi Nick G,


We have checked your reported query and prepared a sample based on your requirements. Using the ajax post in the button click event, you can get the QueryBuilder rule using the getValidRules method and send the rule from the client to the server. In server side, we have compared the created rule with the Rule object by checking whether the rule object has field, label, operator, and value properties, and finally, you can get true or false in the isRulesProperlyFramed variable. Please find the following code snippet and sample.

[Client]

btnClick(): void{

            var rule = this.qryBldrObj.getValidRules();

            let ajax: XMLHttpRequest = new XMLHttpRequest();

            ajax.open('POST', 'https://localhost:7255/querybuilder/GetValidRules', true);

            ajax.setRequestHeader('Content-Type', 'application/json');

 

            ajax.onreadystatechange = function () {

                if (ajax.readyState === XMLHttpRequest.DONE) {

                    if (ajax.status === 200) {

                        var dt = ajax.responseText;

                        // Handle the successful response here

                    } else {

                        // Handle the error, e.g., display an error message

                        console.error('Error:', ajax.status, ajax.statusText);

                    }

                }

            };

            // Convert the data to JSON string before sending

            ajax.send(JSON.stringify(rule));

        }


Sample link: https://stackblitz.com/edit/angular-9qnbcb-5rnqw7?file=src%2Fapp.component.ts

[Server]

  public void GetValidRules(dynamic data)

  {

      var jsonString = JsonConvert.SerializeObject(data);

      Rule actualRuleSet = JsonConvert.DeserializeObject<Rule>(jsonString);

      bool isRulesProperlyFramed = AreRulesProperlyFramed(actualRuleSet);

  }



Please let us know if you need any further assistance on this.



Regards,

KeerthiKaran K V


Attachment: WebService_7ac01946.zip

Loader.
Up arrow icon