コード例 #1
0
        public async void GetQuestionList(int len, int amount, bool addon = false, string txt = null)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true; IsEmpty = false;
            try
            {
                string link = Keys.Url_Main + "item-question/get-question/" + Itemid;
                if (txt != null)
                {
                    link += "?Search=" + txt;
                }


                ObservableCollection <mQuestion> result = new ObservableCollection <mQuestion>();
                if (CrossConnectivity.Current.IsConnected)
                {
                    result = await QuestionService.Instance.FetchQuestions(link, len, amount);

                    if (result == null)
                    {
                        if (addon)
                        {
                            isDone = true;
                            return;
                        }
                        IsEmpty = true;
                        return;
                    }
                    OfflineService.Write <ObservableCollection <mQuestion> >(result, Strings.ItemQuestion_Offline_fileName, null);
                }
                else
                {
                    result = await OfflineService.Read <ObservableCollection <mQuestion> >(Strings.ItemQuestion_Offline_fileName, null);
                }


                if (result == null)
                {
                    if (addon)
                    {
                        isDone = true;
                        return;
                    }
                    IsEmpty = true;
                    return;
                }

                if (addon)
                {
                    Questionlist.AddRange(result);
                }
                else
                {
                    Questionlist = result;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(Keys.TAG + ex);
                DialogService.ShowError(Strings.SomethingWrong);
                Crashes.TrackError(ex);
                return;
            }
            finally { IsBusy = false; IsListRefereshing = false; }
        }