Пример #1
0
        public static void GetPCMD()
        {
            SqlConnection conn = GetConnection();
            string selStrng = "SELECT * FROM PostCommentRelation ";
            SqlCommand selCmd = new SqlCommand(selStrng, conn);
            try
            {
                conn.Open();
                SqlDataReader reader = selCmd.ExecuteReader();
                while (reader.Read())
                {
                    if (reader["IsDeleted"].ToString() == "False")
                    {
                        PostCommentRelation pcr = new PostCommentRelation(Comment.Items[new Guid(reader["CommentId"].ToString())]);

                        //pcr.Post = Post.Items[new Guid(reader["PostId"].ToString())];
                        //pcr.Comment = Comment.Items[new Guid(reader["CommentId"].ToString())];
                        string isDel = reader["IsDeleted"].ToString();
                        if (isDel == "True") pcr.IsDeleted = true;
                        else pcr.IsDeleted = false;

                        PostCommentRelation.Items.Add(pcr.Id, pcr);
                    }
                }
                reader.Close();
            }
            catch (SqlException ex) { throw ex; }
            finally { conn.Close(); }
        }
Пример #2
0
        public static void SaveToDB(PostCommentRelation pcr)
        {
            string insString = "INSERT INTO PostCommentRelation (PostId, CommentID) VALUES (@postid, @commentid)";
            SqlConnection conn = GetConnection();
            SqlCommand insCmd = new SqlCommand(insString, conn);
            insCmd.Parameters.AddWithValue("@postid", pcr.Post.Id.ToString());
            insCmd.Parameters.AddWithValue("@commentid", pcr.Comment.Id.ToString());

            try
            {
                conn.Open();
                insCmd.ExecuteNonQuery();
            }
            catch (SqlException ex) { throw ex; }
            finally { conn.Close(); }
        }
Пример #3
0
        public static void AddCommentToDB(Comment cmnt)
        {
            string insString = "INSERT INTO Comment (ID, Title, Body, DateAdded, PostId) VALUES (@id, @title, @body, @added, @postId)";
            SqlConnection conn = GetConnection();
            SqlCommand insCmd = new SqlCommand(insString, conn);
            insCmd.Parameters.AddWithValue("@id", cmnt.Id.ToString());
            insCmd.Parameters.AddWithValue("@title", cmnt.Title);
            insCmd.Parameters.AddWithValue("@body", cmnt.Body);
            var date = cmnt.CommentedDate.ToString("yyyy-MM-dd HH:mm:ss");
            insCmd.Parameters.AddWithValue("@added", date);
            insCmd.Parameters.AddWithValue("@postId", cmnt.getPost().Id);
            try
            {
                conn.Open();
                insCmd.ExecuteNonQuery();
            }
            catch (SqlException ex) { throw ex; }
            finally { conn.Close(); }

            PostCommentRelation PCR = new PostCommentRelation(cmnt);
            PstCmntRelationManager.SaveToDB(PCR);
        }