Example #1
0
        public ActionResult Create(Pessoa p)
        {
            try
            {
                var mc = new ModelContainer();

                mc.AddToPessoas(p);
                mc.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Example #2
0
        public ActionResult Delete(Pessoa p)
        {
            try
            {
                var mc = new ModelContainer();

                mc.Pessoas.Attach(p);
                mc.Pessoas.DeleteObject(p);
                mc.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Example #3
0
        public ActionResult Edit(int id, Pessoa p)
        {
            try
            {
                var mc = new ModelContainer();

                mc.Pessoas.Attach(p);
                mc.ObjectStateManager.ChangeObjectState(p, EntityState.Modified);
                mc.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }