Exemple #1
0
        public async Task <List <NewsItemSource> > GetNews(FilterNewsDto filterNewsDto)
        {
            List <ContentDto> news = (await _oDataClient.For <ContentDto>("Contents")
                                      .Action("GetNews")
                                      .Set(filterNewsDto)
                                      .ExecuteAsEnumerableAsync()).ToList();

            List <NewsItemSource> newsItemSources = new List <NewsItemSource>();

            foreach (ContentDto item in news)
            {
                newsItemSources.Add(new NewsItemSource
                {
                    Date     = item.Date,
                    Text     = StripHTML(item.Text),
                    Id       = item.Id,
                    Image    = ImageSource.FromUri(new System.Uri(item.Photo)),
                    NewsID   = item.NewsID,
                    Photo    = item.Photo,
                    Likes    = item.Likes,
                    Visits   = item.Visits,
                    Title    = item.Title,
                    YourLike = item.YourLike
                });
            }

            return(newsItemSources);
        }
Exemple #2
0
        public async Task <IEnumerable <ContentDto> > GetNews(FilterNewsDto filterNewsDto)
        {
            if (httpClient == null)
            {
                httpClient = HttpClientFactory.CreateClient("SoltaniHttpClient");
            }

            filterNewsDto.Page = 1;

            string json = JsonConvert.SerializeObject(filterNewsDto, Formatting.None,
                                                      new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            HttpResponseMessage result = await httpClient.PostAsync("GetNewsList", new StringContent(json, UnicodeEncoding.UTF8, "application/json"));

            if (result.IsSuccessStatusCode)
            {
                NewsList newsList = JsonConvert.DeserializeObject <NewsList>(await result.Content.ReadAsStringAsync());

                return(newsList.Items);
            }
            else
            {
                throw new Exception(result.ReasonPhrase);
            }
        }
Exemple #3
0
        public ContentListViewModel(IODataClient oDataClient, IUserDialogs userDialogs, INewsService newsService, IInitialDataService initialDataService, IEventAggregator eventAggregator, IPageDialogService dialogService)
        {
            _oDataClient        = oDataClient;
            _userDialogs        = userDialogs;
            _newsService        = newsService;
            _initialDataService = initialDataService;

            ShowContent = new BitDelegateCommand <NewsItemSource>(async(content) =>
            {
                INavigationParameters parameters = new NavigationParameters();
                parameters.Add("NewsId", content.NewsID);

                await NavigationService.NavigateAsync(nameof(ShowContentView), parameters);
            });

            FilterContent = new BitDelegateCommand(async() =>
            {
                FilterDto.Month = SelectedMonth?.Number;
                FilterDto.Year  = SelectedYear?.Number;

                if (FilterDto.Month != null || FilterDto.Year != null)
                {
                    if (FilterDto.Month == null || FilterDto.Year == null)
                    {
                        await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.NewsFilterNotValid, ConstantStrings.Ok);

                        SelectedYear  = null;
                        SelectedMonth = null;

                        return;
                    }
                }

                contentCancellationTokenSource?.Cancel();
                contentCancellationTokenSource = new CancellationTokenSource();
                using (_userDialogs.Loading(ConstantStrings.Loading, cancelText: ConstantStrings.Loading_Cancel, onCancel: contentCancellationTokenSource.Cancel))
                {
                    await loadContents(FilterDto);
                }

                eventAggregator.GetEvent <OpenNewsFilterPopupEvent>().Publish(new OpenNewsFilterPopupEvent());

                FilterDto     = new FilterNewsDto();
                SelectedYear  = null;
                SelectedMonth = null;
            });

            OpenFilterPopup = new BitDelegateCommand(async() =>
            {
                eventAggregator.GetEvent <OpenNewsFilterPopupEvent>().Publish(new OpenNewsFilterPopupEvent());
            });
        }
Exemple #4
0
        public async Task loadContents(FilterNewsDto filterNewsDto)
        {
            if (SelectedMonth != null)
            {
                filterNewsDto.Month = SelectedMonth.Number;
            }

            if (SelectedYear != null)
            {
                filterNewsDto.Year = SelectedYear.Number;
            }

            List <NewsItemSource> contents = await _newsService.GetNews(filterNewsDto);

            if (contents != null)
            {
                Contents = new ObservableCollection <NewsItemSource>(contents);
            }
        }
Exemple #5
0
 public async Task <IEnumerable <ContentDto> > GetNews([FromBody] FilterNewsDto filterNewsDto)
 {
     return(await ExternalApiService.GetNews(filterNewsDto));
 }