Exemplo n.º 1
0
        public void PostClassTest()
        {
            Post post = new Post();
            post.Title = "A Test Post";
            post.Date = DateTime.Now;
            post.MediaType = Post.Media.Article;
            post.Content = "Yeppy Tai Yai Yay!";
            post.Flagged = false;

            // Submit a post.
            try
            {
                using (DataContext postDataContext = new DataContext(Constants.DatabaseConnectionString))
                {
                    Table<Post> postTable = postDataContext.GetTable<Post>();

                    postTable.InsertOnSubmit(post);
                    postDataContext.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
            }

            post = null;

            // Retrieve the post.
            try
            {
                using (DataContext postDataContext = new DataContext(Constants.DatabaseConnectionString))
                {
                    Table<Post> postTable = postDataContext.GetTable<Post>();

                    post = (from postEntity in postTable where postEntity.Title.Contains("Test") select postEntity).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
            }

            Assert.IsNotNull(post);
        }
Exemplo n.º 2
0
        public ActionResult Post(int? id)
        {
            if (id == null || id < 1)
            {
                return RedirectToAction("Index");
            }
            else
            {
                Post post = new Post();

                // Grab the post content.
                using (DataContext postDataContext = new DataContext(Constants.DatabaseConnectionString))
                {
                    Table<Post> postTable = postDataContext.GetTable<Post>();

                    post = (from postEntity in postTable
                            where postEntity.ID == id
                            select postEntity).FirstOrDefault();

                    if (post != null) // Make sure the post object returned is not null, then update the post view count.
                    {
                        post.ViewCount++;

                        postDataContext.SubmitChanges();
                    }
                }

                // Grab all of the post comments.
                // At this time the comments are only ordered by their time stamp, from oldest to new.
                // Other alternatives to consider in the future are grouped threaded discussions, staircase type thread etc.
                using (DataContext cmtDataContext = new DataContext(Constants.DatabaseConnectionString))
                {
                    Table<Comment> cmtTable = cmtDataContext.GetTable<Comment>();

                    post.Comments = (from cmtEntity in cmtTable
                                     where cmtEntity.ParentPostID == post.ID
                                     orderby cmtEntity.Date ascending
                                     select cmtEntity).ToList();

                    post.CommentsCount = post.Comments.Count;
                }

                return View(post);
            }
        }
Exemplo n.º 3
0
        public ActionResult Viewed(int? id)
        {
            if (!Request.IsAjaxRequest())
            {
                return Content("error...");
            }

            if (id == null || id < 1)
            {
                return Content("error...");
            }

            Post post = new Post();

            // Grab the post content.
            using (DataContext postDataContext = new DataContext(Constants.DatabaseConnectionString))
            {
                Table<Post> postTable = postDataContext.GetTable<Post>();

                post = (from postEntity in postTable
                        where postEntity.ID == id
                        select postEntity).FirstOrDefault();

                if (post != null) // Make sure the post object returned is not null, then update the post view count.
                {
                    post.ViewCount++;

                    postDataContext.SubmitChanges();
                }
                else
                {
                    return Content("error...");
                }
            }

            return Content(post.ViewCount.ToString());
        }
Exemplo n.º 4
0
        public ActionResult SubmitPost(DomainModel.ValidationEntities.PostSubmission post)
        {
            if (!UserLoggedIn())
            {
                return RedirectToAction("Login");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    post.SourceURI = AffiliationHelper.LinkToAffiliates(post.SourceURI);
                    post.Title = HtmlFilterHelper.Filter(post.Title, new string[] { });
                    post.Description = HtmlFilterHelper.Filter(post.Description, new string[] { "a", "b", "i", "p" });

                    // Verify that it's not a double post.
                    using (DataContext postDataContext = new DataContext(Constants.DatabaseConnectionString))
                    {
                        Table<Post> postTable = postDataContext.GetTable<Post>();

                        DomainModel.DataEntities.Post postExists = (from postEntity in postTable
                                                                    where postEntity.Title == post.Title
                                                                    || (!String.IsNullOrEmpty(post.SourceURI) && post.SourceURI != "http://" && postEntity.SourceURI == post.SourceURI)
                                                                    || (!String.IsNullOrEmpty(post.Content) && postEntity.Content == post.Content)
                                                                    select postEntity).FirstOrDefault();

                        if (postExists != null)
                        {
                            ViewData["postAlreadyExists"] = true;
                            ViewData["existingPost"] = postExists;

                            return View();
                        }
                    }

                    if (post.MediaType == DomainModel.ValidationEntities.PostSubmission.Media.Video)
                    {
                        if (VideoPageHtmlParser.Provider == VideoPageHtmlParser.VideoProvider.YouTube)
                        {
                            post.Content = VideoPageHtmlParser.GetVideoObjectHtmlCode(post.SourceURI);
                        }
                    }
                    else if (post.MediaType == DomainModel.ValidationEntities.PostSubmission.Media.Question || post.MediaType == DomainModel.ValidationEntities.PostSubmission.Media.Blog)
                    {
                        post.SourceURI = String.Empty;
                        post.Description = String.Empty;
                        post.Content = HtmlFilterHelper.Filter(post.Content, new string[] { "a", "b", "i", "p" });
                        post.Content = HtmlParsingHelper.ReplaceLineBreaksWithHtml(post.Content);
                    }

                    using (DataContext postDataContext = new DataContext(Constants.DatabaseConnectionString))
                    {
                        Table<Post> postTable = postDataContext.GetTable<Post>();

                        DomainModel.DataEntities.Post postEntity = new Post();

                        postEntity.Date = DateTime.Now;
                        postEntity.UserName = ((DomainModel.DataEntities.User)Session["User"]).UserName;
                        postEntity.SourceURI = post.SourceURI;
                        postEntity.MediaType = (DomainModel.DataEntities.Post.Media)post.MediaType;
                        postEntity.Title = post.Title;
                        postEntity.Description = post.Description;
                        postEntity.Content = post.Content;

                        postTable.InsertOnSubmit(postEntity);
                        postDataContext.SubmitChanges();
                    }

                    ViewData["postSubmitted"] = true;

                    UpdateUserVoteQuota();
                }
                catch
                {
                    ViewData["postError"] = true;
                }
            }

            return View();
        }