private void EnregistrerTempsRepartir(ObjRepartir resultat) { int tempsParPersonne = (int)(Math.Round((double)resultat.Duree / resultat.ChoixMentores.Length, MidpointRounding.AwayFromZero)); //int tempsParPersonne = Convert.ToInt32((double) (resultat.Duree / resultat.ChoixMentores.Length)); var entities = new List <Intervention>(); if (tempsParPersonne > 0) { foreach (var iNoMentore in resultat.ChoixMentores) { var entity = new Intervention { Date_Intervention = resultat.Date, No_Mentor_Intervention = HttpContext.Session.GetString("intNoMentor").ToString(), //No_Mentor_Intervention =Session["intNoMentor"].ToString(), No_Mentore_Intervention = iNoMentore, Duree_Intervention = tempsParPersonne, Description_Intervention = resultat.Commentaire, }; db.Interventions.Add(entity); entities.Add(entity); } db.SaveChanges(); } }
public ActionResult RepartirContent(ObjRepartir resultat) { if (ModelState.IsValid) { var erreursMentore = new List <string>(); foreach (string noMentore in resultat.ChoixMentores) { if (!ValiderInscriptionMentore(resultat.Date, noMentore)) { string nomMentore = ""; using (var db = new ApplicationDbContext()) { Mentore mentore = db.Mentores.FirstOrDefault(f => f.No_Mentore == noMentore); if (mentore != null) { nomMentore = mentore.NomComplet_Mentore; } } if (nomMentore == "") { nomMentore = "inconnu"; } erreursMentore.Add(nomMentore); } } if (erreursMentore.Count == 0) { EnregistrerTempsRepartir(resultat); return(Json(new { success = true })); } else { return(Json(new { success = false, msg = "Ces mentorés ne sont pas inscrits au service de mentorat : \n\n" + string.Join(", ", erreursMentore.ToArray()) })); } } return(Json(new { success = false })); }