public static PostReference GetNextPrevPost(this IDocumentSession session, Post compareTo, bool isNext)
        {
            var queryable = session.Query<Post>()
                .WhereIsPublicPost();

            if (isNext)
            {
                queryable = queryable
                    .Where(post => post.PublishAt >= compareTo.PublishAt && post.Id != compareTo.Id)
                    .OrderBy(post => post.PublishAt);
            }
            else
            {
                queryable = queryable
                    .Where(post => post.PublishAt <= compareTo.PublishAt && post.Id != compareTo.Id)
                    .OrderByDescending(post => post.PublishAt);
            }

            var postReference = queryable
                .Select(p => new Post { Id = p.Id, Title = p.Title })
                .FirstOrDefault();

            if (postReference == null)
                return null;

            return postReference.MapTo<PostReference>();
        }
Ejemplo n.º 2
0
        public bool AreCommentsClosed(Post post, int numberOfDayToCloseComments)
        {
            if (numberOfDayToCloseComments < 1)
                return false;

            DateTimeOffset lastCommentDate = Comments.Count == 0 ? post.PublishAt : Comments.Max(x => x.CreatedAt);
            return DateTimeOffset.Now - lastCommentDate > TimeSpan.FromDays(numberOfDayToCloseComments);
        }
Ejemplo n.º 3
0
        private void SendNewCommentEmail(Post post, PostComments.Comment comment, User postAuthor)
        {
            if (requestValues.IsAuthenticated)
                return; // we don't send email for authenticated users

            var viewModel = comment.MapTo<NewCommentEmailViewModel>();
            viewModel.PostId = RavenIdResolver.Resolve(post.Id);
            viewModel.PostTitle = HttpUtility.HtmlDecode(post.Title);
            viewModel.PostSlug = SlugConverter.TitleToSlug(post.Title);
            viewModel.BlogName = DocumentSession.Load<BlogConfig>("Blog/Config").Title;
            viewModel.Key = post.ShowPostEvenIfPrivate.MapTo<string>();

            var subject = string.Format("{2}Comment on: {0} from {1}", viewModel.PostTitle, viewModel.BlogName, comment.IsSpam ? "[Spam] " : string.Empty);

            TaskExecutor.ExcuteLater(new SendEmailTask(viewModel.Email, subject, "NewComment", postAuthor.Email, viewModel));
        }
Ejemplo n.º 4
0
 private void ValidateCommentsAllowed(Post post, PostComments comments)
 {
     if (comments.AreCommentsClosed(post, BlogConfig.NumberOfDayToCloseComments))
         ModelState.AddModelError("CommentsClosed", "This post is closed for new comments.");
     if (post.AllowComments == false)
         ModelState.AddModelError("CommentsClosed", "This post does not allow comments.");
 }
Ejemplo n.º 5
0
        private ActionResult PostingCommentSucceeded(Post post, CommentInput input)
        {
            const string successMessage = "Your comment will be posted soon. Thanks!";
            if (Request.IsAjaxRequest())
                return Json(new { Success = true, message = successMessage });

            TempData["new-comment"] = input;
            var postReference = post.MapTo<PostReference>();

            return Redirect(Url.Action("Details",
                                       new { Id = postReference.DomainId, postReference.Slug, key = post.ShowPostEvenIfPrivate }) + "#comments-form-location");
        }
Ejemplo n.º 6
0
        private ActionResult PostingCommentFailed(Post post, CommentInput input, Guid key)
        {
            if (Request.IsAjaxRequest())
                return Json(new { Success = false, message = ModelState.FirstErrorMessage() });

            var postReference = post.MapTo<PostReference>();
            var result = Details(postReference.DomainId, postReference.Slug, key);
            var model = result as ViewResult;
            if (model != null)
            {
                var viewModel = model.Model as PostViewModel;
                if (viewModel != null)
                    viewModel.Input = input;
            }
            return result;
        }
Ejemplo n.º 7
0
 private string GetPostLink(Post post)
 {
     if (post.Id == null) // invalid feed
         return Url.AbsoluteAction("Index", "Posts");
     return Url.AbsoluteAction("Details", "PostDetails", new { Id = RavenIdResolver.Resolve(post.Id), Slug = SlugConverter.TitleToSlug(post.Title), Key = post.ShowPostEvenIfPrivate });
 }