Example #1
0
        public bool CreateNewForum(ForumModel forumModel)
        {
            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(Constants.DATABASE.CONNECTION_STRING))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = new SqlCommand("INSERT INTO ForumPost VALUES (@ForumSubject, @ForumPost, @UserId, @DateEntered, @DateModified, @Active)", sqlConnection))
                    {

                        sqlCommand.Parameters.Add(new SqlParameter("ForumSubject", forumModel.Subject));
                        sqlCommand.Parameters.Add(new SqlParameter("ForumPost", forumModel.ForumPost));
                        sqlCommand.Parameters.Add(new SqlParameter("UserId", forumModel.UserId));
                        sqlCommand.Parameters.Add(new SqlParameter("DateEntered", DateTime.Now));
                        sqlCommand.Parameters.Add(new SqlParameter("DateModified", DateTime.Now));
                        sqlCommand.Parameters.Add(new SqlParameter("Active", 1));
                        sqlCommand.ExecuteNonQuery();

                    }
                    sqlConnection.Close();
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     if (!String.IsNullOrEmpty(txtBoxSubject.Text) && !String.IsNullOrEmpty(txtBoxPost.Text))
     {
         ForumModel forumModel = new ForumModel();
         forumModel.ForumPost = txtBoxPost.Text;
         forumModel.ForumId = Convert.ToInt32(Request["ForumId"]);
         new Controllers.ForumController().EditForumPost(forumModel);
         Response.Redirect("~/Forum/ForumPostDetails.aspx?ForumId="+ Request["ForumId"]);
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Request["ForumId"] != null)
     {
         Controllers.ForumController forumController = new Controllers.ForumController();
         ForumModel = forumController.ReadForumPost(Convert.ToInt32(Request["ForumId"]));
     }
     else
     {
         Response.Redirect(Request.UrlReferrer.AbsolutePath);
     }
 }
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     if (!String.IsNullOrEmpty(txtBoxSubject.Text) && !String.IsNullOrEmpty(txtBoxPost.Text))
     {
         ForumModel forumModel = new ForumModel();
         forumModel.Subject = txtBoxSubject.Text;
         forumModel.ForumPost = txtBoxPost.Text;
         User user = (User)Session["User"];
         forumModel.UserId = user.UserId;
         new ForumController().CreateNewForum(forumModel);
         Response.Redirect("~/Forum/Forum.aspx");
     }
 }
 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 = "";
     }
 }
Example #6
0
        public ArrayList DisplayForumPosts()
        {
            try
            {
                ArrayList forumList = new ArrayList();
                using (SqlConnection sqlConnection = new SqlConnection(Constants.DATABASE.CONNECTION_STRING))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = new SqlCommand("SELECT * FROM ForumPost INNER JOIN Users ON Users.UserID = ForumPost.UserId WHERE Active=1 Order By DateModified DESC", sqlConnection))
                    {
                        using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
                        {
                            if (sqlDataReader.HasRows)
                            {

                                while (sqlDataReader.Read())
                                {
                                    ForumModel forumModel = new ForumModel();
                                    forumModel.ForumId = Convert.ToInt32(sqlDataReader["ForumId"]);
                                    forumModel.Subject = Convert.ToString(sqlDataReader["ForumSubject"]);
                                    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"]);
                                    forumList.Add(forumModel);
                                }
                            }
                            sqlDataReader.Close();
                        }
                    }
                    sqlConnection.Close();

                }
                return forumList;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
Example #7
0
 public bool DeleteForumPost(ForumModel forumModel)
 {
     try
     {
         using (SqlConnection sqlConnection = new SqlConnection(Constants.DATABASE.CONNECTION_STRING))
         {
             sqlConnection.Open();
             using (SqlCommand sqlCommand = new SqlCommand("Update ForumPost SET  Active = 0, DateModified = @DateModified WHERE ForumId = @ForumId", sqlConnection))
             {
                 sqlCommand.Parameters.Add(new SqlParameter("ForumId", forumModel.ForumId));
                 sqlCommand.Parameters.Add(new SqlParameter("DateModified", DateTime.Now));
                 sqlCommand.ExecuteNonQuery();
             }
             sqlConnection.Close();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
 public bool EditForumPost(ForumModel forumModel)
 {
     return new ForumBLL().EditForumPost(forumModel);
 }
 public bool DeleteForumPost(ForumModel forumModel)
 {
     return new ForumBLL().DeleteForumPost(forumModel);
 }
Example #10
0
 public bool CreateNewForum(ForumModel forumModel)
 {
     return new ForumBLL().CreateNewForum(forumModel);
 }
Example #11
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;
            }
        }