I have created an api which accept list and one string as parameter.
public class LifeScoreGetRequestData
{
public string UserAge { get; set; }
public List<QuestionAnswerMapping> QAnswelist { get; set; }
}
public class QuestionAnswerMapping
{
public string QuestionID { get; set; }
public string AnswerOptionID { get; set; }
}
my api
public async Task<IActionResult> LifeScoreDetailsAsync(LifeScoreGetRequestData lifescore)
{
try
{
var response = await _lifescoreRepository.LifeScoreGetDetails(lifescore).ConfigureAwait(false);
if (!response.Status)
{
return BadRequest(new { status = response.Status, message = response.Message });
}
return Ok(response);
}
catch (Exception ex)
{
Logger.AddErrorLog(this.ControllerContext.ActionDescriptor.ControllerName + "Controller", this.ControllerContext.ActionDescriptor.MethodInfo.Name, User.Identity.Name, ex);
return StatusCode(500, new { Status = false, Message = String.Concat(ex.Message, MessageHelper.GenericException) });
}
I am trying to pass value from another solution. Where i am getting data as DataTable and i have converted that DataTable in below format.
[
{"QuestionID":"1021","AnswerOptionID":"1051"},
{"QuestionID":"1022","AnswerOptionID":"1057"},
{"QuestionID":"1023","AnswerOptionID":"1059"},
{"QuestionID":"1024","AnswerOptionID":"1061"},
{"QuestionID":"1025","AnswerOptionID":"1063"},
{"QuestionID":"1027","AnswerOptionID":"1067"},
{"QuestionID":"1028","AnswerOptionID":"1068"},
{"QuestionID":"1029","AnswerOptionID":"1077"},
{"QuestionID":"1030","AnswerOptionID":"1079"},
{"QuestionID":"1031","AnswerOptionID":"1081"},
{"QuestionID":"1032","AnswerOptionID":"1083"},
{"QuestionID":"1033","AnswerOptionID":"1085"},
{"QuestionID":"1034","AnswerOptionID":"1086"},
{"QuestionID":"1035","AnswerOptionID":"1089"},
{"QuestionID":"1036","AnswerOptionID":"1091"},
{"QuestionID":"1037","AnswerOptionID":"1093"},
{"QuestionID":"1038","AnswerOptionID":"1095"},
{"QuestionID":"1039","AnswerOptionID":"1097"},
{"QuestionID":"1040","AnswerOptionID":"1099"},
{"QuestionID":"1041","AnswerOptionID":"1101"},
{"QuestionID":"1042","AnswerOptionID":"1103"},
{"QuestionID":"1043","AnswerOptionID":"1105"},
{"QuestionID":"1044","AnswerOptionID":"1106"}
]
I do not know how to pass the data below is my code.
clientHandler.ServerCertificateCustomValidationCallback += (sender, cert, chain, sslPolicyErrors) => { return true; };
clientHandler.SslProtocols = SslProtocols.None;
HttpClient client = new HttpClient(clientHandler);
MultipartFormDataContent multiContent = new MultipartFormDataContent();
multiContent.Add(new StringContent(Convert.ToString(UserAge)), "UserAge");
multiContent.Add(new StringContent(result), "QAnswelist");
var content = new StringContent(result, Encoding.UTF8, "application/json");
var response = client.PostAsync(new Uri ("http://localhost:54462/api/lifescore/get"), multiContent).Result;