Beispiel #1
0
    protected void btnAddPost_Click(object sender, EventArgs e)
    {
        String str;

         str = edited_html.InnerText;
         string mesag = str;

         // we could save database in clean HTML

         //System.Text.StringBuilder sb = new System.Text.StringBuilder(
         //          HttpUtility.HtmlEncode(str));
         //string mesag = "";
         //mesag = sb.ToString();
         //convertHTMLcode conv = new convertHTMLcode();
         //mesag = conv.convertHTMLtext(mesag);

         blogpostsModel.blogdbEntities bl = new blogpostsModel.blogdbEntities();

         if (s == null)
         {

             blogpostsModel.blogpost po = new blogpostsModel.blogpost();
             //po.blogID = 3;
             po.blogMsgText = mesag;
             po.posted = DateTime.Now;
             bl.AddToblogposts(po);
             bl.SaveChanges();

         }
         else
         {
             int requestID2;
             requestID2 = Convert.ToInt16(s);

             blogpostsModel.blogpost ite = bl.blogposts.First(c => c.blogID == requestID2);
             ite.blogMsgText = mesag;
             ite.lastedited = DateTime.Now;
             bl.SaveChanges();

         }

         try
         {
             FormsAuthentication.SignOut();
         }
         catch { }

            Response.Redirect("blog.aspx");
    }
Beispiel #2
0
    protected void addComment(object sender, EventArgs e)
    {
        Button btn = (Button)sender;

        GridViewRow row = (GridViewRow)btn.NamingContainer;

        DataControlFieldCell Datafld = (DataControlFieldCell)row.Controls[0];

        Label lbl = (Label)Datafld.Controls[1];

        TextBox txtB = (TextBox)Datafld.Controls[3];

        String stroka;

        stroka = txtB.Text;

        if (stroka.Trim().Length<1)
            return;

        System.Text.StringBuilder sb2 = new System.Text.StringBuilder(
                  HttpUtility.HtmlEncode(stroka));

        string commm;
        commm = sb2.ToString();
        commm = Regex.Replace(commm, "\\n", "<br />", RegexOptions.IgnoreCase);

        int commmID;
        commmID = Convert.ToInt16(lbl.Text);

        blogpostsModel.blogdbEntities bl = new blogpostsModel.blogdbEntities();
        blogpostsModel.blogcomment po = new blogpostsModel.blogcomment();
        po.commentID =commmID;
        po.commentMsgText = commm;
        bl.AddToblogcomments(po);
        bl.SaveChanges();

        Response.Redirect(Request.Path);
    }
Beispiel #3
0
    protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "RemoveRecord")
        {

        string lbltext;
            try
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridView gr = sender as GridView;
                GridViewRow row = gr.Rows[index];

               Label lbl = row.FindControl("cID") as Label;
                lbltext = lbl.Text.Trim();
            }
            catch {
                return;
            }

            blogpostsModel.blogdbEntities bl = new blogpostsModel.blogdbEntities();

            blogpostsModel.blogcomment bc = new blogpostsModel.blogcomment();

            // remove using command
            string qStr = "Delete FROM blogcomments where cID="+lbltext;
            bl.ExecuteStoreCommand(qStr);
            bl.SaveChanges();

            Response.Redirect(Request.Path);

        }
    }