コード例 #1
0
 /// <summary>
 /// The map from.
 /// </summary>
 /// <param name="blog">
 /// The blog containing the blog posts.
 /// </param>
 /// <param name="archiveMonth">
 /// The archive month.
 /// </param>
 /// <returns>
 /// The collection of months with archived blog posts.
 /// </returns>
 public ArchiveMonthViewModel MapFrom(Blog blog, int archiveMonth)
 {
     return new ArchiveMonthViewModel
         {
             Value = archiveMonth, Name = new DateTime(1999, archiveMonth, 1).ToString("MMMM") 
         };
 }
コード例 #2
0
        /// <summary>
        /// The map from.
        /// </summary>
        /// <param name="blog">
        /// The blog to map from.
        /// </param>
        /// <param name="archiveYear">
        /// The the archived post year.
        /// </param>
        /// <returns>
        /// The mappped arcihve year view model.
        /// </returns>
        public ArchiveYearViewModel MapFrom(Blog blog, int archiveYear)
        {
            var blogPosts = blog.BlogPosts.Where(x => x.PostDate.Year == archiveYear);

            var archiveMonthsValues = GetArchiveMonthsValues(blogPosts);

            if (archiveMonthsValues.Count == 0)
            {
                return null;
            }

            var archiveMonths = archiveMonthsValues.Select(x => this.archiveMonthsViewModelMapper.MapFrom(blog, x));

            return new ArchiveYearViewModel
                {
                    BlogUrl = blog.Url, ArchiveYear = archiveYear, ArchiveMonths = archiveMonths 
                };
        }