public void Criar(Tarefa tarefa) { try { using(ConexaoDeDados conexao = new ConexaoDeDados()){ conexao.TbTarefa.Add(tarefa); conexao.SaveChanges(); } }catch { throw; } }
public void Gravar(Usuario usuario) { using(conexao = new ConexaoDeDados()) { try { conexao.TbUsuario.Add(usuario); usuario.Senha = GeraHashMd5(usuario.Senha); conexao.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach(var erro in dbEx.EntityValidationErrors){ foreach (var linha in erro.ValidationErrors) { linha.ErrorMessage.ToString(); } } throw; } } }
public void Excluir(int id) { try { using (ConexaoDeDados conexao = new ConexaoDeDados()) { Tarefa tarefa = new Tarefa(); tarefa.Id = id; conexao.TbTarefa.Remove(tarefa); conexao.SaveChanges(); } } catch { throw; } }
public void Editar(Tarefa tarefa) { try { using (ConexaoDeDados conexao = new ConexaoDeDados()) { conexao.Entry(tarefa).State = EntityState.Modified; conexao.SaveChanges(); } } catch { throw; } }