public virtual ActionResult Details(int id, string slug, Guid key)
        {
            var post = RavenSession
                       .Include <Post>(x => x.CommentsId)
                       .Include(x => x.AuthorId)
                       .Load(id);

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

            if (post.IsPublicPost(key) == false)
            {
                return(HttpNotFound());
            }

            SeriesInfo seriesInfo = GetSeriesInfo(post.Title);

            var comments = RavenSession.Load <PostComments>(post.CommentsId) ?? new PostComments();
            var vm       = new PostViewModel
            {
                Post     = post.MapTo <PostViewModel.PostDetails>(),
                Comments = comments.Comments
                           .OrderBy(x => x.CreatedAt)
                           .MapTo <PostViewModel.Comment>(),
                NextPost          = RavenSession.GetNextPrevPost(post, true),
                PreviousPost      = RavenSession.GetNextPrevPost(post, false),
                AreCommentsClosed = comments.AreCommentsClosed(post, BlogConfig.NumberOfDayToCloseComments),
                SeriesInfo        = seriesInfo
            };

            vm.Post.Author = RavenSession.Load <User>(post.AuthorId).MapTo <PostViewModel.UserDetails>();

            var comment = TempData["new-comment"] as CommentInput;

            if (comment != null)
            {
                vm.Comments.Add(new PostViewModel.Comment
                {
                    CreatedAt = DateTimeOffset.Now.ToString(),
                    Author    = comment.Name,
                    Body      = MarkdownResolver.Resolve(comment.Body),
                    Id        = -1,
                    Url       = UrlResolver.Resolve(comment.Url),
                    Tooltip   = "Comment by " + comment.Name,
                    EmailHash = EmailHashResolver.Resolve(comment.Email)
                });
            }

            if (vm.Post.Slug != slug)
            {
                return(RedirectToActionPermanent("Details", new { id, vm.Post.Slug }));
            }

            SetWhateverUserIsTrustedCommenter(vm);

            return(View("Details", vm));
        }
        public PostViewModelMapperProfile()
        {
            CreateMap <Post, PostViewModel.PostDetails>()
            .ForMember(x => x.Id, o => o.MapFrom(m => m.GetIdForUrl()))
            .ForMember(x => x.Slug, o => o.MapFrom(m => SlugConverter.TitleToSlug(m.Title)))
            .ForMember(x => x.PublishedAt, o => o.MapFrom(m => m.PublishAt))
            .ForMember(x => x.IsCommentAllowed, o => o.MapFrom(m => m.AllowComments))
            .ForMember(x => x.Title, o => o.MapFrom(m => HttpUtility.HtmlDecode(m.Title)))
            .ForMember(x => x.Author, o => o.Ignore())
            ;

            CreateMap <PostComments.Comment, PostViewModel.Comment>()
            .ForMember(x => x.Body, o => o.MapFrom(m => MarkdownResolver.Resolve(m.Body)))
            .ForMember(x => x.EmailHash, o => o.MapFrom(m => EmailHashResolver.Resolve(m.Email)))
            .ForMember(x => x.IsImportant, o => o.MapFrom(m => m.Important))
            .ForMember(x => x.Url, o => o.MapFrom(m => UrlResolver.Resolve(m.Url)))
            .ForMember(x => x.Tooltip, o => o.MapFrom(m => string.IsNullOrEmpty(m.Url) ? "Comment by " + m.Author : m.Url))
            .ForMember(x => x.CreatedAt, o => o.MapFrom(m => m.CreatedAt.ToUniversalTime().ToString("MM/dd/yyyy hh:mm tt")))
            ;

            CreateMap <Post, PostReference>()
            .ForMember(x => x.Title, o => o.MapFrom(m => HttpUtility.HtmlDecode(m.Title)))
            .ForMember(x => x.Slug, o => o.Ignore())
            ;

            CreateMap <Commenter, CommentInput>()
            .ForMember(x => x.Body, o => o.Ignore())
            .ForMember(x => x.CommenterKey, o => o.MapFrom(m => m.Key))
            ;

            CreateMap <CommentInput, Commenter>()
            .ForMember(x => x.Id, o => o.Ignore())
            .ForMember(x => x.IsTrustedCommenter, o => o.Ignore())
            .ForMember(x => x.Key, o => o.Ignore())
            .ForMember(x => x.OpenId, o => o.Ignore())
            .ForMember(x => x.NumberOfSpamComments, o => o.Ignore())
            ;

            CreateMap <User, CommentInput>()
            .ForMember(x => x.Name, o => o.MapFrom(m => m.FullName))
            .ForMember(x => x.Url, o => o.MapFrom(m => UrlHelper.RelativeToAbsolute(UrlHelper.RouteUrl("homepage"))))
            .ForMember(x => x.Body, o => o.Ignore())
            .ForMember(x => x.CommenterKey, o => o.Ignore())
            ;

            //CreateMap<UserProfile, CommentInput>()
            //    .ForMember(x => x.Name, o => o.MapFrom(m => m.FirstName + " " + m.LastName))
            //    .ForMember(x => x.Url, o => o.MapFrom(m => m.ProfileURL))
            //    .ForMember(x => x.Body, o => o.Ignore())
            //    .ForMember(x => x.CommenterKey, o => o.Ignore())
            //    ;

            CreateMap <HttpRequestWrapper, Tasks.AddCommentTask.RequestValues>();

            CreateMap <User, PostViewModel.UserDetails>();
        }
        protected override void Configure()
        {
            Mapper.CreateMap <Post, PostSummaryJson>()
            .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id)))
            .ForMember(x => x.Title, o => o.MapFrom(m => HttpUtility.HtmlDecode(m.Title)))
            .ForMember(x => x.Start, o => o.MapFrom(m => m.PublishAt.ToString("yyyy-MM-ddTHH:mm:ssZ")))
            .ForMember(x => x.Url, o => o.MapFrom(m => UrlHelper.Action("Details", "Posts", new { Id = RavenIdResolver.Resolve(m.Id), Slug = SlugConverter.TitleToSlug(m.Title) })))
            .ForMember(x => x.AllDay, o => o.UseValue(false))
            ;

            Mapper.CreateMap <Post, PostInput>()
            .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id)))
            .ForMember(x => x.Tags, o => o.MapFrom(m => TagsResolver.ResolveTags(m.Tags)))
            ;

            Mapper.CreateMap <PostInput, Post>()
            .ForMember(x => x.Id, o => o.Ignore())
            .ForMember(x => x.AuthorId, o => o.Ignore())
            .ForMember(x => x.LegacySlug, o => o.Ignore())
            .ForMember(x => x.ShowPostEvenIfPrivate, o => o.Ignore())
            .ForMember(x => x.SkipAutoReschedule, o => o.Ignore())
            .ForMember(x => x.IsDeleted, o => o.Ignore())
            .ForMember(x => x.CommentsCount, o => o.Ignore())
            .ForMember(x => x.CommentsId, o => o.Ignore())
            .ForMember(x => x.LastEditedByUserId, o => o.Ignore())
            .ForMember(x => x.LastEditedAt, o => o.Ignore())
            .ForMember(x => x.Tags, o => o.MapFrom(m => TagsResolver.ResolveTagsInput(m.Tags)))
            .ForMember(x => x.PublishAt, o => o.MapFrom(m => m.PublishAt.HasValue ? m.PublishAt.Value : DateTimeOffset.MinValue))
            ;

            Mapper.CreateMap <Post, AdminPostDetailsViewModel.PostDetails>()
            .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id)))
            .ForMember(x => x.Slug, o => o.MapFrom(m => SlugConverter.TitleToSlug(m.Title)))
            .ForMember(x => x.PublishedAt, o => o.MapFrom(m => m.PublishAt))
            .ForMember(x => x.Key, o => o.MapFrom(m => m.ShowPostEvenIfPrivate))
            ;

            Mapper.CreateMap <PostComments.Comment, AdminPostDetailsViewModel.Comment>()
            .ForMember(x => x.Body, o => o.MapFrom(m => MarkdownResolver.Resolve(m.Body)))
            .ForMember(x => x.EmailHash, o => o.MapFrom(m => EmailHashResolver.Resolve(m.Email)))
            .ForMember(x => x.IsImportant, o => o.MapFrom(m => m.Important))
            ;
        }
Пример #4
0
        protected override void Configure()
        {
            Mapper.CreateMap <Post, PostViewModel.PostDetails>()
            .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id)))
            .ForMember(x => x.Slug, o => o.MapFrom(m => SlugConverter.TitleToSlag(m.Title)))
            .ForMember(x => x.PublishedAt, o => o.MapFrom(m => m.PublishAt))
            .ForMember(x => x.IsCommentAllowed, o => o.MapFrom(m => m.AllowComments))
            .ForMember(x => x.Author, o => o.Ignore())
            .ForMember(x => x.Tags, o => o.MapFrom(m => m.Tags.Select(name => new TagDetails {
                Name = name
            })))
            ;

            Mapper.CreateMap <PostComments.Comment, PostViewModel.Comment>()
            .ForMember(x => x.Body, o => o.MapFrom(m => MarkdownResolver.Resolve(m.Body)))
            .ForMember(x => x.EmailHash, o => o.MapFrom(m => EmailHashResolver.Resolve(m.Email)))
            .ForMember(x => x.IsImportant, o => o.MapFrom(m => m.Important))
            .ForMember(x => x.Url, o => o.MapFrom(m => UrlResolver.Resolve(m.Url)))
            .ForMember(x => x.Tooltip, o => o.MapFrom(m => string.IsNullOrEmpty(m.Url) ? "Comment by " + m.Author : m.Url))
            .ForMember(x => x.CreatedAt, o => o.MapFrom(m => m.CreatedAt.ToString("MM/dd/yyyy hh:mm tt")))
            ;

            Mapper.CreateMap <Post, PostReference>()
            .ForMember(x => x.Slug, o => o.Ignore())
            ;

            Mapper.CreateMap <Commenter, CommentInput>()
            .ForMember(x => x.Body, o => o.Ignore())
            .ForMember(x => x.CommenterKey, o => o.MapFrom(m => m.Key))
            ;

            Mapper.CreateMap <User, CommentInput>()
            .ForMember(x => x.Name, o => o.MapFrom(m => m.FullName))
            .ForMember(x => x.Url, o => o.MapFrom(m => ConfigurationManager.AppSettings["MainUrl"] + UrlHelper.RouteUrl("Default")))
            .ForMember(x => x.Body, o => o.Ignore())
            .ForMember(x => x.CommenterKey, o => o.Ignore())
            ;

            Mapper.CreateMap <HttpRequestWrapper, RequestValues>();

            Mapper.CreateMap <User, PostViewModel.UserDetails>();
        }