Exemple #1
0
 public void ReplyForumPostTest()
 {
     ReplyModel replyModel = new ReplyModel();
     replyModel.ForumId = 1;
     replyModel.UserId = 1;
     replyModel.ReplyPost = "I am testing the reply post to a forum";
     Assert.IsTrue(forumController.ReplyForumPost(replyModel) != null);
 }
 protected void btnReply_Click(object sender, EventArgs e)
 {
     if (!String.IsNullOrEmpty(txtBoxReply.Text))
     {
         Controllers.ForumController forumController = new Controllers.ForumController();
         ReplyModel replyModel = new ReplyModel();
         User user = (User)Session["User"];
         replyModel.UserId = user.UserId;
         replyModel.ForumId = ForumModel.ForumId;
         replyModel.ReplyPost = txtBoxReply.Text;
         ForumModel = forumController.ReplyForumPost(replyModel);
         txtBoxReply.Text = "";
     }
 }
 public ForumModel ReplyForumPost(ReplyModel replyModel)
 {
     return new ForumBLL().ReplyForumPost(replyModel);
 }
Exemple #4
0
        public ForumModel ReplyForumPost(ReplyModel replyModel)
        {
            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(Constants.DATABASE.CONNECTION_STRING))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = new SqlCommand("INSERT INTO ReplyForumPost VALUES (@ForumId, @ReplyPost, @ReplyUserId, @ReplyDateEntered, @ReplyDateModified, @Active)", sqlConnection))
                    {

                        sqlCommand.Parameters.Add(new SqlParameter("ForumId", replyModel.ForumId));
                        sqlCommand.Parameters.Add(new SqlParameter("ReplyPost", replyModel.ReplyPost));
                        sqlCommand.Parameters.Add(new SqlParameter("ReplyUserId", replyModel.UserId));
                        sqlCommand.Parameters.Add(new SqlParameter("ReplyDateEntered", DateTime.Now));
                        sqlCommand.Parameters.Add(new SqlParameter("ReplyDateModified", DateTime.Now));
                        sqlCommand.Parameters.Add(new SqlParameter("Active", 1));
                        sqlCommand.ExecuteNonQuery();

                    }
                    sqlConnection.Close();
                }
                return ReadForumPost(replyModel.ForumId);
            }
            catch
            {
                return null;
            }
        }
Exemple #5
0
        public ForumModel ReadForumPost(int forumId)
        {
            try
            {
                ForumModel forumModel = new ForumModel();
                using (SqlConnection sqlConnection = new SqlConnection(Constants.DATABASE.CONNECTION_STRING))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = new SqlCommand("SELECT * FROM ForumPost " +
                        " INNER JOIN Users ON ForumPost.UserId = Users.UserID" +
                        " WHERE ForumPost.ForumId=" + forumId + " Order By DateModified DESC", sqlConnection))
                    {
                        using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
                        {
                            if (sqlDataReader.HasRows)
                            {
                                forumModel.ReplyList = new ArrayList();
                                sqlDataReader.Read();
                                forumModel.ForumId = Convert.ToInt32(sqlDataReader["ForumId"]);
                                forumModel.Subject = Convert.ToString(sqlDataReader["ForumSubject"]);
                                forumModel.ForumPost = Convert.ToString(sqlDataReader["ForumPost"]);
                                forumModel.UserId = Convert.ToInt32(sqlDataReader["UserId"]);
                                forumModel.DateEntered = Convert.ToDateTime(sqlDataReader["DateEntered"]);
                                forumModel.DateModified = Convert.ToDateTime(sqlDataReader["DateModified"]);
                                forumModel.FirstName = Convert.ToString(sqlDataReader["FirstName"]);
                                forumModel.LastName = Convert.ToString(sqlDataReader["LastName"]);

                            }
                            sqlDataReader.Close();
                        }

                    }
                    using (SqlCommand sqlCommand = new SqlCommand("Select * from ReplyForumPost " +
                            " INNER JOIN Users ON ReplyForumPost.ReplyUserId = Users.UserID" +
                            " WHERE ReplyForumPost.ForumId=" + forumId + " Order By ReplyDateModified ASC", sqlConnection))
                    {
                        using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
                        {
                            if (sqlDataReader.HasRows)
                            {
                                while (sqlDataReader.Read())
                                {
                                    ReplyModel replyModel = new ReplyModel();
                                    replyModel.ReplyPost = Convert.ToString(sqlDataReader["ReplyPost"]);
                                    replyModel.UserId = Convert.ToInt32(sqlDataReader["ReplyUserId"]);
                                    replyModel.DateEntered = Convert.ToDateTime(sqlDataReader["ReplyDateEntered"]);
                                    replyModel.DateModified = Convert.ToDateTime(sqlDataReader["ReplyDateModified"]);
                                    replyModel.FirstName = Convert.ToString(sqlDataReader["FirstName"]);
                                    replyModel.LastName = Convert.ToString(sqlDataReader["LastName"]);
                                    forumModel.ReplyList.Add(replyModel);
                                }
                            }
                            sqlDataReader.Close();
                        }
                    }
                    sqlConnection.Close();

                }
                return forumModel;
            }
            catch (Exception ex)
            {
                return null;
            }
        }