コード例 #1
0
ファイル: ViewService.cs プロジェクト: prolearner18/Tcust
        public PostViewModel MapPostViewModel(Post post, bool allMedias = false)
        {
            var model = new PostViewModel();

            model.id         = post.Id;
            model.title      = post.Title;
            model.termNumber = post.TermNumber;
            model.number     = post.Number;
            model.author     = post.Author;
            model.content    = post.Content;
            model.reviewed   = post.Reviewed;
            model.date       = post.Date.ToShortDateString();
            model.createdAt  = post.CreatedAt;

            model.url = String.Format("{0}/posts/{1}?title={2}", settings.Value.Url, post.Id, post.Title);

            if (String.IsNullOrEmpty(post.Summary))
            {
                model.summary = PostViewModel.GetDefaultSummary(post);
            }
            else
            {
                model.summary = post.Summary;
            }

            if (allMedias)
            {
                model.medias = new List <MediaViewModel>();
                foreach (var media in post.Attachments.OrderByDescending(a => a.Order))
                {
                    model.medias.Add(MapMediaViewModel(media));
                }
            }
            else
            {
                if (post.TopFile != null)
                {
                    model.cover = MapMediaViewModel(post.TopFile);
                }
            }



            return(model);
        }