Parent / child editing with Editor In .NET Syntax

Parent / child editing with Editor In .NET Syntax

BigDataWarehouseBigDataWarehouse Posts: 23Questions: 10Answers: 0
edited November 2020 in Free community support

What is the syntax in C# .NET for the following filter?

if ( ! isset($_POST['site']) || ! is_numeric($_POST['site']) ) {
    echo json_encode( [ "data" => [] ] );
}
else {
    Editor::inst( $db, 'users' )
        ->field(
            Field::inst( 'users.first_name' ),
            Field::inst( 'users.last_name' ),
            Field::inst( 'users.phone' ),
            Field::inst( 'users.site' )
                ->options( 'sites', 'id', 'name' )
                ->validator( 'Validate::dbValues' ),
            Field::inst( 'sites.name' )
        )
        ->leftJoin( 'sites', 'sites.id', '=', 'users.site' )
        ->where( 'site', $_POST['site'] )
        ->process($_POST)
        ->json();
}

more info here: https://datatables.net/blog/2016-03-25

THANKS!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Answer ✓

    It is very similar:

    var response = new Editor(Db, "users")
        .Field(new Field("users.first_name"))
        .Field(new Field("users.last_name"))
        // ...
        .LeftJoin( "sites",   "sites.id",   "=", "users.site" )
        .Where("site", request.Form["site"])
        .Process(request)
        .Data();
    
    return Json(response);
    

    See the .NET documentation for more details. You might also want to add the wrapper if condition with request.Form.AllKeys.Contains("site").

    Regards,
    Allan

This discussion has been closed.