public async Task <IHttpActionResult> PutMinisterioCelula(int id, MinisterioCelula ministerioCelula) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != ministerioCelula.IdMinisterioCelula) { return(BadRequest()); } db.Entry(ministerioCelula).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MinisterioCelulaExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public List <modelocrud> buscarCelulas(int?id) { Select_padrao = "select * from Celula as C " + " inner join MinisterioCelula as MICE on C.IdCelula=MICE.CelulaId" + " inner join Ministerio as M on MICE.MinisterioId=M.IdMinisterio" + $" where MICE.MinisterioId='{id}'"; List <modelocrud> modelos = new List <modelocrud>(); var conecta = bd.obterconexao(); conecta.Open(); SqlCommand comando = new SqlCommand(Select_padrao, conecta); SqlDataReader dr = comando.ExecuteReader(); if (dr.HasRows == false) { bd.obterconexao().Close(); return(modelos); } var lista = new MinisterioCelula().recuperar(null).OfType <MinisterioCelula>().ToList(); while (dr.Read()) { var m = lista.First(i => i.CelulaId == int.Parse(Convert.ToString(dr["CelulaId"]))); modelos.Add(m); } dr.Close(); bd.obterconexao().Close(); return(modelos); }
public List <modelocrud> recuperarMinisterios(int?id) { var select = "select * from Ministerio as m inner join " + " MinisterioCelula as mice on m.IdMinisterio=mice.MinisterioId inner join Celula as c" + $" on mice.CelulaId=c.IdCelula where mice.CelulaId='{id}' "; List <modelocrud> modelos = new List <modelocrud>(); var conecta = bd.obterconexao(); conecta.Open(); SqlCommand comando = new SqlCommand(select, conecta); SqlDataReader dr = comando.ExecuteReader(); if (dr.HasRows == false) { bd.obterconexao().Close(); return(modelos); } var lista = new MinisterioCelula().recuperar(null).OfType <MinisterioCelula>().ToList(); while (dr.Read()) { var m = lista.First(i => i.MinisterioId == int.Parse(Convert.ToString(dr["MinisterioId"]))); modelos.Add(m); } dr.Close(); bd.obterconexao().Close(); return(modelos); }
public async Task <IHttpActionResult> GetMinisterioCelula(int id) { MinisterioCelula ministerioCelula = await db.MinisterioCelula.FindAsync(id); if (ministerioCelula == null) { return(NotFound()); } return(Ok(ministerioCelula)); }
public async Task <IHttpActionResult> PostMinisterioCelula(MinisterioCelula ministerioCelula) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.MinisterioCelula.Add(ministerioCelula); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = ministerioCelula.IdMinisterioCelula }, ministerioCelula)); }
public async Task <IHttpActionResult> DeleteMinisterioCelula(int id) { MinisterioCelula ministerioCelula = await db.MinisterioCelula.FindAsync(id); if (ministerioCelula == null) { return(NotFound()); } db.MinisterioCelula.Remove(ministerioCelula); await db.SaveChangesAsync(); return(Ok(ministerioCelula)); }
public async Task <IHttpActionResult> DeleteMinisterioCelula(int id) { MinisterioCelula ministerioCelula = await db.MinisterioCelula.FindAsync(id); if (ministerioCelula == null) { return(NotFound()); } db.MinisterioCelula.Remove(ministerioCelula); await db.SaveChangesAsync(); db.DadoExcluido.Add(new DadoExcluido { Entidade = ministerioCelula.GetType().Name, IdDado = id }); await db.SaveChangesAsync(); return(Ok(ministerioCelula)); }