Example #1
0
        public override CreateUserData Execute()
        {
            try
            {
                if (IsCreateNew)
                {
                    Data.ScorePoints = 0;
                }
                string imagePath = " ";
                if (Data.ProfileImage != null && !Data.ProfileImage.ToLower().StartsWith("http"))
                {
                    imagePath         = Data.ProfileImage;
                    Data.ProfileImage = null;
                }

                string serializedData = JsonConvert.SerializeObject(Data);

                string userId = UserId;

                if (IsCreateNew)
                {
                    //	var result = WebClient.PostStringAsync(QueryBuilder.Instance.GetUsersQuery (), serializedData).Result;
                    var result = KinveyWebClient.PostSignUpStringAsync(QueryBuilder.Instance.GetUsersKinveyQuery(), serializedData).Result;

                    UniqueItem uniqueItemId = JsonConvert.DeserializeObject <UniqueItem>(result);
                    userId = uniqueItemId.Id;
                }
                else
                {
                    if (!Data.IsEmpty())
                    {
                        AppProvider.Log.WriteLine(LogChannel.All, QueryBuilder.Instance.GetPostUserProfileChangesKinveyQuery(UserId) + " : " + serializedData);
                        var update = KinveyWebClient.PutStringAsync(QueryBuilder.Instance.GetPostUserProfileChangesKinveyQuery(UserId), serializedData).Result;
                    }
                }

                if (!string.IsNullOrEmpty(imagePath.Trim()))
                {
                    var postImageToPost = new PostImageKinveyBackgroundTask(imagePath, userId, KinveyImageType.User);

                    postImageToPost.Execute();
                    //Data.ProfileImage = postImageToPost.Execute();

                    //var response = WebClient.PutBytesAsync(QueryBuilder.Instance.GetUploadUserImageQuery (userId), imageContent).Result;
                }

                return(Data);
            }
            catch (Exception ex)
            {
                AppProvider.Log.WriteLine(LogChannel.Exception, ex);
                Exception = ex;
            }

            return(null);
        }
Example #2
0
        //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);
        }