public ActionResult Create() { VMDisciplina vm = new VMDisciplina(); return View(vm); }
public ActionResult Edit(long id, VMDisciplina vm) { try { Disciplina disciplina = db.Disciplinas.Find(vm.Id); db.Disciplinas.Remove(disciplina); db.SaveChanges(); this.FlashInfo("Disciplina removida com sucesso"); return this.RedirectToAction("Index"); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } return View(vm); }
public ActionResult Edit(long id) { VMDisciplina vm = new VMDisciplina(); Disciplina disciplina = db.Disciplinas.Find(id); vm.Nome = disciplina.Nome; vm.Id = disciplina.Id; foreach (var aluno in disciplina.Alunos) { vm.Alunos.Add(new VMAluno() { Id = aluno.Id, Email = aluno.Email, Nome = aluno.UserName }); } return View(vm); }
public ActionResult Edit(VMDisciplina vm) { if (ModelState.IsValid) { try { Disciplina disciplina = db.Disciplinas.Find(vm.Id); disciplina.Nome = vm.Nome; db.SaveChanges(); this.FlashInfo("Disciplina atualizada com sucesso"); return this.RedirectToAction("Index"); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } return View(vm); }
public ActionResult Create(VMDisciplina vm) { if (ModelState.IsValid) { try { Disciplina disciplina = new Disciplina(); disciplina.Nome = vm.Nome; db.Disciplinas.Add(disciplina); db.SaveChanges(); this.FlashInfo("Disciplina cadastrada com sucesso"); return this.RedirectToAction("Edit", new { id = disciplina.Id }); } catch(Exception ex) { ModelState.AddModelError("", ex.Message); } } return View(vm); }