public ActionResult Create(Pessoa p) { if (ModelState.IsValid) { try { using(var mc = new ModelContainer()) { mc.AddToPessoas(p); mc.SaveChanges(); } return RedirectToAction("Index"); } catch(Exception ex) { ModelState.AddModelError("MSG", ex); return View(); } } else { return View(); } }
/// <summary> /// Create a new Pessoa object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="nome">Initial value of the Nome property.</param> /// <param name="sexoId">Initial value of the SexoId property.</param> public static Pessoa CreatePessoa(global::System.Int32 id, global::System.String nome, global::System.String sexoId) { Pessoa pessoa = new Pessoa(); pessoa.Id = id; pessoa.Nome = nome; pessoa.SexoId = sexoId; return pessoa; }
/// <summary> /// Deprecated Method for adding a new object to the Pessoas EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToPessoas(Pessoa pessoa) { base.AddObject("Pessoas", pessoa); }