Ejemplo n.º 1
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);
        }