public async Task GetAllNewsShouldReturnList()
        {
            string userId = "Jack";
            var    actual = await newsRepository.GetAllNews(userId);

            Assert.Equal(2, actual.Count);
        }
        public async Task GetAllNewsShouldReturnList()
        {
            string userId = "Jack";
            var    actual = await repository.GetAllNews(userId);

            Assert.IsAssignableFrom <List <News> >(actual);
            Assert.Equal(3, actual.Count);
        }
Ejemplo n.º 3
0
        public IEnumerable <NewsItemDto> GetAllNews(int pageNumber, int pageSize, string urlStr)
        {
            var allNews = _newsRepository.GetAllNews(urlStr);
            var listSize = allNews.Count();
            int lowerBound = 0, range = 0;

            if (allNews != null && getCorrectRangeWithPaging(pageNumber, pageSize, listSize, ref lowerBound, ref range))
            {
                allNews = allNews.ToList().GetRange(lowerBound, range);
                return(allNews);
            }
            return(null);
        }
Ejemplo n.º 4
0
        public IEnumerable <NewsItemDto> GetAllNews()
        {
            var newsItems = _newsRepository.GetAllNews().ToList();

            newsItems.ForEach(ni =>
            {
                ni.Links.AddReference("self", $"/api/{ni.Id}");
                ni.Links.AddReference("edit", $"/api/{ni.Id}");
                ni.Links.AddReference("delete", $"/api/{ni.Id}");
                ni.Links.AddListReference("authors", _authorRepository.GetAuthorsByNewsId(ni.Id).Select(a => new { href = $"/api/authors/{a.Id}" }));
                ni.Links.AddListReference("categories", _categoryRepository.GetCategoriesByNewsId(ni.Id).Select(c => new { href = $"/api/categories/{c.Id}" }));
            });

            return(newsItems);
        }
Ejemplo n.º 5
0
        public List <NewsItemDto> GetAllNews()
        {
            var news = _newsRepo.GetAllNews();

            foreach (var n in news)
            {
                n.Links.AddReference("self", $"api/{n.Id}");
                n.Links.AddReference("edit", $"api/{n.Id}");
                n.Links.AddReference("delete", $"api/{n.Id}");
                n.Links.AddListReference("authors", _newsRepo.GetAuthorsByNewsItemId(n.Id)
                                         .Select(a => new { href = $"api/authors/{a.Id}" }));
                n.Links.AddListReference("categories", _newsRepo.GetCategoriesByNewsItemId(n.Id)
                                         .Select(c => new { href = $"api/categories/{c.Id}" }));
            }
            return(news);
        }
Ejemplo n.º 6
0
        public IEnumerable <NewsItemDto> GetAllNews(int pageSize, int pageNumber)
        {
            var news = _newsRepo.GetAllNews(pageSize, pageNumber).ToList();

            for (int i = 0; i < news.Count(); i++)
            {
                var obj = new { href = $"api/{news[i].Id}" };
                news[i].Links.AddReference("self", obj);
                news[i].Links.AddReference("edit", obj);
                news[i].Links.AddReference("delete", obj);

                var authorsObjectList = getAuthorsObjectByNewsId(news[i].Id);
                news[i].Links.AddListReference("authors", authorsObjectList);

                var categoriesObjectList = getCategoriesObjectByNewsId(news[i].Id);
                news[i].Links.AddListReference("categories", categoriesObjectList);
            }
            return(news);
        }
Ejemplo n.º 7
0
        public Envelope <NewsItemDto> GetAllNews(int pageSize, int pageNumber)
        {
            if (pageSize == 0)
            {
                pageSize = 25;
            }
            if (pageNumber == 0)
            {
                pageNumber = 1;
            }
            /*Total count of models in DataContext */
            decimal newsCount = _newsRepository.GetNewsItemCount();
            /*Calculating maximum pages */
            int maxPages = (int)(Math.Ceiling(newsCount / pageSize));
            /*Calculating how many models are in the beginning of the list before the ones we want */
            int pagesToSkip = (pageNumber - 1) * pageSize;

            /*Constructing the ModelDTO list of models */
            IEnumerable <NewsItemDto> newsItems = _newsRepository.GetAllNews(pageSize, pageNumber);

            /*Selecting the models to put in the envelope */
            var items = newsItems.Skip(pagesToSkip).Take(pageSize).ToList();

            foreach (var i in items)
            {
                AddReferenceLinks(i);
            }

            /*Constructing the envelope */
            var envelope = new Envelope <NewsItemDto>()
            {
                Items      = items,
                PageSize   = pageSize,
                PageNumber = pageNumber,
                MaxPages   = maxPages
            };

            return(envelope);
        }
Ejemplo n.º 8
0
        public ActionResult Index()
        {
            var news = repo.GetAllNews().OrderByDescending(x => x.DateCreated).Take(10);

            return(View(news));
        }
Ejemplo n.º 9
0
 public IEnumerable <NewsItemDto> GetAllNews()
 {
     return(_newsRepository.GetAllNews());
 }
        public ActionResult News()
        {
            var obj = _news.GetAllNews();

            return(View(obj));
        }
Ejemplo n.º 11
0
        public ActionResult Index()
        {
            var Model = repo.GetAllNews();

            return(View(Model));
        }
Ejemplo n.º 12
0
 public List<tb_News> GetAllNews()
 {
     _repository = new NewsRepository();
     return _repository.GetAllNews();
 }
Ejemplo n.º 13
0
        public List <News> GetNews()
        {
            var newsList = _newsRepository.GetAllNews();

            return(newsList);
        }
Ejemplo n.º 14
0
        public ActionResult Index()
        {
            var news = repo.GetAllNews();

            return(View(news));
        }
Ejemplo n.º 15
0
 public IActionResult NewsList()
 {
     return(View(NewsRepository.GetAllNews()));
 }