public Postagens SpAddTarefa(Postagens post) { SqlConnection con = new SqlConnection(this.Context.Database.GetDbConnection().ConnectionString); con.Open(); SqlCommand cmd = new SqlCommand("comando", con); if (post.Tipo == "comunicado") { cmd.CommandText = "sp_addComunicado " + post.IdSala + ", '" + post.Descricao + "', '" + post.Data + "', '" + post.Tipo + "', '" + post.DataEntrega + "', " + post.IdAtividade; } else { cmd.CommandText = "sp_addTarefa " + post.IdSala + ", '" + post.Descricao + "', '" + post.Data + "', '" + post.Tipo + "', '" + post.DataEntrega + "', " + post.IdAtividade; } SqlDataReader leitor = cmd.ExecuteReader(); while (leitor.Read()) { post.Id = Convert.ToInt32(leitor["id"]); } con.Close(); return(post); }
public List <Postagens> SpGetPostagensBySalaCod(string codigo) { SqlConnection con = new SqlConnection(this.Context.Database.GetDbConnection().ConnectionString); con.Open(); SqlCommand cmd = new SqlCommand("comando", con); cmd.CommandText = "sp_GetPostagensCod '" + codigo + "'"; SqlDataReader leitor = cmd.ExecuteReader(); var result = new List <Postagens>(); while (leitor.Read()) { Postagens dados = new Postagens( (int)leitor["id"], (int)leitor["idSala"], (string)leitor["descricao"], (DateTime)leitor["data"], (string)leitor["tipo"], (DateTime)leitor["dataEntrega"], (int)leitor["idAtividade"]); result.Add(dados); } result.Reverse(); con.Close(); return(result); }
public void Postar(Postagem post) { post.SetUsuario(this); post.Validate(); AddNotifications(post.Notifications); if (Valid) { Postagens.Add(post); } }
public async Task <IActionResult> post(Postagens modelo) { try { var result = this.Repo.SpAddTarefa(modelo); return(Ok(result)); } catch { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Falha no acesso ao banco de dados.")); } }
public async Task <IActionResult> delete(int PostagemId) { try { //verifica se existe postagem a ser excluído Postagens postagem = await this.Repo.GetPostagemById(PostagemId); if (postagem == null) { return(NotFound()); } this.Repo.SpDeletarPostagemById(postagem); return(Ok()); } catch { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Falha no acesso ao banco de dados.")); } }
public void SpDeletarPostagemById(Postagens post) { SqlConnection con = new SqlConnection(this.Context.Database.GetDbConnection().ConnectionString); con.Open(); SqlCommand cmd = new SqlCommand("comando", con); if (post.Tipo == "atividade") { cmd.CommandText = "sp_DeletarTarefa " + post.Id; } else { cmd.CommandText = "sp_DeletarComunicado " + post.Id; } cmd.ExecuteNonQuery(); con.Close(); }