protected override void Configure()
        {
            Mapper.CreateMap <Post, PostsViewModel.PostSummary>()
            .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.Tags, o => o.MapFrom(m => m.Tags.Select(name => new TagDetails {
                Name = name
            })))
            ;

            Mapper.CreateMap <User, PostsViewModel.PostSummary.UserDetails>();
        }
Example #2
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>();
        }
Example #3
0
        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 => 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", "PostAdmin", new { Id = RavenIdResolver.Resolve(m.Id), Slug = SlugConverter.TitleToSlag(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)))
            ;

            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.TitleToSlag(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))
            ;
        }
Example #4
0
        Post IMetaWeblog.GetPost(string postid, string username, string password)
        {
            ValidateUser(username, password);
            var thePost = session.Load <Models.Post>(postid);

            if (thePost.IsDeleted)
            {
                throw new InvalidOperationException("You cannot get deleted post");
            }

            return(new Post
            {
                wp_slug = SlugConverter.TitleToSlag(thePost.Title),
                description = thePost.Body,
                dateCreated = thePost.PublishAt.DateTime,
                categories = thePost.Tags.ToArray(),
                title = thePost.Title,
                postid = thePost.Id,
            });
        }
Example #5
0
        Post[] IMetaWeblog.GetRecentPosts(string blogid, string username, string password,
                                          int numberOfPosts)
        {
            ValidateUser(username, password);

            var list = session.Query <Models.Post>()
                       .Where(p => p.IsDeleted == false)
                       .OrderByDescending(x => x.PublishAt)
                       .Take(numberOfPosts)
                       .ToList();

            return(list.Select(thePost => new Post
            {
                wp_slug = SlugConverter.TitleToSlag(thePost.Title),
                description = thePost.Body,
                dateCreated = thePost.PublishAt.DateTime,
                categories = thePost.Tags.ToArray(),
                title = thePost.Title,
                postid = thePost.Id,
            }).ToArray());
        }
        public ActionResult CommentsAdmin(int id, CommentCommandOptions command, int[] commentIds)
        {
            if (commentIds.Length < 1)
            {
                ModelState.AddModelError("CommentIdsAreEmpty", "Not comments was selected.");
            }

            var post = Session.Load <Post>(id);

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

            var slug = SlugConverter.TitleToSlag(post.Title);

            if (ModelState.IsValid == false)
            {
                if (Request.IsAjaxRequest())
                {
                    return(Json(new { Success = false, message = ModelState.GetFirstErrorMessage() }));
                }

                return(Details(id, slug));
            }

            var comments      = Session.Load <PostComments>(id);
            var requestValues = Request.MapTo <RequestValues>();

            switch (command)
            {
            case CommentCommandOptions.Delete:
                comments.Comments.RemoveAll(c => commentIds.Contains(c.Id));
                comments.Spam.RemoveAll(c => commentIds.Contains(c.Id));
                break;

            case CommentCommandOptions.MarkSpam:
                var spams = comments.Comments
                            .Where(c => commentIds.Contains(c.Id))
                            .ToArray();

                comments.Comments.RemoveAll(spams.Contains);
                comments.Spam.RemoveAll(spams.Contains);
                foreach (var comment in spams)
                {
                    new AskimetService(Session).MarkSpam(comment);
                }
                break;

            case CommentCommandOptions.MarkHam:
                var ham = comments.Spam
                          .Where(c => commentIds.Contains(c.Id))
                          .ToArray();

                comments.Spam.RemoveAll(ham.Contains);
                foreach (var comment in ham)
                {
                    comment.IsSpam = false;
                    new AskimetService(Session).MarkHam(comment);
                }
                comments.Comments.AddRange(ham);
                break;

            default:
                throw new InvalidOperationException(command + " command is not recognized.");
            }

            if (Request.IsAjaxRequest())
            {
                return(Json(new { Success = true }));
            }
            return(RedirectToAction("Details", new { id, slug }));
        }
Example #7
0
 private string C(string title)
 {
     return(SlugConverter.TitleToSlag(title));
 }