Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i debug API project created using C#

I want to debug my API project which is currently in my local. Written using C#.

reason for debugging is below function in that API project returns null for a particular JSON.

 [Route("api/NMRController/Disposition")]
    [HttpPost]
    public NMR_Object Disposition(NMR nmr)
    {

        try
        {
            Console.WriteLine($"nmr: {JsonConvert.SerializeObject(nmr)}");
            string CorrectiveAction = nmr.CorrectiveAction;
            string DispositionResult = nmr.DispositionResult;
            string DispositionComment = nmr.DispositionComment;
            string NoteForGroup = nmr.NoteForGroup;
            string SerialNo = nmr.SerialNo;


            MySql.Data.MySqlClient.MySqlConnection conn;
            conn = new MySql.Data.MySqlClient.MySqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["constr_nmr"].ConnectionString;

            MySql.Data.MySqlClient.MySqlCommand myCommand = conn.CreateCommand();
            myCommand.Connection = conn;
            if (conn.State.ToString() != "Open")
            {
                conn.Open();
            }

            myCommand.CommandText = "UPDATE NMR_SerialNo SET CorrectiveAction = @CorrectiveAction, DispositionResult = @DispositionResult, DispositionComment = @DispositionComment, NoteForGroup = @NoteForGroup WHERE SerialNo = @SerialNo";
            myCommand.Parameters.AddWithValue("@CorrectiveAction", CorrectiveAction);
            myCommand.Parameters.AddWithValue("@DispositionResult", DispositionResult);
            myCommand.Parameters.AddWithValue("@DispositionComment", DispositionComment);
            myCommand.Parameters.AddWithValue("@NoteForGroup", NoteForGroup);
            myCommand.Parameters.AddWithValue("@SerialNo", SerialNo);
            myCommand.ExecuteNonQuery();
            conn.Close();

            // write insert query


            var RM = new NMR_Object();
            RM.data = "";
            RM.success = true;
            // RM = JsonConvert.SerializeObject(dt));
            return RM;

        }
        catch (Exception ex)
        {

            var RME = new NMR_Object();
            RME.success = false;
            RME.message = "NMR POST: " + ex.Message;
        }
        return null;
    }

Below is the JSON i have passed during post call.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
"CorrectiveAction": "testing",
"DispositionResult": "testing",
"DispositionComment": "testing",
"NoteForGroup": "testing",
"SerialNo": "MYSQL"
}

>Solution :

On Visual Studio for Mac, open your Project.

On the upper left hand side you can choose whether you want to use http or https, then you need to choose debug, and the browser with which you wish to debug.

Then click run

After your project successfully builds and is up and running, you can place breakpoints in visual studio by clicking on the line name next to the line of code you want to test.

Visual studio will break when the breakpoint is entered and you can watch your variables

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading