Monday, March 23, 2026

ActionResult response convert to JSON format from DATA table and custom JSON

 


ActionResult response convert to JSON format from DATA table and custom JSON


[HttpGet]

[Route("users")]

[Authorize]

public ActionResult<List<IgaResponse>> GetUsers(string pageNumber, string pageSize)

{

    try

    {

        var currUser = _iHttpContextAccessor.HttpContext.User;

        string luser = "";

        if (!string.IsNullOrEmpty(HttpContext.Request.Headers["Authorization"]))

            luser = HttpContext.Request.Headers["Authorization"].ToString();

        List<IgaResponse> ds = new List<IgaResponse>();

        (ds, DataSet ods) = new IGABAL().GetUserDetails(pageNumber, pageSize, luser);

        // return Ok(JsonConvert.SerializeObject(new { data = ds, pagination = ods.Tables[1] }, Formatting.Indented));

        var payload = JsonConvert.SerializeObject(new { data = ds, pagination = ods.Tables[1] });              

 

        return Content(payload, "application/json");

    }

    catch (Exception ex)

    {

        Helper.WriteToLog("CORE_API", "IAController->GetUsers()", ex);

        return BadRequest(ex.Message);

    }

}


No comments:

Post a Comment