예제 #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
        public Dictionary <string, bool> GetBadgesStates(List <BadgeAction> badgesUserResult)
        {
            var result = new Dictionary <string, bool>();

            foreach (BadgeType badgeType in AppModel.Instance.BadgeTypes.Items)
            {
                bool isEnabled             = false;
                List <BadgeAction> actions = badgesUserResult.FindAll(temp => temp.Id.Equals(badgeType.Id));
                isEnabled = AppResources.IsBadgeEnabled(badgeType.Id, actions.Count);
                result.Add(badgeType.Id, isEnabled);
            }

            return(result);
        }
예제 #3
0
 public void TryToConnect(ConnectionModel connectionModel)
 {
     if (AppResources.IsUserCommon(connectionModel.UserModel.User.UserType))
     {
         if (connectionModel.State == ConnectState.RequestNotSent)
         {
             SentCommonRequest(connectionModel);
         }
         else if (connectionModel.State == ConnectState.RequestedToAccept)
         {
             AcceptCommonRequest(connectionModel);
         }
     }
     else
     {
         ConnectToUncommonUser(connectionModel);
     }
 }
예제 #4
0
        public bool GetBadgeState(BadgeType badge)
        {
            AppBadgeType appBadgeType = AppResources.BadgeTypes[badge.Id];

            List <BadgeAction> actions;

            switch (appBadgeType)
            {
            case AppBadgeType.ConnectTo10Users:
            case AppBadgeType.ConnectTo3Users:
            case AppBadgeType.ConnectTo50Users:
                string badgeId = AppResources.GetBadgeIdByType(AppBadgeType.ConnectTo50Users);
                actions = BadgeActions.Items.FindAll(temp => temp.Badge.Equals(badgeId));
                break;

            default:
                actions = BadgeActions.Items.FindAll(temp => temp.Badge.Equals(badge.Id));
                break;
            }

            return(AppResources.IsBadgeEnabled(badge.Id, actions.Count));
        }