22using System . Collections . Generic ;
33using System . Linq ;
44using System . Threading . Tasks ;
5+ using System . Web ;
56using Microsoft . AspNetCore . Mvc ;
7+ using Newtonsoft . Json ;
8+ using Newtonsoft . Json . Linq ;
69
710namespace surveyjs_aspnet_mvc . Controllers
811{
@@ -22,12 +25,21 @@ public class PostSurveyResultModel
2225 [ Route ( "/api" ) ]
2326 public class ServiceController : Controller
2427 {
28+ private JObject GetSurveyObject ( SurveyDefinition survey )
29+ {
30+ var jobj = new JObject ( ) ;
31+ jobj [ "id" ] = survey . id ;
32+ jobj [ "name" ] = survey . name ;
33+ jobj [ "json" ] = JsonConvert . DeserializeObject ( survey . json ) as JObject ;
34+ return jobj ;
35+ }
2536
2637 [ HttpGet ( "getActive" ) ]
27- public JsonResult GetActive ( )
38+ public ContentResult GetActive ( )
2839 {
2940 var db = new SessionStorage ( HttpContext . Session ) ;
30- return Json ( db . GetSurveys ( ) ) ;
41+ var result = db . GetSurveys ( ) . Select ( survey => GetSurveyObject ( survey ) ) ;
42+ return Content ( JsonConvert . SerializeObject ( result ) , "application/json" ) ;
3143 }
3244
3345 [ HttpGet ( "getSurvey" ) ]
@@ -53,11 +65,13 @@ public JsonResult ChangeName(string id, string name)
5365 }
5466
5567 [ HttpPost ( "changeJson" ) ]
56- public JsonResult ChangeJson ( [ FromBody ] ChangeSurveyModel model )
68+ public ContentResult ChangeJson ( [ FromBody ] ChangeSurveyModel model )
5769 {
5870 var db = new SessionStorage ( HttpContext . Session ) ;
5971 db . StoreSurvey ( model . id , model . text ) ;
60- return Json ( db . GetSurvey ( model . id ) ) ;
72+ var survey = db . GetSurvey ( model . id ) ;
73+ var result = GetSurveyObject ( survey ) ;
74+ return Content ( JsonConvert . SerializeObject ( result ) , "application/json" ) ;
6175 }
6276
6377 [ HttpGet ( "delete" ) ]
0 commit comments