Esempio n. 1
0
        public bool SubmitPost(PostResultsViewModel postResults)
        {
            int rowsAffected = 0;

            try
            {
                using (SqlConnection conn = new SqlConnection(ConnectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand("Insert into posts Values (@threadID, @userID, @postBody, @postDate);", conn);
                    cmd.Parameters.AddWithValue("@threadID", postResults.NewPost.ThreadID);
                    cmd.Parameters.AddWithValue("@userID", postResults.NewPost.UserID);
                    cmd.Parameters.AddWithValue("@postBody", postResults.NewPost.PostBody);
                    cmd.Parameters.AddWithValue("@postDate", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
                    rowsAffected = cmd.ExecuteNonQuery();
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
            return(rowsAffected > 0);
        }
Esempio n. 2
0
        public ActionResult AddAPost(PostResultsViewModel model)
        {
            forumDAL.SubmitPost(model);
            ThreadModel      selectedThread = forumDAL.GetThreadByThreadID(model.SelectedThread.ThreadID);
            List <PostModel> AllPosts       = new List <PostModel>();

            AllPosts = forumDAL.GetAllPosts(selectedThread.ThreadID);
            model.AllPostsInThread = AllPosts;
            UserModel user = usersDAL.GetUser(base.CurrentUser);

            model.NewPost.UserID   = user.UserID;
            model.NewPost.Username = user.Username;
            //model.NewPost.PostBody = "";

            return(RedirectToAction("ViewPosts", new { threadID = model.SelectedThread.ThreadID }));
        }
Esempio n. 3
0
        public void TestSubmitPost()
        {
            ForumSqlDAL          dal     = new ForumSqlDAL();
            PostResultsViewModel model   = new PostResultsViewModel();
            PostModel            newPost = new PostModel();

            model.NewPost            = newPost;
            model.NewPost.ThreadID   = threadId;
            model.NewPost.UserID     = userId;
            model.NewPost.ThreadName = "The awesome threadName";
            model.NewPost.PostBody   = "This is the postBody";

            bool isSubmitted = dal.SubmitPost(model);

            Assert.IsTrue(isSubmitted);
        }
Esempio n. 4
0
        // GET: Forum


        public ActionResult ViewPosts(int threadID)
        {
            List <PostModel>     list   = new List <PostModel>();
            PostResultsViewModel model  = new PostResultsViewModel();
            ThreadModel          thread = forumDAL.GetThreadByThreadID(threadID);

            model.SelectedThread = thread;
            list = forumDAL.GetAllPosts(threadID);
            model.AllPostsInThread = list;
            UserModel user    = usersDAL.GetUser(base.CurrentUser);
            PostModel newPost = new PostModel();

            model.NewPost          = newPost;
            model.NewPost.UserID   = user.UserID;
            model.NewPost.ThreadID = thread.ThreadID;
            return(View("ViewPosts", model));
        }