Jaya Prakash

Jaya Prakash

  • 545
  • 2.3k
  • 65k

How to pass object to request body

Jun 15 2023 11:13 AM

My Entity Class

 

namespace Entities
{
    public class Myclass
    {

       
        public class Payee
        {
            public string name { get; set; }
            public string accountNumber { get; set; }
        }

        public class Payer
        {
            public string bankProfileId { get; set; }
            public string accountNumber { get; set; }
        }

        public Payer payer { get; set; }
        public Payee payee { get; set; }
        public string transferMode { get; set; }
        public string transferAmount { get; set; }
        public string externalRef { get; set; }
        public string latitude { get; set; }
        public string longitude { get; set; }
        public string remarks { get; set; }
        public string alertEmail { get; set; }
        
    }

}

i tried this but not worked 

Note*: I should not use below method give me an alternative either list or something.

var requestBody = new
            {
                payer = new
                {
                    bankProfileId = "0",
                    accountNumber = "9999999999"
                },
                payee = new
                {
                    name = "ABC ZYX",
                    accountNumber = "538787667671678"
                },
                transferMode = "CREDITCARD",
                transferAmount = "5.00",
                externalRef = "BILLPAY1",
                latitude = "20.**36",
                longitude = "78.**28",
                remarks = "Credit Card BILL",
                alertEmail = ""
            };

I need to pass this to request body by adding it to JObject object =new jObject();

i am unable to do it pls help me

i tried object.Add(requestbody);  but none works for me

 

once the request object saved in the database i need to show my request object like this in respected column

{
    "payer" : {
        "bankProfileId" : "0",
        "accountNumber" : "9999999999"
    },
    "payee" : {
        "name" : "ABC ZYX",
        "accountNumber" : "538787667671678"
    },
    "transferMode" : "CREDITCARD",
    "transferAmount" : "5.00",
    "externalRef" : "BILLPAY1",
    "latitude" : "20.**36",
    "longitude" : "78.**28",
    "remarks" : "Credit Card BILL",
    "alertEmail" : ""
}

 


Answers (4)