Embarking on a new journey with AngularJS and ASP.NET WebAPI, I find myself faced with the challenge of working with base tables structured as follows:
CurriculumID SubjectArea CourseNumber
------------ ----------- ------------
303 GHIJ 101
304 ABCD 102
305 MNPQ 103
306 WXYZ 104
lookupId lookupValue
-------- -----------
1 Very Useful
2 Somewhat Useful
3 Not Useful
4 Not Applicable
5 Elsewhere
To tackle this requirement, I've created model classes (course and lookup) for these tables. Now, my quest is to generate JSON data in the backend using a web API controller method
public HttpResponseMessage getData(...)
The desired JSON output should be structured as follows:
$scope.questions = [
{
"CurriculumID": "303", "SubjectArea": "GHIJ", "CourseNumber": "101", "answers": [
{ "lookupValue": "Very Useful","lookupId":"1" },
{ "lookupValue": "Somewhat Useful", "lookupId": "2" },
{ "lookupValue": "Not Useful", "lookupId": "3" },
{ "lookupValue": "Not Applicable", "lookupId": "4" },
{ "lookupValue": "Elsewhere", "lookupId": "5" }
]
},
{
"CurriculumID": "304", "SubjectArea": "ABCD", "CourseNumber": "102", "answers": [
{ "lookupValue": "Very Useful","lookupId":"1" },
{ "lookupValue": "Somewhat Useful", "lookupId": "2" },
{ "lookupValue": "Not Useful", "lookupId": "3" },
{ "lookupValue": "Not Applicable", "lookupId": "4" },
{ "lookupValue": "Elsewhere", "lookupId": "5" }
]
}
.
.
.
];
For further insights, refer to this link: https://plnkr.co/edit/73oA3rsrre8gqYX9V25W?p=preview
I'm seeking guidance on constructing the two methods getData
to serialize this structure in ASP.NET. Any assistance towards achieving this serialization would be greatly appreciated.