Exemple #1
0
        //public IEnumerable<ITopNews> Select20TopNews(int topNumber)
        //{
        //    var top20 = TopNewsDB.Instance.Select20TopNews();

        //    return (top20.ToList().FindAll(v => !string.IsNullOrEmpty(v.ImageUrl))).Take(topNumber);
        //}

        public IEnumerable <ITopNews> SelectFirst10TopNews()
        {
            try
            {
                int             newsCount  = 10;
                int             remainNews = newsCount;
                List <ITopNews> newsList   = new List <ITopNews>();
                var             top20      = new TopNewsDB().Select20TopNews();
                if (top20 != null)
                {
                    newsList.AddRange(top20.OrderByDescending(v => v.DttmCreated).Take(newsCount).ToList());
                }

                if (newsList.Count < newsCount)
                {
                    remainNews = remainNews - newsList.Count;
                    if (remainNews > 0)
                    {
                        var topRssNews = new RssProviderService().GetFirstTopNews();
                        if (topRssNews != null && topRssNews.Count() > 0)
                        {
                            int newsCounter = 0;
                            foreach (var val in topRssNews.OrderByDescending(v => v.DttmCreated))
                            {
                                if (newsCounter++ >= remainNews)
                                {
                                    break;
                                }

                                val.IsRss = true;
                                newsList.Add(val);
                            }
                        }
                    }
                }

                return(newsList.Take(newsCount));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //public IEnumerable<ITopNews> Select20TopNews(int topNumber)
        //{
        //    var top20 = TopNewsDB.Instance.Select20TopNews();

        //    return (top20.ToList().FindAll(v => !string.IsNullOrEmpty(v.ImageUrl))).Take(topNumber);
        //}

        public IEnumerable<ITopNews> SelectFirst10TopNews()
        {           
            try
            {
                int newsCount = 10;
                int remainNews = newsCount;
                List<ITopNews> newsList = new List<ITopNews>();
                var top20 = new TopNewsDB().Select20TopNews();
                if (top20 != null)
                {
                    newsList.AddRange(top20.OrderByDescending(v => v.DttmCreated).Take(newsCount).ToList());
                }
                
                if (newsList.Count < newsCount)
                {
                    remainNews = remainNews - newsList.Count;
                    if (remainNews > 0)
                    {
                        var topRssNews = new RssProviderService().GetFirstTopNews();
                        if (topRssNews != null && topRssNews.Count() > 0)
                        {
                            int newsCounter = 0;
                            foreach (var val in topRssNews.OrderByDescending(v => v.DttmCreated))
                            {
                                if (newsCounter++ >= remainNews)
                                    break;

                                val.IsRss = true;
                                newsList.Add(val);
                            }
                        }
                    }
                }

                return newsList.Take(newsCount);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }