Exemple #1
0
        public List <SiteViewModel> GetSites()
        {
            var sites = new List <SiteViewModel>();
            IEnumerable <IGrouping <int, Article> > siteArticles;

            using (_context)
            {
                var userSitesIds = _userRepository.GetUserSitesIds();
                var showArticle  = _userRepository.GetUserViewSetting();
                var userId       = _userRepository.GetUserId();
                if (showArticle)
                {
                    siteArticles = _articleRepository.GetShowArticlesUser(userSitesIds, userId).ToList();
                }
                else
                {
                    siteArticles = _articleRepository.GetAllArticlesUser(userSitesIds, userId).ToList();
                }
                foreach (var site in siteArticles)
                {
                    var articles = new List <ArticleViewModel>();
                    var _site    = _articleRepository.GetPartArticlesSite(site, _partSize);
                    foreach (var article in _site)
                    {
                        articles.Add(
                            new ArticleViewModel
                        {
                            Link        = article.Url,
                            Title       = article.Title,
                            PartContent = article.PartContent,
                            FullContent = article.Content,
                            Id          = article.Id
                        });
                    }
                    sites.Add(
                        new SiteViewModel
                    {
                        Articles      = articles,
                        IdLastArticle = _articleRepository.GetLastId(site, _partSize),
                        NameSite      = _articleRepository.GetSiteName(site),
                        SiteId        = _articleRepository.GetSiteId(site)
                    });
                }
            }
            return(sites);
        }