public ActionResult Create(SurveyVM suv, string employename) { IEnumerable <utilisateur> employesnum = us.GetEmployesByman(2); List <utilisateur> employesList = new List <utilisateur>(); foreach (var employe in employesnum) { employesList.Add(employe); } ViewData["employes"] = employesList; int empid = System.Convert.ToInt32(employename.Substring(0, 1)); try { if (questions.Count() == 0) { ModelState.AddModelError("", "Ajouter des questions !"); return(View()); } else { foreach (SurveyQuestion quest in questions) { quest.date = DateTime.Now; quest.employeId = empid; quest.managerId = 2; //surquestservice.Add(quest); } List <SurveyQuestion> questionlist = new List <SurveyQuestion>(); questionlist = questions; foreach (SurveyQuestion quest in questionlist) { quest.date = DateTime.Now; quest.employeId = empid; quest.managerId = 2; surquestservice.Add(quest); } Survey sv = new Survey() { date = DateTime.Now, duree = suv.duree, status = true, managerId = 2, employeId = empid }; surveyservice.Add(sv); surveyservice.Commit(); surquestservice.Commit(); questions.Clear(); return(RedirectToAction("Index")); } } catch (Exception e) { // Console.WriteLine(e.Message); return(View(e.Message)); } }