public async Task <IActionResult> Index(string country = "bg", int currPage = 1)
        {
            try
            {
                var topNewsViewModel = new TopNewsViewModel();
                var list             = await GetNews.TopNews(country.ToLower());

                topNewsViewModel.Articles      = list.Skip((currPage - 1) * 3).Take(3);
                topNewsViewModel.Country       = country.ToLower();
                topNewsViewModel.CurrentPage   = currPage;
                topNewsViewModel.TotalNumPages = Calculations.TotalNumPages(list.Count());

                return(View(topNewsViewModel));
            }
            catch (InvalidOperationException)
            {
                return(RedirectToAction("Error", $"Error", new { statusCode = "404", message = "Specified Country was not found!" }));
            }
            catch (ArgumentNullException)
            {
                return(RedirectToAction("Error", "Error", new { statusCode = "503", message = "Server unavailable!" }));
            }
            catch (Exception)
            {
                return(RedirectToAction("Error", "Error", new { statusCode = "400", message = "Something went wrong!" }));
            }
        }
Пример #2
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     TopNewsModel = NavigationServices.CurrentViewModel as TopNewsViewModel;
     if (e.NavigationMode == NavigationMode.New && NavigationContext.QueryString.ContainsKey("id"))
     {
         string id = NavigationContext.QueryString["id"];
         if (!String.IsNullOrEmpty(id))
         {
             _isDeepLink = true;
             TopNewsModel = new TopNewsViewModel();
             NavigationServices.CurrentViewModel = TopNewsModel;
             TopNewsModel.LoadItem(id);
         }
     }
     if (TopNewsModel != null)
     {
         TopNewsModel.ViewType = ViewTypes.Detail;
     }
     DataContext = TopNewsModel;
     base.OnNavigatedTo(e);
 }