public ActionResult createPost(string postTitle, string postBody)
        {
            // clean up the whitespace
            postBody = postBody.Trim();
            postTitle = postTitle.Trim();

               // Declare our database connection // will exist only in the scope
            // of the using statement.
            using (Helpers.DAL.CapstoneEntities db = new Helpers.DAL.CapstoneEntities())
            {
                Helpers.DAL.tTopicPost newPost = new Helpers.DAL.tTopicPost()
                {
                    userID = Helpers.HelperQueries.getUserID(User.Identity.Name),
                    topicTitle = postTitle,
                    topicDate = DateTime.Now,
                    topicPost = postBody

                };

                db.AddTotTopicPosts(newPost);
                db.SaveChanges();

                object returnData = new
                {
                    postID = newPost.topicPostID,
                    postedBy = User.Identity.Name,
                    postTitle = postTitle,
                    postBody = postBody,
                    postDate = DateTime.Now.ToShortDateString() + " @ " + DateTime.Now.ToShortTimeString()
                };

                return Json(returnData, JsonRequestBehavior.AllowGet);
            }
        }
Example #2
0
        public ActionResult createPost(string postTitle, string postBody)
        {
            // clean up the whitespace
            postBody  = postBody.Trim();
            postTitle = postTitle.Trim();

            // Declare our database connection // will exist only in the scope
            // of the using statement.
            using (Helpers.DAL.CapstoneEntities db = new Helpers.DAL.CapstoneEntities())
            {
                Helpers.DAL.tTopicPost newPost = new Helpers.DAL.tTopicPost()
                {
                    userID     = Helpers.HelperQueries.getUserID(User.Identity.Name),
                    topicTitle = postTitle,
                    topicDate  = DateTime.Now,
                    topicPost  = postBody
                };

                db.AddTotTopicPosts(newPost);
                db.SaveChanges();

                object returnData = new
                {
                    postID    = newPost.topicPostID,
                    postedBy  = User.Identity.Name,
                    postTitle = postTitle,
                    postBody  = postBody,
                    postDate  = DateTime.Now.ToShortDateString() + " @ " + DateTime.Now.ToShortTimeString()
                };

                return(Json(returnData, JsonRequestBehavior.AllowGet));
            }
        }
Example #3
0
        public ActionResult postComment(int postID, string comment)
        {
            // Do some data transforms, and encoding
            comment = comment.Trim();


            // Declare our database connection // will exist only in the scope
            // of the using statement.
            using (Helpers.DAL.CapstoneEntities db = new Helpers.DAL.CapstoneEntities())
            {
                Helpers.DAL.tTopicPost commentPost = new Helpers.DAL.tTopicPost()
                {
                    topicParentID = postID,
                    topicPost     = comment,
                    topicDate     = DateTime.Now,
                    userID        = Helpers.HelperQueries.getUserID(User.Identity.Name),
                    // theres a ridiculous bug here - it wont let me save null
                    // objects on a nullable field, so set the title to 0
                    topicTitle = "0"
                };



                db.AddTotTopicPosts(commentPost);
                db.SaveChanges();
            }


            // This is where data modeling comes in handy. I hate that I have to declare yet ANOTHER model, but hey we cant have our cake and eat it too.
            ReplyModel returnObject = new ReplyModel()
            {
                parentID = postID,
                postBody = MSA.Encoder.HtmlEncode(comment),
                postDate = DateTime.Now.ToShortDateString() + " @ " + DateTime.Now.ToShortTimeString(),
                postedBy = User.Identity.Name
            };

            return(Json(returnObject, JsonRequestBehavior.AllowGet));
        }
        public ActionResult postComment(int postID, string comment)
        {
            // Do some data transforms, and encoding
            comment = comment.Trim();

            // Declare our database connection // will exist only in the scope
            // of the using statement.
            using (Helpers.DAL.CapstoneEntities db = new Helpers.DAL.CapstoneEntities())
            {
                Helpers.DAL.tTopicPost commentPost = new Helpers.DAL.tTopicPost()
                {
                    topicParentID = postID,
                    topicPost = comment,
                    topicDate = DateTime.Now,
                    userID = Helpers.HelperQueries.getUserID(User.Identity.Name),
                    // theres a ridiculous bug here - it wont let me save null
                    // objects on a nullable field, so set the title to 0
                    topicTitle = "0"
                };

                db.AddTotTopicPosts(commentPost);
                db.SaveChanges();
            }

            // This is where data modeling comes in handy. I hate that I have to declare yet ANOTHER model, but hey we cant have our cake and eat it too.
            ReplyModel returnObject = new ReplyModel()
            {
                parentID = postID,
                postBody = MSA.Encoder.HtmlEncode(comment),
                postDate = DateTime.Now.ToShortDateString() + " @ " + DateTime.Now.ToShortTimeString(),
                postedBy = User.Identity.Name
            };

                return Json(returnObject, JsonRequestBehavior.AllowGet);
        }