Skip to content

Commit 898824c

Browse files
author
tsv2013
committed
Fixed live survey title update
1 parent 3043219 commit 898824c

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Controllers/ServiceController.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading.Tasks;
5+
using System.Web;
56
using Microsoft.AspNetCore.Mvc;
7+
using Newtonsoft.Json;
8+
using Newtonsoft.Json.Linq;
69

710
namespace 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

Comments
 (0)