Ejemplo n.º 1
0
        public string Get(string id)
        {
            var result = _context.Survey.FindAsync(id);

            if (result == null)
            {
                return("Not found");
            }
            Survey     survey     = result.Result;
            JsonSurvey jsonSurvey = new JsonSurvey();

            jsonSurvey.id  = id;
            jsonSurvey.pwd = survey.PatternLock;
            List <JsonQuestion> jsonQuestionList = new List <JsonQuestion>();

            Question[] questionList = _context.Question.Include(q => q.Survey).Where(m => m.RefSurveyID == id).ToArray();
            foreach (Question question in questionList)
            {
                JsonQuestion jsonQuestion = new JsonQuestion();
                jsonQuestionList.Add(jsonQuestion);
                jsonQuestion.question = question.QuestionDescription;

                switch (question.QuestionType)
                {
                case QuestionType.Input:
                    jsonQuestion.type    = "edit";
                    jsonQuestion.options = new string[0];
                    break;

                case QuestionType.Multiple:
                    jsonQuestion.type    = "multiple";
                    jsonQuestion.options = question.Options.Split(";");
                    break;

                case QuestionType.Single:
                    jsonQuestion.type    = "single";
                    jsonQuestion.options = question.Options.Split(";");
                    break;

                default:
                    break;
                }
            }
            jsonSurvey.questions = jsonQuestionList.ToArray();
            string jsonStr = "";

            try
            {
                jsonStr = JsonSerializer.Serialize(jsonSurvey);
            }
            catch (Exception e)
            {
                return("Failed");
            }
            return(jsonStr);
        }
    private void Start()
    {
        answers         = new Answers();
        answers.choices = new List <string>();

        Cursor.lockState = CursorLockMode.None;

        jQuestions = new List <JsonQuestion>();
        jAnswers   = new List <JsonAnswer>();

        rSD    = GetComponent <RobotSurveyDownload>();
        survey = new JsonSurvey();

        backgroundScript.SetRotation(ParameterManager.Instance.BackgroundRotation);
    }