public async Task <IHttpActionResult> GetMovieNews()
        {
            var result = await _movieListService.GetMovieNewsAsync();

            NewsListVM newsListVM = Mapper.Map <NewsListVM>(result);

            return(Ok(newsListVM));
        }
Пример #2
0
        public async Task <NewsListVM> GetAll()
        {
            var news = new NewsListVM
            {
                NewsList = await _newsRepository.GetAll()
            };

            return(news);
        }
Пример #3
0
 public async Task <NewsListVM> GetLimitAll(int countEntity, int page)
 {
     if (countEntity <= 0 || page <= 0)
     {
         NewsListVM listEmpty = new NewsListVM();
         return(listEmpty);
     }
     else
     {
         return(await _newsStorage.GetLimitAll(countEntity, page));
     }
 }
Пример #4
0
        public async Task <NewsListVM> GetAll(int count, int page)
        {
            var countEntity = await _newsRepository.Count();

            var news = new NewsListVM
            {
                CountPage = countEntity % count == 0 ? countEntity / count : (countEntity / count) + 1,
                NewsList  = await _newsRepository.GetAll(count, page)
            };

            return(news);
        }
Пример #5
0
        public async Task <NewsListVM> GetAll([FromRoute] int count, [FromRoute] int page)
        {
            NewsListVM news = null;

            if (Request.HttpContext.User.IsInRole("user"))
            {
                news = await _newsBuilder.GetAll(count, page);
            }
            else
            {
                news = await _newsBuilder.GetLimitAll(count, page);
            }
            return(news);
        }
Пример #6
0
        /// <summary>
        /// Index view to display the news.
        /// Provides a profile manage view model
        /// with important information about a user
        /// so that their settings can be used to
        /// filter the news sources selected
        /// </summary>
        /// <returns>View</returns>
        public IActionResult Index()
        {
            // Find the user
            var user = _userSettingRepo.Read(User.Identity.Name);

            // When the user is not found
            if (user == null)
            {
                return(LocalRedirect("/Identity/Account/Register"));
            }
            else
            {
                // Create a dictionary with a key that has several attributes
                var categorySources = new Dictionary <string, List <string> >();

                // Iterate over each category
                foreach (var category in user.UserSettingNewsCategories)
                {
                    // Set the source list
                    var sourceList = new List <string>();
                    // Iterate over each source
                    foreach (var source in category.NewsSources.Select(s => s.SourceId))
                    {
                        // Add the source associated with the category to the source list
                        sourceList.Add(source);
                    }

                    // When a category at least has 1 source
                    if (sourceList.Count() > 0)
                    {
                        // Add the category and it's sources to the category source list
                        categorySources.Add(category.NewsCategory.Name, sourceList);
                    }
                }

                // Instantiate a new news list view model
                NewsListVM listVM = new NewsListVM
                {
                    UserSettingNewsCategories = user.UserSettingNewsCategories,
                    Country         = user.Country,
                    CategorySources = JsonConvert.SerializeObject(categorySources)
                };
                return(View(listVM));
            }
        }