// get listForResponse & check IdQuestion/IdReponse
        // Add reponse to user in new table Result
        public JsonResult saveResult(List <string> lst)
        {
            List <string> listreponse = new List <string>();
            User          u           = userService.getUserById(12);

            for (int i = 1; i < lst.Count; i++)
            {
                Analyse analyse = new Analyse
                {
                    UtilisateurId = u.UtilisateurID,
                    Utilisateur   = u
                };
                if (lst[0] == "qcm")
                {
                    int     idReponse = Int32.Parse(lst[i]);
                    Reponse r         = reponseService.getReponseById(idReponse);
                    analyse.AnalyseModel = "QCM for User";
                    analyse.TypeAnalyse  = Analyse.AnalyseType.QCM;
                    analyse.ReponseId    = idReponse;
                    analyse.Reponse      = r;
                }
                else
                {
                    var      rsl        = lst[i].Split(':');
                    int      idQuestion = Int32.Parse(rsl[0]);
                    Question q          = questionService.getQuestionById(idQuestion);
                    analyse.AnalyseModel = "Question for User";
                    analyse.QuestionId   = idQuestion;
                    analyse.Question     = q;
                    if (lst[0] == "noted")
                    {
                        analyse.NoteQuestion = Int32.Parse(rsl[1]);
                        analyse.TypeAnalyse  = Analyse.AnalyseType.Notee;
                    }
                    else
                    {
                        analyse.TextQuestion = rsl[1];
                        analyse.TypeAnalyse  = Analyse.AnalyseType.Ouvert;
                    }
                }
                analyseService.saveAnalyse(analyse);
                listreponse.Add("");
            }
            return(Json(listreponse, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public ActionResult Index(QuestionnaireVm model)
        {
            // _emailService.SendAcountCredentiel(new Domain.Model.User { AdresseEmail = "*****@*****.**", Password = "" });
            Questionnaire questionnaire;
            var           questions = new List <QuestionReponse>();

            foreach (var cat in model.CategorieQuestions)
            {
                foreach (var q in cat.Questions)
                {
                    var questionReponse = new QuestionReponse
                    {
                        QuestionID      = q.Question.QuestionID,
                        ReponseSelected = q.ReponseSelected,
                        ReponseString   = q.ReponseString
                    };

                    questions.Add(questionReponse);
                }
            }
            if (model.QuestionnaireId == 0)
            {
                questionnaire = new Questionnaire();

                questionnaire.Questions    = questions;
                questionnaire.UserId       = SecurityHelper.GetCurrentUserId();
                questionnaire.DateCreation = DateTime.Now;
                //Anayse
                var anlysePointsForts = string.Empty;
                foreach (var q in questions)
                {
                    if (q.ReponseSelected > 0)
                    {
                        var rep = _reponseService.getReponseById(q.ReponseSelected);
                        anlysePointsForts = anlysePointsForts + rep.AnalyseReponsePointsForts;
                    }
                }
                questionnaire.AnalysePointForts = anlysePointsForts;
                _questionnaireService.Create(questionnaire);
            }
            else
            {
                questionnaire = _questionnaireService.getQuestionnaireById(model.QuestionnaireId);
                _questionnaireService.DeleteQuestionReponseByQuestionnaireId(model.QuestionnaireId);
                questionnaire.Questions = questions;
                questionnaire.UserId    = SecurityHelper.GetCurrentUserId();
                //Anayse
                var anlysePointsForts = string.Empty;
                foreach (var q in questions)
                {
                    if (q.ReponseSelected > 0)
                    {
                        var rep = _reponseService.getReponseById(q.ReponseSelected);
                        anlysePointsForts = anlysePointsForts + rep.AnalyseReponsePointsForts;
                    }
                }
                questionnaire.AnalysePointForts = anlysePointsForts;
                _questionnaireService.Update(questionnaire);
            }
            var categories = categorieService.getCategories();

            model = new QuestionnaireVm(categories, questionnaire);
            // return View(model);
            return(RedirectToAction("ListQuestionnaire"));
        }