public Professor FindWithCursos(int id) { Professor professor = new Professor(); using (AppDBContext Context = new AppDBContext()) { professor = Context.Professores.Include(typeof(Curso).Name).FirstOrDefault(c => c.Id == id); } return professor; }
public void Add(Professor professor) { if (professor is IValidator) { ((IValidator)professor).Validate(); } using (AppDBContext Context = new AppDBContext()) { Context.Professores.Add(professor); Context.SaveChanges(); } }
public bool Delete(Professor professor) { bool retorno = true; try { using (AppDBContext Context = new AppDBContext()) { Professor professorTemp = Context.Professores.FirstOrDefault(c => c.Id == professor.Id); Context.Professores.Remove(professorTemp); Context.SaveChanges(); } } catch (Exception) { retorno = false; } return retorno; }
public void Update(Professor professor) { if (professor is IValidator) { ((IValidator)professor).Validate(); } using (AppDBContext Context = new AppDBContext()) { Context.Entry(professor).State = EntityState.Modified; Context.SaveChanges(); } }