public async Task <IHttpActionResult> AlternaTb_tarefas(int id, bool fg_finalizado) { tb_tarefas tb_tarefas = await db.tb_tarefas.FindAsync(id); if (tb_tarefas == null) { return(NotFound()); } if (tb_tarefas == null) { return(NotFound()); } if (fg_finalizado && fg_finalizado == tb_tarefas.fg_finalizado) { tb_tarefas.fg_finalizado = false; tb_tarefas.dt_concluido = null; } else if (!fg_finalizado && fg_finalizado == tb_tarefas.fg_finalizado) { tb_tarefas.fg_finalizado = true; tb_tarefas.dt_concluido = DateTime.Today; } return(await Puttb_tarefas(id, tb_tarefas, "alternar")); }
public async Task <IHttpActionResult> Deletetb_tarefas(int id) { tb_tarefas tb_tarefas = await db.tb_tarefas.FindAsync(id); if (tb_tarefas == null) { return(NotFound()); } return(await Puttb_tarefas(id, tb_tarefas, "delete")); }
public async Task <IHttpActionResult> Posttb_tarefas(tb_tarefas tb_tarefas) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } tb_tarefas.dt_criado = DateTime.Today; db.tb_tarefas.Add(tb_tarefas); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = tb_tarefas.id }, tb_tarefas)); }
public async Task <IHttpActionResult> Puttb_tarefas(int id, tb_tarefas tb_tarefas, string action = "edit") { if (action == "edit") { tb_tarefas tb_tarefas_banco = await db.tb_tarefas.FindAsync(id); tb_tarefas_banco.ds_descricao = tb_tarefas.ds_descricao; tb_tarefas_banco.ds_titulo = tb_tarefas.ds_titulo; tb_tarefas_banco.dt_editado = DateTime.Today; tb_tarefas = tb_tarefas_banco; } else if (action == "delete") { tb_tarefas.dt_deletado = DateTime.Today; } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tb_tarefas.id) { return(BadRequest()); } db.Entry(tb_tarefas).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!tb_tarefasExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }