public BlogPostViewModel Index(BlogPostViewModel inModel)
        {
            var badRedirectResult = new BlogPostViewModel {
                ResultOverride = new RedirectResult(_resolver.PageNotFoundUrl())
            };

            if (inModel.Slug.IsEmpty())
            {
                return(badRedirectResult);
            }

            var post = _repository.Query(new PostBySlug(inModel.Slug)).SingleOrDefault();

            if (post == null)
            {
                return(badRedirectResult);
            }

            User user = inModel.CurrentUser;

            var postDisplay = new PostDisplay(post);

            return(new BlogPostViewModel
            {
                Post = postDisplay,
                Comment = new CommentFormDisplay(user, new Comment(), postDisplay)
            });
        }
Beispiel #2
0
        public BlogPostViewModel Comment(BlogPostCommentViewModel inModel)
        {
            var badRedirectResult = new BlogPostViewModel {
                ResultOverride = new RedirectResult(_resolver.PageNotFound())
            };

            // Trying to reduce spam comments
            if (!string.IsNullOrEmpty(inModel.OptionalUrl) && (
                    inModel.OptionalUrl.Contains("geocities.com") ||
                    inModel.OptionalUrl.Contains("tripod.com")))
            {
                return(badRedirectResult);
            }

            if (inModel.Slug.IsEmpty())
            {
                return(badRedirectResult);
            }

            var post = _repository.Query(new PostBySlug(inModel.Slug)).SingleOrDefault();

            if (post == null)
            {
                return(badRedirectResult);
            }

            var postDisplay = new PostDisplay(post);

            if (inModel.ValidationResults.GetInvalidFields().Count() > 0)
            {
                var bblo = new BlogPostViewModel
                {
                    Post    = postDisplay,
                    Comment = new CommentFormDisplay(new Comment
                    {
                        Body           = inModel.Body,
                        UserSubscribed = inModel.Subscribed,
                        User           = new User
                        {
                            DisplayName     = inModel.DisplayName,
                            Email           = inModel.Email,
                            Url             = inModel.OptionalUrl,
                            TwitterUserName = inModel.OptionalTwitterUserName,
                        },
                    }, postDisplay),
                    SiteName = "{0} - {1}".ToFormat(inModel.SiteName, postDisplay.Title),
                    //ResultOverride = new RedirectResult(_resolver.PublishedPost(postDisplay) + "#leave_comment"),
                };
                bblo.Comment.ValidationResults.CloneFrom(inModel.ValidationResults);
                return(bblo);
            }

            var user = _userService.AddOrUpdateUser(inModel.Email, HttpUtility.HtmlEncode(inModel.DisplayName), HttpUtility.HtmlEncode(inModel.OptionalUrl), HttpUtility.HtmlEncode(inModel.OptionalTwitterUserName));

            _blogPostCommentService.AddCommentToBlogPost(HttpUtility.HtmlEncode(inModel.Body), inModel.Subscribed, user, post, inModel.OptionalTwitterUserName);

            return(new BlogPostViewModel {
                ResultOverride = new RedirectResult(_resolver.PublishedPost(postDisplay))
            });
        }
Beispiel #3
0
        public BlogPostViewModel Index(BlogPostViewModel inModel)
        {
            var badRedirectResult = new BlogPostViewModel {
                ResultOverride = new RedirectResult(_resolver.PageNotFound())
            };

            if (inModel.Slug.IsEmpty())
            {
                return(badRedirectResult);
            }

            var post = _repository.Query(new PostBySlug(inModel.Slug)).SingleOrDefault();

            if (post == null)
            {
                return(badRedirectResult);
            }

            User user = inModel.CurrentUser;

            var postDisplay = new PostDisplay(post);

            return(new BlogPostViewModel
            {
                Post = postDisplay,
                Comment = new CommentFormDisplay(new Comment {
                    User = user
                }, postDisplay),
                SiteName = "{0} - {1}".ToFormat(inModel.SiteName, postDisplay.Title),
            });
        }
 public static string PublishedPost(this IUrlResolver resolver, PostDisplay post)
 {
     // TODO: _resolver.UrlFor<BlogController>() + "/" + ...;
     return(("~/blog/" +
             post.Published.Year + "/" +
             post.Published.Month + "/" +
             post.Published.Day + "/" +
             post.Slug).ToFullUrl());
 }
        public static string GetCommentsText(this IAltOxitePage viewPage, PostDisplay post)
        {
            var commentCount = (post.Comments == null) ? 0 : post.Comments.Count();

            return("<a href=\"{0}#comments\">{1}</a>"
                   .ToFormat(
                       viewPage.UrlTo().PublishedPost(post),
                       (commentCount == 1)
                       ? "{0} comment".ToFormat(commentCount)
                       : "{0} comments".ToFormat(commentCount)));
        }
Beispiel #6
0
        public static EmbedBuilder BuildRedditPost(Post posts, SocketGuild guild)
        {
            PostDisplay display = new PostDisplay(posts);

            EmbedBuilder emb = new EmbedBuilder()
            {
                Color        = Color.Teal,
                Description  = display.Content,
                Footer       = BuildFooter(guild),
                ThumbnailUrl = display.Image,
                Title        = $"{display.Author} made a post on the subreddit.",
                Url          = display.URL,
            };

            emb.Fields = BuildFields(display);

            return(emb);
        }
        public BlogPostViewModel Comment(BlogPostCommentViewModel inModel)
        {
            var badRedirectResult = new BlogPostViewModel {
                ResultOverride = new RedirectResult(_resolver.PageNotFoundUrl())
            };

            if (inModel.Slug.IsEmpty())
            {
                return(badRedirectResult);
            }

            var post = _repository.Query(new PostBySlug(inModel.Slug)).SingleOrDefault();

            if (post == null)
            {
                return(badRedirectResult);
            }

            var result = new BlogPostViewModel();

            valid_comment_submission(inModel, result);

            if (result.InvalidFields.Count > 0)
            {
                result.ResultOverride = new RedirectResult(_resolver.PublishedPost(new PostDisplay(post)));
                return(result);
            }

            var user = _userService.AddOrUpdateUser(inModel.UserEmail, inModel.UserDisplayName, inModel.UserUrl);

            _blogPostCommentService.AddCommentToBlogPost(inModel.Body, inModel.UserSubscribed, user, post);

            var postDisplay = new PostDisplay(post);

            result.ResultOverride = new RedirectResult(_resolver.PublishedPost(postDisplay));

            return(result);
        }