public ActionResult Create(Perfil perfil) { if (ModelState.IsValid) { string[] ids = Request.Form.AllKeys.Skip(1).ToArray(); foreach (var item in ids) { int id = int.Parse(Request.Form[item]); db.ExecuteStoreCommand("Insert into PerfilFuncionalidade values({0}, {1})", new object[] { perfil.Id, id }); } db.Perfil.AddObject(perfil); db.SaveChanges(); return RedirectToAction("Index"); } return View(perfil); }
/// <summary> /// Deprecated Method for adding a new object to the Perfil EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToPerfil(Perfil perfil) { base.AddObject("Perfil", perfil); }
/// <summary> /// Create a new Perfil object. /// </summary> /// <param name="id">Initial value of the Id property.</param> public static Perfil CreatePerfil(global::System.Int32 id) { Perfil perfil = new Perfil(); perfil.Id = id; return perfil; }
public ActionResult Edit(Perfil perfil) { if (ModelState.IsValid) { string[] ids = Request.Form.AllKeys.Skip(1).ToArray(); db.ExecuteStoreCommand("Delete from PerfilFuncionalidade where IdPerfil = {0}", new object[] { perfil.Id }); foreach (var item in ids) { int id = int.Parse(Request.Form[item]); db.ExecuteStoreCommand("Insert into PerfilFuncionalidade values({0}, {1})", new object[] { perfil.Id, id }); } db.Perfil.Attach(perfil); db.ObjectStateManager.ChangeObjectState(perfil, EntityState.Modified); db.SaveChanges(); return RedirectToAction("Index"); } return View(perfil); }