示例#1
0
        private void AcceptCommonRequest(ConnectionModel connectionModel)
        {
            UserDialogs.Instance.ShowLoading(AppResources.LoadingSendingAcceptRequest);

            /* Todo validar
             * var data = new RequestConnectionData(connectionModel.Request.Requester.Id,
             *  connectionModel.Request.Responder.Id,
             *  AppResources.GetPointsEarned(connectionModel.Request.Responder.UserType),
             *  true);
             */
            var data = new RequestConnectionData(connectionModel.Request.RequesterId,
                                                 connectionModel.Request.ResponderId,
                                                 AppResources.GetPointsEarned(AppModel.Instance.Users.Find(connectionModel.Request.ResponderId).UserType),
                                                 true);

            data.ConnectionRequestId = connectionModel.Request.Id;

            var requestTask = new RequestConnectionBackgroundTask(data, true, connectionModel.Request.Id);

            requestTask.ContinueWith((task, result) =>
            {
                if (result == null)
                {
                    UserDialogs.Instance.HideLoading();
                    AppProvider.PopUpFactory.ShowMessage(AppResources.FailedServer, AppResources.Error);
                }
                else
                {
                    var postBadgeTask = new PostBadgeActionBackgroundTask(AppBadgeType.ConnectTo50Users, AppModel.Instance.CurrentUser.User.Id, AppModel.Instance.CurrentUser.BadgeActions);
                    postBadgeTask.ContinueWith((badgeTask, badgeResult) =>
                    {
                        string query       = QueryBuilder.Instance.GetConnectionRequestByIdKinveyQuery(connectionModel.Request.Id);
                        var getRequestTask = new GetItemByIdBackgroundTask <ConnectRequest>(query, connectionModel.UserModel.Connections);

                        getRequestTask.ContinueWith((getTask, getResult) =>
                        {
                            UserDialogs.Instance.HideLoading();
                            if (getResult != null)
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    if (Device.OS == TargetPlatform.iOS)
                                    {
                                        UserDialogs.Instance.ShowSuccess(AppResources.SuccessfulAcceptRequestConnection, 1);
                                    }
                                    connectionModel.ApplyConnectRequest(getResult);
                                    UpdateProfileData(AppModel.Instance.CurrentUser);
                                });
                            }
                        });

                        _backgroundWorkers[AppBackgroundWorkerType.UserPostData].Add(getRequestTask);
                    });

                    _backgroundWorkers[AppBackgroundWorkerType.UserPostData].Add(postBadgeTask);
                    _backgroundWorkers[AppBackgroundWorkerType.UserPostData].Add(new PostBadgeActionBackgroundTask(AppBadgeType.ConnectTo50Users, connectionModel.UserModel.User.Id, null));
                }
            });
            _backgroundWorkers[AppBackgroundWorkerType.UserPostData].Add(requestTask);
        }
示例#2
0
        private void SentCommonRequest(ConnectionModel connectionModel)
        {
            UserDialogs.Instance.ShowLoading(AppResources.LoadingSendingRequest);

            string currentUserId   = AppModel.Instance.CurrentUser.User.Id;
            string requestedUserId = connectionModel.UserModel.User.Id;

            var checkIsCurrentUserSendRequest = new DownloadConnectRequestDataByUserBackgroundTask(AppModel.Instance.CurrentUser.Connections,
                                                                                                   QueryBuilder.Instance.GetConnectRequestByUsersKimveyQuery(currentUserId, requestedUserId));

            checkIsCurrentUserSendRequest.ContinueWith((task, result) =>
            {
                if (result == null || result.Count > 0)
                {
                    Device.BeginInvokeOnMainThread(() => connectionModel.ApplyConnectRequest(result[0]));
                    UserDialogs.Instance.HideLoading();
                    AppProvider.PopUpFactory.ShowMessage(AppResources.AlreadySentRequestError, AppResources.Error);
                }
                else
                {
                    if (result.Count == 0)
                    {
                        var checkIsUserSendRequestToCurrentUser = new DownloadConnectRequestDataByUserBackgroundTask(AppModel.Instance.CurrentUser.Connections,
                                                                                                                     QueryBuilder.Instance.GetConnectRequestByUsersKimveyQuery(requestedUserId, currentUserId));

                        checkIsUserSendRequestToCurrentUser.ContinueWith((rtask, rresult) =>
                        {
                            if (rtask == null || rresult.Count > 0)
                            {
                                Device.BeginInvokeOnMainThread(() => connectionModel.ApplyConnectRequest(rresult[0]));
                                UserDialogs.Instance.HideLoading();
                                AppProvider.PopUpFactory.ShowMessage(AppResources.AlreadySentRequestToError, AppResources.Error);
                            }
                            else if (rresult.Count == 0)
                            {
                                var data = new RequestConnectionData(AppModel.Instance.CurrentUser.User.Id, connectionModel.UserModel.User.Id);

                                var requestTask = new RequestConnectionBackgroundTask(data, false, null);
                                requestTask.ContinueWith((retask, reresult) =>
                                {
                                    if (reresult == null)
                                    {
                                        UserDialogs.Instance.HideLoading();
                                        AppProvider.PopUpFactory.ShowMessage(AppResources.FailedServer, AppResources.Error);
                                    }
                                    else
                                    {
                                        string query       = QueryBuilder.Instance.GetConnectionRequestByIdKinveyQuery(reresult.Id);
                                        var getRequestTask = new GetItemByIdBackgroundTask <ConnectRequest>(query, connectionModel.UserModel.Connections);

                                        getRequestTask.ContinueWith((getTask, getResult) =>
                                        {
                                            UserDialogs.Instance.HideLoading();
                                            if (getResult != null)
                                            {
                                                Device.BeginInvokeOnMainThread(() =>
                                                {
                                                    UserDialogs.Instance.ShowSuccess(AppResources.SuccessfulRequestConnection, 1);
                                                    connectionModel.ApplyConnectRequest(getResult);
                                                });
                                            }
                                        });

                                        _backgroundWorkers[AppBackgroundWorkerType.UserPostData].Add(getRequestTask);
                                    }
                                });
                                _backgroundWorkers[AppBackgroundWorkerType.UserPostData].Add(requestTask);
                            }
                        });

                        _backgroundWorkers[AppBackgroundWorkerType.UserPostData].Add(checkIsUserSendRequestToCurrentUser);
                    }
                }
            });

            _backgroundWorkers[AppBackgroundWorkerType.UserPostData].Add(checkIsCurrentUserSendRequest);
        }