public ActionResult createShout(string shoutMessage)
        {
            // pull the person making the shout from the
            // current session
            string userName = User.Identity.Name;

            // Declare our database context
            //
            using (var db = new Helpers.DAL.CapstoneEntities())
            {
               // Declare a new shout - use the Entity Framework object
               // to make this easier use object initialization format
                Helpers.DAL.tShout thisShout = new Helpers.DAL.tShout()
                {
                    shoutString = shoutMessage,
                    userID = Helpers.HelperQueries.getUserID(userName)
                };

                db.AddTotShouts(thisShout);
                db.SaveChanges();

                var returnShout = new Models.ShoutModel()
                {
                    shoutString = thisShout.shoutString,
                    userID = Helpers.HelperQueries.GetUserName((int)thisShout.userID)
                };

                // this tshout now contains everything we need to copy it to
                // a blank object - that we can JSON encode and return to the browser
                // and use jquery to append it to he html <Span>
                return Json(returnShout, JsonRequestBehavior.AllowGet);
            }
        }
        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);
            }
        }
        // set this to require authorization
        public ActionResult createShout(string shoutMessage)
        {
            // pull the person making the shout from the
            // current session
            string userName = User.Identity.Name;

            // Declare our database context
            //
            using (var db = new Helpers.DAL.CapstoneEntities())
            {
                // Declare a new shout - use the Entity Framework object
                // to make this easier use object initialization format
                Helpers.DAL.tShout thisShout = new Helpers.DAL.tShout()
                {
                    shoutString = shoutMessage,
                    userID      = Helpers.HelperQueries.getUserID(userName)
                };

                db.AddTotShouts(thisShout);
                db.SaveChanges();

                var returnShout = new Models.ShoutModel()
                {
                    shoutString = thisShout.shoutString,
                    userID      = Helpers.HelperQueries.GetUserName((int)thisShout.userID)
                };


                // this tshout now contains everything we need to copy it to
                // a blank object - that we can JSON encode and return to the browser
                // and use jquery to append it to he html <Span>
                return(Json(returnShout, JsonRequestBehavior.AllowGet));
            }
        }
Example #4
0
        public ActionResult deletePost(int postID)
        {
            using (Helpers.DAL.CapstoneEntities db = new Helpers.DAL.CapstoneEntities())
            {
                var replies = from x in db.tTopicPosts
                              where (x.topicParentID == postID)
                              select x;

                foreach (var reply in replies)
                {
                    // attach it back to the table (?) i know this is dumb
                    db.CreateObjectSet <Helpers.DAL.tTopicPost>().Attach(reply);

                    // Delete it
                    db.ObjectStateManager.ChangeObjectState(reply, System.Data.EntityState.Deleted);
                }


                // this is a bit of mojo to delete a post without a stored proc
                var post = new Helpers.DAL.tTopicPost();

                // create a post, assign its id
                post.topicPostID = postID;

                // attach it back to the table (?) i know this is dumb
                db.CreateObjectSet <Helpers.DAL.tTopicPost>().Attach(post);

                // Delete it
                db.ObjectStateManager.ChangeObjectState(post, System.Data.EntityState.Deleted);
                db.SaveChanges();
            };

            return(Json(postID));
        }
Example #5
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 #6
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);
        }
        public ActionResult deletePost(int postID)
        {
            using (Helpers.DAL.CapstoneEntities db = new Helpers.DAL.CapstoneEntities())
            {
                var replies = from x in db.tTopicPosts
                        where (x.topicParentID == postID)
                        select x;

                foreach(var reply in replies)
                {

                    // attach it back to the table (?) i know this is dumb
                    db.CreateObjectSet<Helpers.DAL.tTopicPost>().Attach(reply);

                    // Delete it
                    db.ObjectStateManager.ChangeObjectState(reply, System.Data.EntityState.Deleted);

                }

                // this is a bit of mojo to delete a post without a stored proc
                var post = new Helpers.DAL.tTopicPost();

                // create a post, assign its id
                post.topicPostID = postID;

                // attach it back to the table (?) i know this is dumb
                db.CreateObjectSet<Helpers.DAL.tTopicPost>().Attach(post);

                // Delete it
                db.ObjectStateManager.ChangeObjectState(post, System.Data.EntityState.Deleted);
                db.SaveChanges();

            };

            return Json(postID);
        }