protected void Page_Load(object sender, EventArgs e) { if (Session["currentUser"] != null) { User currentUser = (User)Session["currentUser"]; Boolean superuser = false; foreach (String s in currentUser.getRoles()) { if (s.Equals("superuser")) { superuser = true; } } if (!superuser) { Response.Redirect("errorPage.aspx"); } else { if (!IsPostBack) { ChatBotInstructionDAO cbiDAO = new ChatBotInstructionDAO(); ChatBotInstruction currentInstruction = cbiDAO.getInstruction(); txtTitle.Text = currentInstruction.title; CKEditor1.Text = currentInstruction.instruction; } } } else { Response.Redirect("Login.aspx"); } }
public ChatBotInstruction getInstruction() { SqlConnection conn = new SqlConnection(); ChatBotInstruction toReturn = new ChatBotInstruction(); try { conn = new SqlConnection(); string connstr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString(); conn.ConnectionString = connstr; conn.Open(); SqlCommand comm = new SqlCommand(); comm.Connection = conn; comm.CommandText = "select * from [ChatBotInstruction]"; SqlDataReader dr = comm.ExecuteReader(); while (dr.Read()) { toReturn.title = (string)dr["title"]; toReturn.instruction = (string)dr["instruction"]; } dr.Close(); } catch (SqlException ex) { throw ex; } finally { conn.Close(); } return(toReturn); }