public tb_mativo Add(tb_mativo contato) { tb_mativo cont = db.tb_mativo.Add(contato); db.SaveChanges(); return(cont); }
public tb_mativo Remove(long id) { tb_mativo cont = db.tb_mativo.Find(id); db.tb_mativo.Remove(cont); db.SaveChanges(); return(cont); }
public HttpResponseMessage ListarContatoId(long id) { tb_mativo resultCont = mativoService.Get(id); if (resultCont == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Contato não encontrado")); } return(Request.CreateResponse(HttpStatusCode.OK, resultCont)); }
public HttpResponseMessage DeletarContato(long id) { tb_mativo cont = mativoService.Get(id); if (cont == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Contato não encontrado")); } else { mativoService.Remove(cont.codContato); var resp = new HttpResponseMessage() { Content = new StringContent("{\"Message\":\"Contato deletado com sucesso\"}") }; resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); return(resp); } }
public string Update(tb_mativo contato) { string retorno = ""; var existingCont = db.tb_mativo.Where(s => s.codContato == contato.codContato).FirstOrDefault <tb_mativo>(); if (existingCont != null) { existingCont.codContato = contato.codContato; existingCont.codUsuario = contato.codUsuario; existingCont.nome = contato.nome; existingCont.telefone = contato.telefone; existingCont.email = contato.email; db.SaveChanges(); retorno = "Contato alterado com sucesso"; } else { retorno = "Contato não encontrado"; } return(retorno); }
public tb_mativo Get(long id) { tb_mativo cont = db.tb_mativo.Find(id); return(cont); }