Get All Product Details
1. getAllProductDetails.cs
These five packages are required to be used.
Step 1. Create class file to store content of the web response.
2. getAllProductDetails.aspx.cs
These 15 packages are required to be used.
Step 1. Store details entered by the user.
Step 2. Create URL which will be post to the server. User inputs need to be stored in the class created, and serialize into JSON format. In this function, both header and content are needed.
Step 3. Post to the server, and store response. URL is sent using web request function, and a response will be send back from the server. The response need to be deserialized into the ‘getAllProductDetails’ class.
Step 4. Obtain error code. If error code is ‘010000’ which means invocation successful, populate attributes of the ‘getAllProductDetails’ class into the Label and Gridview. If error code is '010041', it means OTP has expired, and we will use the newOTP() function to prompt the user for the OTP again. Else, we will display the ErrorText and ErrorDetails.
The newOTP() function can be referred to under Common Stuff Section
Overview of getAllProductDetails.cs
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Demo
{
public class getAllProductDetailsProduct
{
public string ProductName { get; set; }
public string MinOpeningBalance { get; set; }
public string PenaltyRate { get; set; }
public string ProductID { get; set; }
public string MaxLtvRatio { get; set; }
public string RepaymentPenaltyThreshold { get; set; }
public string Term { get; set; }
public string InterestRate { get; set; }
}
public class getAllProductDetailsProductList
{
[JsonConverter(typeof(ArrayConverter<getAllProductDetailsProduct>))]
public List<getAllProductDetailsProduct> Product { get; set; }
}
public class getAllProductDetailsProductParametersListReadResponse
{
public getAllProductDetailsProductList ProductList { get; set; }
}
public class getAllProductDetailsServiceRespHeader
{
public string ErrorText { get; set; }
public object ErrorDetails { get; set; }
public string GlobalErrorID { get; set; }
}
public class getAllProductDetailsServiceResponse
{
[JsonProperty("Product_ParametersList_Read-Response")]
public getAllProductDetailsProductParametersListReadResponse Product_ParametersList { get; set; }
public getAllProductDetailsServiceRespHeader ServiceRespHeader { get; set; }
}
public class getAllProductDetailsContent
{
public getAllProductDetailsServiceResponse ServiceResponse { get; set; }
}
public class getAllProductDetailsRootObject
{
public getAllProductDetailsContent Content { get; set; }
}
}
Overview of getAllProductDetails.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetOpenAuth.OAuth2;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Specialized;
using System.Configuration;
using System.Net;
using System.IO;
using System.Windows.Forms;
using System.Data;
namespace Demo
{
public partial class GetAllProductDetails : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
gvProductDetails.DataSource = null;
gvProductDetails.DataBind();
try
{
string bankID = txtBankID.Text;
var header = new HeaderJson();
header.userID = "";
header.PIN = "";
header.serviceName = "getAllProductDetails";
header.OTP = "";
var headerJson = new HeaderJsonObject();
headerJson.Header = header;
string strHeader = JsonConvert.SerializeObject(headerJson);
var content = new ContentJson();
content.bankID = bankID;
var contentJson = new ContentJsonObject();
contentJson.Content = content;
string strContent = JsonConvert.SerializeObject(contentJson);
string url = "http://tbankonline.com/SMUtBank_API/Gateway?Header=" + strHeader + "&Content=" + strContent;
var webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.ContentType = "application/json";
webRequest.Method = "POST";
var result = "";
var httpResponse = (HttpWebResponse)webRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
getAllProductDetailsRootObject PD = new getAllProductDetailsRootObject();
PD = JsonConvert.DeserializeObject<getAllProductDetailsRootObject>(result);
string globalErrorID = PD.Content.ServiceResponse.ServiceRespHeader.GlobalErrorID.ToString();
if (globalErrorID == "010000")
{
int counter = PD.Content.ServiceResponse.Product_ParametersList.ProductList.Product.Count();
DataTable dt = new DataTable();
DataColumn col1 = new DataColumn(" ", typeof(string));
DataColumn col2 = new DataColumn("Product Name", typeof(string));
DataColumn col3 = new DataColumn("Min Opening Balance", typeof(string));
DataColumn col4 = new DataColumn("Penalty Rate", typeof(string));
DataColumn col5 = new DataColumn("Product ID", typeof(string));
DataColumn col6 = new DataColumn("Max Ltv Ratio", typeof(string));
DataColumn col7 = new DataColumn("Repayment Penalty Threshold", typeof(string));
DataColumn col8 = new DataColumn("Term", typeof(string));
DataColumn col9 = new DataColumn("Interest Rate", typeof(string));
dt.Columns.Add(col1);
dt.Columns.Add(col2);
dt.Columns.Add(col3);
dt.Columns.Add(col4);
dt.Columns.Add(col5);
dt.Columns.Add(col6);
dt.Columns.Add(col7);
dt.Columns.Add(col8);
dt.Columns.Add(col9);
// put data into the data table
for (int i = 0; i <= counter - 1; i++)
{
DataRow row = dt.NewRow();
dt.Rows.Add(row);
dt.Rows[i][col1] = i + 1;
dt.Rows[i][col2] = PD.Content.ServiceResponse.Product_ParametersList.ProductList.Product[i].ProductName?.ToString() ?? " ";
dt.Rows[i][col3] = PD.Content.ServiceResponse.Product_ParametersList.ProductList.Product[i].MinOpeningBalance?.ToString() ?? " ";
dt.Rows[i][col4] = PD.Content.ServiceResponse.Product_ParametersList.ProductList.Product[i].PenaltyRate?.ToString() ?? " ";
dt.Rows[i][col5] = PD.Content.ServiceResponse.Product_ParametersList.ProductList.Product[i].ProductID?.ToString() ?? " ";
dt.Rows[i][col6] = PD.Content.ServiceResponse.Product_ParametersList.ProductList.Product[i].MaxLtvRatio?.ToString() ?? " ";
dt.Rows[i][col7] = PD.Content.ServiceResponse.Product_ParametersList.ProductList.Product[i].RepaymentPenaltyThreshold?.ToString() ?? " ";
dt.Rows[i][col8] = PD.Content.ServiceResponse.Product_ParametersList.ProductList.Product[i].Term?.ToString() ?? " ";
dt.Rows[i][col9] = PD.Content.ServiceResponse.Product_ParametersList.ProductList.Product[i].InterestRate?.ToString() ?? " ";
}
gvProductDetails.DataSource = dt;
gvProductDetails.DataBind();
}
else
{
lblTest.Text = PD.Content.ServiceResponse.ServiceRespHeader.ErrorText.ToString();
string errorMessage = PD.Content.ServiceResponse.ServiceRespHeader.ErrorDetails.ToString();
lblErrorMessage.Text = errorMessage;
}
}
catch (Exception ex)
{
lblExceptionMsg.Text = ex.ToString();
}
}
}
}
}
Created with the Personal Edition of HelpNDoc: Write EPub books for the iPad