private ActionResult ListView(int count, IList <Post> posts) { var summaries = posts.MapTo <PostsViewModel.PostSummary>(); foreach (var post in posts) { if (string.IsNullOrWhiteSpace(post.AuthorId)) { continue; } var author = RavenSession.Load <User>(post.AuthorId); if (author == null) { continue; } var postSummary = summaries.First(x => x.Id == RavenIdResolver.Resolve(post.Id)); postSummary.Author = author.MapTo <PostsViewModel.PostSummary.UserDetails>(); } return(View("List", new PostsViewModel { CurrentPage = CurrentPage, PostsCount = count, Posts = summaries })); }
protected override void Configure() { Mapper.CreateMap <Section, SectionDetails>() ; Mapper.CreateMap <Post, FuturePostViewModel>() .ForMember(x => x.Title, o => o.MapFrom(m => HttpUtility.HtmlDecode(m.Title))) ; Mapper.CreateMap <Posts_Statistics.ReduceResult, PostsStatisticsViewModel>() ; Mapper.CreateMap <Post, RecentCommentViewModel>() .ForMember(x => x.PostId, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id))) .ForMember(x => x.PostTitle, o => o.MapFrom(m => m.Title)) .ForMember(x => x.PostSlug, o => o.MapFrom(m => SlugConverter.TitleToSlug(m.Title))) .ForMember(x => x.Author, o => o.Ignore()) .ForMember(x => x.CommentId, o => o.Ignore()) .ForMember(x => x.ShortBody, o => o.Ignore()) ; Mapper.CreateMap <PostComments.Comment, RecentCommentViewModel>() .ForMember(x => x.PostId, o => o.Ignore()) .ForMember(x => x.ShortBody, o => o.MapFrom(x => MaxLength(x.Body, 128))) .ForMember(x => x.CommentId, o => o.MapFrom(x => x.Id)) .ForMember(x => x.PostSlug, o => o.Ignore()) .ForMember(x => x.PostTitle, o => o.Ignore()) ; }
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 })); }
public static string Url(Post post) { var slug = SlugConverter.TitleToSlug(post.Title); var id = RavenIdResolver.Resolve(post.Id); var blogUrl = ConfigurationHelper.MainBlogUrl.TrimEnd('/'); return($"{blogUrl}/{id}/{slug}"); }
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.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()) ; 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.ToUniversalTime().ToString("MM/dd/yyyy hh:mm tt"))) ; Mapper.CreateMap <Post, PostReference>() .ForMember(x => x.Title, o => o.MapFrom(m => HttpUtility.HtmlDecode(m.Title))) .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 <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()) ; Mapper.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()) ; //Mapper.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()) // ; Mapper.CreateMap <HttpRequestWrapper, Tasks.AddCommentTask.RequestValues>(); Mapper.CreateMap <User, PostViewModel.UserDetails>(); }
protected override void Configure() { Mapper.CreateMap <User, UserSummeryViewModel>() .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id))) ; Mapper.CreateMap <UserInput, User>() .ForMember(x => x.Id, o => o.Ignore()); Mapper.CreateMap <User, UserInput>() .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id))) ; }
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>(); }
protected override void Configure() { Mapper.CreateMap <Posts_Series.PostInformation, PostInSeries>() .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id))) .ForMember(x => x.PublishAt, o => o.MapFrom(m => m.PublishAt)) .ForMember(x => x.Slug, o => o.MapFrom(m => SlugConverter.TitleToSlug(m.Title))) .ForMember(x => x.Title, o => o.MapFrom(m => m.Title)) ; Mapper.CreateMap <Posts_Series.Result, SeriesInfo>() .ForMember(x => x.SeriesTitle, o => o.MapFrom(x => x.Series)) .ForMember(x => x.PostsInSeries, o => o.Ignore()) ; }
protected override void Configure() { Mapper.CreateMap <Section, SectionSummery>() .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id))) ; Mapper.CreateMap <Section, SectionInput>() .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id))) ; Mapper.CreateMap <SectionInput, Section>() .ForMember(x => x.Id, o => o.Ignore()) .ForMember(x => x.Position, o => o.Ignore()) ; }
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.TitleToSlug(m.Title))) .ForMember(x => x.Author, o => o.Ignore()) .ForMember(x => x.PublishedAt, o => o.MapFrom(m => m.PublishAt)) ; Mapper.CreateMap <User, PostsViewModel.PostSummary.UserDetails>(); Mapper.CreateMap <string, TagDetails>() .ForMember(x => x.Name, o => o.MapFrom(m => m)) ; }
private ActionResult ListView(int count, IList <Post> posts) { ViewBag.ChangeViewStyle = true; var summaries = posts.MapTo <PostsViewModel.PostSummary>(); var serieTitles = summaries .Select(x => TitleConverter.ToSeriesTitle(x.Title)) .Where(x => string.IsNullOrEmpty(x) == false) .Distinct() .ToList(); var series = RavenSession .Query <Posts_Series.Result, Posts_Series>() .Where(x => x.Series.In(serieTitles) && x.Count > 1) .ToList(); foreach (var post in posts) { var postSummary = summaries.First(x => x.Id == RavenIdResolver.Resolve(post.Id)); postSummary.IsSerie = series.Any(x => string.Equals(x.Series, TitleConverter.ToSeriesTitle(postSummary.Title), StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrWhiteSpace(post.AuthorId)) { continue; } var author = RavenSession.Load <User>(post.AuthorId); if (author == null) { continue; } postSummary.Author = author.MapTo <PostsViewModel.PostSummary.UserDetails>(); } return(View("List", new PostsViewModel { PageSize = BlogConfig.PostsOnPage, CurrentPage = CurrentPage, PostsCount = count, Posts = summaries })); }
public ActionResult ChangePass(int id) { var user = Session.Load <User>(id); if (user == null) { return(HttpNotFound("User does not exist.")); } return(View(new ChangePassViewModel { FullName = user.FullName, Input = new UserPasswordInput { Id = RavenIdResolver.Resolve(user.Id) } })); }
private void SendNewCommentEmail(Post post, PostComments.Comment comment) { var viewModel = comment.MapTo <NewCommentEmailViewModel>(); viewModel.PostId = RavenIdResolver.Resolve(post.Id); viewModel.PostTitle = post.Title; viewModel.BlogName = Session.Load <BlogConfig>("Blog/Config").Title; var subject = string.Format("Comment on: {0} from {1}", viewModel.PostTitle, viewModel.BlogName); if (comment.IsSpam) { subject = "Spam " + subject; } CommandExecutor.ExcuteLater(new SendEmailCommand(viewModel.Email, subject, "NewComment", viewModel)); }
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)); }
private ActionResult ListView(int count, IEnumerable <Post> posts) { var summaries = posts.MapTo <PostsViewModel.PostSummary>(); foreach (var post in posts) { var author = Session.Load <User>(post.AuthorId) .MapTo <PostsViewModel.PostSummary.UserDetails>(); var postSummary = summaries.First(x => x.Id == RavenIdResolver.Resolve(post.Id)); postSummary.Author = author; } return(View("List", new PostsViewModel { CurrentPage = CurrentPage, PostsCount = count, Posts = summaries })); }
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)) ; }
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>(); }
private IList <PostInSeries> GetPostsForCurrentSeries(Posts_Series.Result series) { IList <PostInSeries> postsInSeries = null; if (series != null) { postsInSeries = series .Posts .Select(s => new PostInSeries { Id = RavenIdResolver.Resolve(s.Id), Slug = SlugConverter.TitleToSlug(s.Title), Title = HttpUtility.HtmlDecode(TitleConverter.ToPostTitle(s.Title)), PublishAt = s.PublishAt }) .OrderByDescending(p => p.PublishAt) .ToList(); } return(postsInSeries); }
public virtual ActionResult CommentsRss(int?id) { RavenQueryStatistics stats = null; var commentsTuples = RavenSession.QueryForRecentComments(q => { if (id != null) { var postId = "posts/" + id; q = q.Where(x => x.PostId == postId); } return(q.Statistics(out stats).Take(30)); }); string responseETagHeader; if (CheckEtag(stats, out responseETagHeader)) { return(HttpNotModified()); } var rss = new XDocument( new XElement("rss", new XAttribute("version", "2.0"), new XElement("channel", new XElement("title", BlogConfig.Title), new XElement("link", Url.RelativeToAbsolute(Url.RouteUrl("homepage"))), new XElement("description", BlogConfig.MetaDescription ?? BlogConfig.Title), new XElement("copyright", String.Format("{0} (c) {1}", BlogConfig.Copyright, DateTime.Now.Year)), new XElement("ttl", "60"), from commentsTuple in commentsTuples let comment = commentsTuple.Item1 let post = commentsTuple.Item2 let link = Url.AbsoluteAction("Details", "PostDetails", new { Id = RavenIdResolver.Resolve(post.Id), Slug = SlugConverter.TitleToSlug(post.Title) }) + "#comment" + comment.Id select new XElement("item", new XElement("title", comment.Author + " commented on " + post.Title), new XElement("description", comment.Body), new XElement("link", link), new XElement("guid", link), new XElement("pubDate", comment.CreatedAt.ToString("R")) ) ) ) ); return(Xml(rss, responseETagHeader)); }
public ActionResult Rss(string tag, Guid key) { RavenQueryStatistics stats; var postsQuery = RavenSession.Query <Post>() .Statistics(out stats); if (key != Guid.Empty && key == BlogConfig.RssFuturePostsKey) { postsQuery = postsQuery.Where(x => x.PublishAt < DateTimeOffset.Now.AddDays(BlogConfig.RssFutureDaysAllowed).AsMinutes()); } else { postsQuery = postsQuery.Where(x => x.PublishAt < DateTimeOffset.Now.AsMinutes()); } if (string.IsNullOrWhiteSpace(tag) == false) { postsQuery = postsQuery.Where(x => x.TagsAsSlugs.Any(postTag => postTag == tag)); } var posts = postsQuery.OrderByDescending(x => x.PublishAt) .Take(20) .ToList(); string responseETagHeader; if (CheckEtag(stats, out responseETagHeader)) { return(HttpNotModified()); } var rss = new XDocument( new XElement("rss", new XAttribute("version", "2.0"), new XElement("channel", new XElement("title", BlogConfig.Title), new XElement("link", Url.RelativeToAbsolute(Url.RouteUrl("Default"))), new XElement("description", BlogConfig.MetaDescription ?? BlogConfig.Title), new XElement("copyright", String.Format("{0} (c) {1}", BlogConfig.Copyright, DateTime.Now.Year)), new XElement("ttl", "60"), from post in posts let postLink = Url.AbsoluteAction("Details", "PostDetails", new { Id = RavenIdResolver.Resolve(post.Id), Slug = SlugConverter.TitleToSlug(post.Title) }) select new XElement("item", new XElement("title", post.Title), new XElement("description", post.CompiledContent()), new XElement("link", postLink), new XElement("guid", postLink), new XElement("pubDate", post.PublishAt.ToString("R")) ) ) ) ); return(Xml(rss, responseETagHeader)); }