예제 #1
0
    public void InsertComment(CommentsClass comment)
    {
        SqlCommand InsertCommentCommand = new SqlCommand("InsertComment", DefaultConnection);
        InsertCommentCommand.CommandType = System.Data.CommandType.StoredProcedure;

        InsertCommentCommand.Parameters.Add("@RecipeID", SqlDbType.Int);
        InsertCommentCommand.Parameters["@RecipeID"].Value = comment.RecipeID;

        InsertCommentCommand.Parameters.Add("@UserName", SqlDbType.NVarChar, 50);
        InsertCommentCommand.Parameters["@UserName"].Value = comment.User;

        InsertCommentCommand.Parameters.Add("@Comment", SqlDbType.Text);
        InsertCommentCommand.Parameters["@Comment"].Value = comment.Comment;

        InsertCommentCommand.Parameters.Add("@PostedTime", SqlDbType.DateTime);
        InsertCommentCommand.Parameters["@PostedTime"].Value = comment.PostedTime;

        try
        {
            DefaultConnection.Open();
            InsertCommentCommand.ExecuteNonQuery();
        }
        catch (Exception e)
        {
            throw;
        }
        finally
        {
            DefaultConnection.Close();
        }
    }
예제 #2
0
    protected void CommentButton_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            if (Membership.GetUser() == null)
                Response.Redirect(@"~\Account\Login.aspx?ReturnUrl=" + Page.Request.RawUrl, false);
            else
            {
                CommentsClass newComment = new CommentsClass();
                newComment.User = User.Identity.Name;
                newComment.RecipeID = RecipeID;
                newComment.Comment = CommentBox.Text;
                newComment.PostedTime = DateTime.Now;

                new CommentsDB().InsertComment(newComment);

                Response.Redirect(Page.Request.RawUrl);
            }
        }
    }