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")); }