コード例 #1
0
ファイル: UserController.cs プロジェクト: seoduda/Conarh_2016
        public void PostQuestion(EventData data, string question, Action onDone)
        {
            if (AppModel.Instance.CurrentUser == null)
            {
                AppProvider.PopUpFactory.ShowMessage(AppResources.LoginFirstMessage, AppResources.Warning);
                return;
            }

            UserDialogs.Instance.ShowLoading(AppResources.LoadingSendingQuestion);
            var questionData = new QuestionData
            {
                UserId   = AppModel.Instance.CurrentUser.User.Id,
                EventId  = data.Id,
                Question = question
            };
            var postQuestionTask = new PostDataBackgroundTask <QuestionData>(QueryBuilder.Instance.GetPostQuestionOnEventKinveyQuery(), questionData, true);

            postQuestionTask.ContinueWith((task, result) =>
            {
                UserDialogs.Instance.HideLoading();

                if (result == null)
                {
                    AppProvider.PopUpFactory.ShowMessage(AppResources.FailedServer, AppResources.Error);
                }
                else
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (onDone != null)
                        {
                            onDone.Invoke();
                        }
                        UserDialogs.Instance.ShowSuccess(AppResources.SuccessfulPostMessage, 2);
                    });
                }
            });
            _backgroundWorkers[AppBackgroundWorkerType.UserPostData].Add(postQuestionTask);
        }
コード例 #2
0
ファイル: UserController.cs プロジェクト: seoduda/Conarh_2016
        //public void CreateWallPost(string text, string imagePath, Action onDone)
        public void CreateWallPost(string text, string imagePath)
        {
            UserDialogs.Instance.ShowLoading(AppResources.LoadingSendingWallPost);
            var data = new CreateWallPostData {
                UserId = AppModel.Instance.CurrentUser.User.Id, Text = text
            };
            string query = QueryBuilder.Instance.GetWallPostskinveyQuery();

            var createWallPostTask = new PostDataBackgroundTask <CreateWallPostData>(query, data);

            createWallPostTask.ContinueWith((task, result) =>
            {
                if (result == null)
                {
                    UserDialogs.Instance.HideLoading();
                    AppProvider.PopUpFactory.ShowMessage(AppResources.FailedServer, AppResources.Error);
                }
                else
                {
                    if (string.IsNullOrEmpty(imagePath))
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            UserDialogs.Instance.ShowSuccess(AppResources.SuccessfulCreateWallPost, 1);
                            AppController.Instance.AppRootPage.Detail.Navigation.PopAsync();

                            AppController.Instance.DownloadWallData(null);
                        });

                        _backgroundWorkers[AppBackgroundWorkerType.UserPostData].Add(
                            new PostBadgeActionBackgroundTask(AppBadgeType.WallPost, AppModel.Instance.CurrentUser.User.Id, AppModel.Instance.CurrentUser.BadgeActions));
                    }
                    else
                    {
                        // var postImageToPost = new PostImageBackgroundTask(QueryBuilder.Instance.GetPostWallPostImageQuery(result.Id), imagePath);
                        var postImageToPost = new PostImageKinveyBackgroundTask(imagePath, result.Id, KinveyImageType.WallPost);

                        /*
                         * postImageToPost.Execute();
                         * UserDialogs.Instance.ShowSuccess(AppResources.SuccessfulCreateWallPost, 1);
                         * AppController.Instance.AppRootPage.Detail.Navigation.PopAsync();//
                         *
                         * AppController.Instance.DownloadWallData(null);
                         * AppController.Instance.AppRootPage.Detail.Navigation.PopAsync();
                         */

                        postImageToPost.ContinueWith((pItask, pIresult) =>
                        {
                            if (pIresult == null)
                            {
                                UserDialogs.Instance.HideLoading();
                                AppProvider.PopUpFactory.ShowMessage(AppResources.FailedServer, AppResources.Error);
                            }
                            else
                            {
                                _backgroundWorkers[AppBackgroundWorkerType.UserPostData].Add(
                                    new PostBadgeActionBackgroundTask(AppBadgeType.WallPost, AppModel.Instance.CurrentUser.User.Id, AppModel.Instance.CurrentUser.BadgeActions));

                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    UserDialogs.Instance.ShowSuccess(AppResources.SuccessfulCreateWallPost, 1);
                                    AppController.Instance.AppRootPage.Detail.Navigation.PopAsync();

                                    AppController.Instance.DownloadWallData(null);
                                });
                            }
                        });
                        _backgroundWorkers[AppBackgroundWorkerType.UserPostData].Add(postImageToPost);
                    }
                }
            });
            _backgroundWorkers[AppBackgroundWorkerType.UserPostData].Add(createWallPostTask);
        }