public List<Comments> getAllCommentByIDTopic(int id) { String sql = "Select *From Comments where id_topic = '"+id.ToString()+"'"; List<Comments> Comments = new List<Comments>(); using (SqlConnection connection = BD.getConnection()) { SqlCommand Comando = new SqlCommand(string.Format(sql), connection); SqlDataReader reader = Comando.ExecuteReader(); while (reader.Read()) { Comments com = new Comments(); com.id = reader.GetInt32(0); com.id_topic = reader.GetInt32(1); com.id_user = reader.GetInt32(2); com.msg = reader.GetString(3); Comments.Add(com); } } return Comments; }
public ActionResult EliminarCa(int id) { Session["UserIDG"] = Session["UserIDG"]; Session["UserID"] = Session["UserID"]; Session["User"] = Session["User"]; string texto = "Estas seguro de Eliminar la categoria?"; string titulo = "Eliminar Categoria"; MessageBoxButtons button = MessageBoxButtons.YesNoCancel; MessageBoxIcon icon = MessageBoxIcon.Question; DialogResult result = MessageBox.Show(texto, titulo, button, icon); List<Topics> topics = new List<Topics>(); Comments comments = new Comments(); Topics top = new Topics(); topics = top.getAllTopicsByCatID(id); if (result.Equals(System.Windows.Forms.DialogResult.Yes)) { for (int i = 0; i < topics.Count; i++) { if (!comments.DeleteCommentsByIDTopic(topics[i].id_topic)) { MessageBox.Show("Comentario de " + topics[i].id_topic + "no eliminado"); } } if (!top.DeleteTopicsByIDCat(id)) { MessageBox.Show("Topic de " + id + "no eliminado"); } String sql = "Delete from Category where id_category = '" + id.ToString() + "'"; int retorno = 0; using (SqlConnection connection = BD.getConnection()) { SqlCommand Comando = new SqlCommand(string.Format(sql), connection); retorno = Comando.ExecuteNonQuery(); connection.Close(); } if (retorno > 0) { MessageBox.Show("Categoria Borrada Con Exito!!", "Eliminada", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("No se pudo borrar la Categoria", "Fallo!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } return RedirectToAction("Categorias", "Home"); }
public ActionResult EliminarTop(string name) { Session["UserIDG"] = Session["UserIDG"]; Session["UserID"] = Session["UserID"]; Session["User"] = Session["User"]; string texto = "Estas seguro de Eliminar el topic?"; string titulo = "Eliminar Topic"; MessageBoxButtons button = MessageBoxButtons.YesNoCancel; MessageBoxIcon icon = MessageBoxIcon.Question; DialogResult result = MessageBox.Show(texto, titulo, button, icon); Comments comments = new Comments(); Topics topic = new Topics(); topic = topic.getTopicsByName(name); if (result.Equals(System.Windows.Forms.DialogResult.Yes)) { if (!comments.DeleteCommentsByIDTopic(topic.id_topic)) { MessageBox.Show("Comentario de " + topic.id_topic + "no eliminado"); return Redirect("GeneralCat"); } String sql = "Delete from Topic where nameTopic = '" + name + "'"; int retorno = 0; using (SqlConnection connection = BD.getConnection()) { SqlCommand Comando = new SqlCommand(string.Format(sql), connection); retorno = Comando.ExecuteNonQuery(); connection.Close(); } if (retorno > 0) { MessageBox.Show("Topic Borrado Con Exito!!", "Eliminado", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("No se pudo borrar el Topic", "Fallo!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } return RedirectToAction("GeneralCat", new { name = Session["CatName"] }); }