public ChatBotIntent getChatBotIntentByID(int intentID) { SqlConnection conn = new SqlConnection(); ChatBotIntent toReturn = new ChatBotIntent(); 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 [ChatBotIntent] where intentID=@intentID"; comm.Parameters.AddWithValue("@intentID", intentID); SqlDataReader dr = comm.ExecuteReader(); while (dr.Read()) { toReturn.intentID = (int)dr["intentID"]; toReturn.intent = (string)dr["intent"]; } dr.Close(); } catch (SqlException ex) { throw ex; } finally { conn.Close(); } return(toReturn); }
protected void Page_Load(object sender, EventArgs e) { if (Session["currentUser"] == null) { Response.Redirect("Login.aspx"); } else { if (!IsPostBack) { 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 { ChatBotIntentDAO cbiDAO = new ChatBotIntentDAO(); ChatBotIntent currentCBI = cbiDAO.getChatBotIntentByID(Convert.ToInt32(Request.QueryString["id"])); txtIntentInput.Text = currentCBI.intent; } } } }
public List <ChatBotIntent> getAllChatBotIntent() { SqlConnection conn = new SqlConnection(); List <ChatBotIntent> toReturn = new List <ChatBotIntent>(); 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 [ChatBotIntent]"; SqlDataReader dr = comm.ExecuteReader(); while (dr.Read()) { ChatBotIntent cbi = new ChatBotIntent(); cbi.intentID = (int)dr["intentID"]; cbi.intent = (string)dr["intent"]; toReturn.Add(cbi); } dr.Close(); } catch (SqlException ex) { throw ex; } finally { conn.Close(); } return(toReturn); }
protected void cfmSubmit_Click(object sender, EventArgs e) { //To do validations ChatBotIntentDAO cbiDAO = new ChatBotIntentDAO(); ChatBotIntent currentCBI = cbiDAO.getChatBotIntentByID(Convert.ToInt32(Request.QueryString["id"])); cbiDAO.updateChatBotIntent(txtIntentInput.Text, currentCBI.intentID); //set audit User currentUser = (User)Session["currentUser"]; setAudit(currentUser, "learny intent", "update", currentCBI.intentID.ToString(), "updated intent name: " + txtIntentInput.Text); Response.Redirect("askLearnyAddIntent.aspx"); }
protected void btnCfmDelete_Click(object sender, EventArgs e) { //To do validations ChatBotIntentDAO cbiDAO = new ChatBotIntentDAO(); ChatBotIntent currentCBI = cbiDAO.getChatBotIntentByID(Convert.ToInt32(Request.QueryString["id"])); cbiDAO.deleteAnswersByIntent(currentCBI.intentID); cbiDAO.deleteIntentByID(currentCBI.intentID); //set audit User currentUser = (User)Session["currentUser"]; setAudit(currentUser, "learny intent", "delete", currentCBI.intentID.ToString(), "deleted intent name: " + currentCBI.intent); Response.Redirect("askLearnyAddIntent.aspx"); }