Hi
I'm using angular and asp.net as a back-end. I would like to save the full survey result in one field in a data base. How could I achieve this.
in my survey.component.ts, I have this code snippet:
TypeScriptngOnInit() {
const survey = new Model(json);
const baseApiUrl : string = environment.baseApiUrl ;
survey.onComplete.add(function (sender, options) {
// Display the "Saving..." message (pass a string value to display a custom message)
options.showSaveInProgress();
const xhr = new XMLHttpRequest();
xhr.open("POST", baseApiUrl + '/api/Survey');
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xhr.onload = xhr.onerror = function () {
if (xhr.status == 200) {
// Display the "Success" message (pass a string value to display a custom message)
options.showSaveSuccess();
// Alternatively, you can clear all messages:
// options.clearSaveMessages();
} else {
// Display the "Error" message (pass a string value to display a custom message)
options.showSaveError("Erreur d'enregistrement");
}
};
xhr.send(JSON.stringify(sender.data));
});
this.model = survey; //pour afficher le mode dans la page web
}
In my API, C# controller I have this
C# [Route("api/[controller]")]
[ApiController]
public class SurveyController : Controller
{
[HttpPost]
public async Task<IActionResult> InsertClient([FromBody] SurveyJSData surveyJSData)
{
var client = new Client
{
NomComplet = surveyJSData.NomComplet,
PrenomComplet = surveyJSData.PrenomComplet,
DateNaissance = surveyJSData.DateNaissance
};
Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<Client> entityEntry = _context.Client.Add(client);
await _context.SaveChangesAsync();
return Ok(client);
I would like also to have an additional field like this
C#allResult = surveyJSData.AllResult
but I'm not able to do that. I have tested various things
I have tables, page and other types of questions in my survey.
Thanks