Esempio n. 1
0
 public JsonResult SaveData()
 {
     if (IsPreview == false)
     {
         List <QuestionAnswerViewModel> q = AccountController.GetQuestionAnswer();
         RespondentViewModel            r = AccountController.GetRespondent();
         if (q != null)
         {
             foreach (var item in q)
             {
                 item.AddQuestionAnswer(item);
             }
         }
         if (r != null)
         {
             r.AddRespondent(r);
             foreach (var item in r.Responses)
             {
                 item.AddResponse(item);
             }
         }
     }
     AccountController.ClearQuestionAnswer();
     AccountController.ClearQuestion();
     return(Json(true, JsonRequestBehavior.AllowGet));
 }
Esempio n. 2
0
        public JsonResult SaveAnswers(string answer, string answers, string questionid, string ipaddress, string browser)
        {
            List <QuestionAnswerViewModel> q = AccountController.GetQuestionAnswer();
            RespondentViewModel            r = AccountController.GetRespondent();

            if (r == null)
            {
                r    = new RespondentViewModel();
                r.Id = Guid.NewGuid();
                if (AccountController.CheckUser())
                {
                    r.UserId       = AccountController.GetUser().Id;
                    r.IsRegistered = true;
                }
                r.IPAdress    = ipaddress;
                r.BrowserName = browser;
                r.SurveyId    = AccountController.GetSurveyId();
            }
            //q.Add(new QuestionViewModel{Id = new Guid(questionid)});

            //int i = r.Count - 1;
            if (r.Responses == null)
            {
                r.Responses = new List <ResponseViewModel>();
            }
            if (q == null)
            {
                q = new List <QuestionAnswerViewModel>();
            }
            if (answer != null)
            {
                QuestionAnswerViewModel qa = new QuestionAnswerViewModel
                {
                    Id         = Guid.NewGuid(),
                    QuestionId = new Guid(questionid),
                    Answer     = answer
                };
                q.Add(qa);
                AccountController.RememberQuestionAnswer(q);

                ResponseViewModel rs = new ResponseViewModel
                {
                    Id             = Guid.NewGuid(),
                    QuestionId     = new Guid(questionid),
                    ResponseAnswer = qa.Id,
                    RespondentId   = r.Id
                };
                r.Responses.Add(rs);
            }
            else if (answers != "")
            {
                string[] a = answers.Split(',');
                //UpdateList();
                //var type = listQuestion.Find(x=>x.Id==new Guid(questionid)).Type;
                //if (type == "Yes/No")
                //{
                //    answers = new List<string>();
                //}
                foreach (var item in a)
                {
                    if (item != "")
                    {
                        ResponseViewModel rs = new ResponseViewModel
                        {
                            Id             = Guid.NewGuid(),
                            QuestionId     = new Guid(questionid),
                            ResponseAnswer = new Guid(item),
                            RespondentId   = r.Id
                        };
                        r.Responses.Add(rs);
                    }
                }
            }
            AccountController.RememberRespondent(r);
            return(Json(true, JsonRequestBehavior.AllowGet));
        }