Пример #1
0
 public ArticleViewModel(ViewArticleModelContainer modelContainer, bool previewMode)
 {
     Article                 = modelContainer.Article;
     AuthorProfile           = modelContainer.AuthorProfile;
     Tags                    = modelContainer.Tags;
     Comments                = modelContainer.Comments ?? new List <CommentInfoPM>();
     RelatedArticles         = modelContainer.RelatedArticles ?? new List <ContentInfo4PM>();
     UserRelatedArticles     = modelContainer.UserRelatedArticles ?? new List <ContentInfo4PM>();
     TopArticles             = modelContainer.TopArticles ?? new List <ContentInfo4PM>();
     PreviewMode             = previewMode;
     AuthorBusinessIntroduce = modelContainer.AuthorBusinessIntroduce;
     TotalVisits             = modelContainer.TotalVisits;
 }
Пример #2
0
        public ViewArticleModelContainer ReadArticleForViewByVisitor(int contentId)
        {
            var content = ArticleBiz.ReadArticleForViewByVisitor(contentId);

            VisitBiz.IncrementContentVisits(contentId);
            UnitOfWork.SaveChanges();
            int totalVisits = 0;

            try
            {
                totalVisits = VisitBiz.Read(e => e.ContentId == contentId).Sum(e => e.Count);
            }
            catch (InvalidOperationException ex)
            {
            }

            var result = new ViewArticleModelContainer()
            {
                Article       = content.GetContentForViewByVisitorPM(),
                Tags          = content.Tags.Select(tag => tag.GetPresentationModel()).ToList(),
                AuthorProfile = new ProfileForViewByVisitorPM()
                {
                    AboutMe = content.Author.ProfileKeyValues.SingleOrDefault(profileKeyValye =>
                                                                              profileKeyValye.Type == ProfileKeyValueType.AboutMe)?.Value
                },
                AuthorBusinessIntroduce = new BusinessIntroducePM()
                {
                    Text = content.Author.ProfileKeyValues.SingleOrDefault(profileKeyValye =>
                                                                           profileKeyValye.Type == ProfileKeyValueType.UserBusinessIntroduceText)?.Value
                },
                Comments            = CommentBiz.GetArticleComments(content.Id).MapTo <CommentInfoPM>().ToList(),
                UserRelatedArticles = ArticleBiz.ReadUserRelatedArticles(content.AuthorId, contentId, 10)
                                      .MapTo <ContentInfo4PM>()
                                      .ToList(),
                RelatedArticles = ArticleBiz.ReadRelatedArticles(content.AuthorId, contentId, 10)
                                  .MapTo <ContentInfo4PM>()
                                  .ToList(),
                TotalVisits = VisitBiz.Read(e => e.ContentId == contentId).Sum(e => e.Count)
            };

            if (result.UserRelatedArticles.Count == 0 && result.RelatedArticles.Count == 0)
            {
                result.TopArticles = ArticleBiz.ReadTopArticles(10)
                                     .MapTo <ContentInfo4PM>()
                                     .ToList();
            }
            return(result);
        }