예제 #1
0
        public void friendshipOperation(InviteFriendOperation operation)
        {
            var m = new ServiceManager <InviteFriendOperationCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <InviteFriendOperationCompletedEventArgs> operationCompleted)
            {
                InviteFriendOperationData data = new InviteFriendOperationData();
                data.Operation = operation;
                data.User      = user;
                client1.InviteFriendOperationCompleted -= operationCompleted;
                client1.InviteFriendOperationCompleted += operationCompleted;
                client1.InviteFriendOperationAsync(ApplicationState.Current.SessionData.Token, data);
            });

            m.OperationCompleted += (s, a) =>
            {
                FaultException <BAServiceException> faultEx = a.Error as FaultException <BAServiceException>;
                if (a.Error != null && (faultEx == null || faultEx.Detail.ErrorCode != ErrorCode.ObjectNotFound))
                {
                    BugSenseHandler.Instance.SendExceptionAsync(a.Error);
                    onOperationCompleted();
                    BAMessageBox.ShowError(ApplicationStrings.UserViewModel_ErrOperation);
                }
                else
                {
                    if (operation == InviteFriendOperation.Reject)
                    {
                        ApplicationState.Current.ProfileInfo.Friends.Remove(user);
                        NotifyPropertyChanged("IsFriend");
                        NotifyPropertyChanged("IsCalendarAccessible");
                        NotifyPropertyChanged("HasAccessToMeasurements");
                    }
                    else
                    {
                        ApplicationState.Current.ProfileInfo.Invitations.Add(new FriendInvitationDTO()
                        {
                            CreatedDateTime = DateTime.UtcNow, InvitationType = InvitationType.Invite, Invited = user
                        });
                    }
                    NotifyPropertyChanged("CanBeFriend");
                    onOperationCompleted();
                }
            };

            if (!m.Run())
            {
                onOperationCompleted();
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
        void inviteOperation(InviteFriendOperation operation)
        {
            progressBar.ShowProgress(true, ApplicationStrings.ProfileInfoPage_ProgressSend);
            var m = new ServiceManager <InviteFriendOperationCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <InviteFriendOperationCompletedEventArgs> operationCompleted)
            {
                InviteFriendOperationData data = new InviteFriendOperationData();
                data.Operation = operation;
                data.User      = viewModel.User;
                client1.InviteFriendOperationCompleted -= operationCompleted;
                client1.InviteFriendOperationCompleted += operationCompleted;
                client1.InviteFriendOperationAsync(ApplicationState.Current.SessionData.Token, data);
            });

            m.OperationCompleted += (s, a) =>
            {
                progressBar.ShowProgress(false);
                FaultException <BAServiceException> faultEx = a.Error as FaultException <BAServiceException>;
                if (a.Error != null && faultEx.Detail.ErrorCode != ErrorCode.ObjectNotFound)
                {
                    BAMessageBox.ShowError(ApplicationStrings.InvitationViewPage_ErrInvitationOperation);
                }
                else
                {
                    ApplicationState.Current.ProfileInfo.Invitations.Remove(viewModel.Invitation);
                    if (NavigationService.CanGoBack)
                    {
                        NavigationService.GoBack();
                    }
                }
            };

            if (!m.Run())
            {
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
 public void Fill(UserDTO user, InviteFriendOperation operation)
 {
     this.user      = user;
     this.operation = operation;
     usrProfileListEntry1.Fill(user);
 }