Example #1
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);
                }
            });
        }
Example #2
0
        public async Task <DeleteFriendResponse> DeleteFriend(DeleteFriendRequest request)
        {
            DeleteFriendResponse deleteFriendResponse = new DeleteFriendResponse();

            try
            {
                deleteFriendResponse = await App.Database.DeleteFriend(new DeleteFriendRequest
                {
                    Username = request.Username
                });
            }
            catch (Exception e)
            {
                await _dialogService.ShowMessage($"The server returned an error: {e.Message}", "Error", "OK", null);
            }
            return(deleteFriendResponse);
        }
Example #3
0
        public async Task <DeleteFriendResponse> RequestDeleteAsync(long friendId, CancellationToken cancellationToken = default(CancellationToken), long?childProfileId = null) =>
        await Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            DeleteFriendRequest deleteFriendRequest = new DeleteFriendRequest {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Url         = GlobalSettings.Instance.Endpoints.FriendEndPoints.DeleteRequestEndPoint,
                Data        = new ConfirmRequestDataModel {
                    FriendId = friendId,
                    ChildId  = childProfileId
                }
            };

            DeleteFriendResponse deleteFriendResponse = null;

            try {
                deleteFriendResponse = await _requestProvider.PostAsync <DeleteFriendRequest, DeleteFriendResponse>(deleteFriendRequest);
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (HttpRequestExceptionEx exc) {
                DeleteFriendResponse deleteFriendBadResponse = JsonConvert.DeserializeObject <DeleteFriendResponse>(exc.Message);

                string output = string.Format("{0} {1}",
                                              deleteFriendBadResponse.Errors?.FirstOrDefault(),
                                              deleteFriendBadResponse.Profile?.FirstOrDefault());

                output = (string.IsNullOrWhiteSpace(output) || string.IsNullOrEmpty(output)) ? DELELTE_FRIEND_ERROR : output;

                throw new InvalidOperationException(output.Trim());
            }
            catch (Exception ex) {
                Crashes.TrackError(ex);

                throw new InvalidOperationException((JsonConvert.DeserializeObject <AddFriendException>(ex.Message)).FriendId.FirstOrDefault(), ex);
            }
            return(deleteFriendResponse);
        }, cancellationToken);