Esempio n. 1
0
        public async Task <ConfirmFriendResponse> RequestConfirmAsync(long friendId, CancellationToken cancellationToken = default(CancellationToken), long?childProfileId = null) =>
        await Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            ConfirmFriendRequest confirmFriendRequest = new ConfirmFriendRequest {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Url         = GlobalSettings.Instance.Endpoints.FriendEndPoints.ConfirmRequestEndPoint,
                Data        = new ConfirmRequestDataModel {
                    FriendId = friendId,
                    ChildId  = childProfileId
                }
            };

            ConfirmFriendResponse confirmFriendResponse = null;

            try {
                confirmFriendResponse = await _requestProvider.PostAsync <ConfirmFriendRequest, ConfirmFriendResponse>(confirmFriendRequest);
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (Exception ex) {
                Crashes.TrackError(ex);
                Debug.WriteLine($"ERROR:{ex.Message}");

                throw new Exception((JsonConvert.DeserializeObject <AddFriendException>(ex.Message)).Empty.FirstOrDefault());
            }

            return(confirmFriendResponse);
        }, cancellationToken);
Esempio n. 2
0
        public ChildFriendshipInviteItemViewModel(
            IFriendService friendService)
        {
            _friendService = friendService;

            IsAvatarEnabled = true;

            AcceptCommand = new Command(async() => {
                try {
                    ConfirmFriendResponse confirmFriendResponse = await _friendService.RequestConfirmAsync(((ProfileDTO)InviteTo).Id, childProfileId: Child.Id);

                    if (confirmFriendResponse != null)
                    {
                        MessagingCenter.Send <object, long>(this, GlobalSettings.Instance.AppMessagingEvents.FriendEvents.FriendshipInviteAccepted, confirmFriendResponse.Id);

                        await DialogService.ToastAsync("Friend added!");
                    }
                }
                catch (OperationCanceledException) { }
                catch (ObjectDisposedException) { }
                catch (ServiceAuthenticationException) { }
                catch (Exception exc) {
                    Crashes.TrackError(exc);

                    await DialogService.ToastAsync(exc.Message);
                }
            });

            DeclineCommand = new Command(async() => {
                try {
                    DeleteFriendResponse deleteFriendResponse = await _friendService.RequestDeleteAsync(((ProfileDTO)InviteTo).Id, childProfileId: Child.Id);

                    if (deleteFriendResponse != null)
                    {
                        MessagingCenter.Instance.Send <object, long>(this, GlobalSettings.Instance.AppMessagingEvents.FriendEvents.FriendshipInviteDeclined, ((ProfileDTO)InviteTo).Id);

                        await DialogService.ToastAsync("Friend request rejected!");
                    }
                }
                catch (OperationCanceledException) { }
                catch (ObjectDisposedException) { }
                catch (ServiceAuthenticationException) { }
                catch (Exception exc) {
                    Crashes.TrackError(exc);

                    Debug.WriteLine($"ERROR:{exc.Message}");
                    await DialogService.ToastAsync(exc.Message);
                }
            });
        }