Hi
I have below object . How i can assign values and then serialize using restsharp
C#
public class BuyerDtls
{
public string Gstin { get; set; }
public string LglNm { get; set; }
public string Pos { get; set; }
public string Addr1 { get; set; }
public string Loc { get; set; }
public int Pin { get; set; }
public string Stcd { get; set; }
}
public class DispDtls
{
public string Nm { get; set; }
public string Addr1 { get; set; }
public string Loc { get; set; }
public int Pin { get; set; }
public string Stcd { get; set; }
}
public class DocDtls
{
public string Typ { get; set; }
public string No { get; set; }
public string Dt { get; set; }
}
public class ItemList
{
public int ItemNo { get; set; }
public string SlNo { get; set; }
public string IsServc { get; set; }
public string PrdDesc { get; set; }
public string HsnCd { get; set; }
public int Qty { get; set; }
public int FreeQty { get; set; }
public string Unit { get; set; }
public int UnitPrice { get; set; }
public int TotAmt { get; set; }
public int Discount { get; set; }
public int PreTaxVal { get; set; }
public int AssAmt { get; set; }
public int GstRt { get; set; }
public int IgstAmt { get; set; }
public int CgstAmt { get; set; }
public int SgstAmt { get; set; }
public int CesRt { get; set; }
public int CesAmt { get; set; }
public int CesNonAdvlAmt { get; set; }
public int StateCesRt { get; set; }
public int StateCesAmt { get; set; }
public int StateCesNonAdvlAmt { get; set; }
public int OthChrg { get; set; }
public int TotItemVal { get; set; }
}
public class Root
{
public string Version { get; set; }
public TranDtls TranDtls { get; set; }
public DocDtls DocDtls { get; set; }
public SellerDtls SellerDtls { get; set; }
public BuyerDtls BuyerDtls { get; set; }
public DispDtls DispDtls { get; set; }
public ShipDtls ShipDtls { get; set; }
public List ItemList { get; set; }
public ValDtls ValDtls { get; set; }
}
public class SellerDtls
{
public string Gstin { get; set; }
public string LglNm { get; set; }
public string Addr1 { get; set; }
public string Loc { get; set; }
public int Pin { get; set; }
public string Stcd { get; set; }
}
public class ShipDtls
{
public string Gstin { get; set; }
public string LglNm { get; set; }
public string Addr1 { get; set; }
public string Loc { get; set; }
public int Pin { get; set; }
public string Stcd { get; set; }
}
public class TranDtls
{
public string TaxSch { get; set; }
public string SupTyp { get; set; }
public string RegRev { get; set; }
public string IgstOnIntra { get; set; }
}
public class ValDtls
{
public int AssVal { get; set; }
public int CgstVal { get; set; }
public int SgstVal { get; set; }
public int IgstVal { get; set; }
public int CesVal { get; set; }
public int StCesVal { get; set; }
public int Discount { get; set; }
public int OthChrg { get; set; }
public int RndOffAmt { get; set; }
public int TotInvVal { get; set; }
}Thanks

Naimish MakwanaRank #324 · 7.7K reputationPosted Aug 14, 2024, 12:41 AM EDT
Here’s how you can assign values to your objects and then serialize them using RestSharp:
// Create an instance of Root and assign values Root root = new Root { Version = "1.0", TranDtls = new TranDtls { TaxSch = "GST", SupTyp = "B2B", RegRev = "Y", IgstOnIntra = "N" }, DocDtls = new DocDtls { Typ = "INV", No = "24QSC3409K1Z5", Dt = "2024-08-14" }, SellerDtls = new SellerDtls { Gstin = "24ABCDE1234F1Z5", LglNm = "XYZ Pvt Ltd", Addr1 = "10th Street", Loc = "Ahmedabad", Pin = 380015, Stcd = "GJ" }, // Similarly assign values for BuyerDtls, DispDtls, ShipDtls, ItemList, ValDtls }; // Serialize the object using RestSharp var client = new RestClient("http://example.com"); var request = new RestRequest(Method.POST); request.AddJsonBody(root); IRestResponse response = client.Execute(request);Please replace
"http://example.com"with your actual API endpoint. Also, make sure to assign appropriate values to all the properties of your objects. This is just a basic example. You may need to adjust it according to your specific requirements.Thanks
Jaimin ShethiyaRank #177 · 13.7K reputationPosted Aug 14, 2024, 6:36 AM EDT
Hello Ramco,
In case the above mention object details are coming from the database, then you need to create the store procedure and assign that value or you can use the linq query as well.
Thanks