public void InsertPerson(string user_id, string nom) { using (var context = new AvisEntitis()) { var person = context.Person.Where(f => f.user_id == user_id).FirstOrDefault(); if (person == null) { Person p = new Person(); p.Nom = nom; p.user_id = user_id; context.Person.Add(p); context.SaveChanges(); } } }
public ActionResult SaveComment(string name, string note, string description, string nSeo) { PersonManager mgr = new PersonManager(); string user_id = User.Identity.GetUserId(); Avis nouveAvis = new Avis(); nouveAvis.DateAvis = DateTime.Now; nouveAvis.Description = description; nouveAvis.Nom = name; nouveAvis.UserId = ""; // double dNote = 0; if (!double.TryParse(note, out dNote)) { throw new Exception("Parse Invalid"); } else { nouveAvis.Note = dNote; } using (var context = new AvisEntitis()) { var formation = context.Formation.FirstOrDefault(f => f.NomSeo == nSeo); nouveAvis.IdFormation = formation.Id; nouveAvis.Nom = mgr.GetNameByUserId(user_id); PersonManager mngr = new PersonManager(); if (mngr.IsExiste(User.Identity.GetUserId(), nouveAvis.IdFormation) == false) { context.Avis.Add(nouveAvis); context.SaveChanges(); } } /// RedirectToAction("DetailsFormation", "Formations", new { nSeo = nSeo }); return(RedirectToAction("DetailsFormation", "Formation", new { nSeo = nSeo })); }