public ChildInviteToGroupItemViewModel(
            IGroupsService groupsService)
        {
            _groupsService = groupsService;

            AcceptCommand = new Command(async() => {
                try {
                    GroupRequestConfirmDataModel groupRequestConfirmDataModel = new GroupRequestConfirmDataModel {
                        GroupId = ((GroupDTO)InviteTo).Id,
                        Id      = Child.Id,
                    };

                    GroupRequestConfirmResponse groupRequestConfirmResponse =
                        await _groupsService.GroupRequestConfirmAsync(groupRequestConfirmDataModel, default(CancellationToken));

                    if (groupRequestConfirmResponse != null)
                    {
                        MessagingCenter.Send <object, long>(this, GlobalSettings.Instance.AppMessagingEvents.GroupsEvents.InviteAccepted, ((GroupDTO)InviteTo).Id);

                        await DialogService.ToastAsync("Child joined to group");
                    }
                }
                catch (OperationCanceledException) { }
                catch (ObjectDisposedException) { }
                catch (ServiceAuthenticationException) { }
                catch (Exception exc) {
                    Crashes.TrackError(exc);

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

            DeclineCommand = new Command(async() => {
                try {
                    GroupRequestDeclineDataModel dataModel = new GroupRequestDeclineDataModel {
                        GroupId = ((GroupDTO)InviteTo).Id,
                        Id      = Child.Id
                    };

                    if (await _groupsService.GroupRequestDeclineAsync(dataModel, default(CancellationToken)))
                    {
                        MessagingCenter.Send <object, long>(this, GlobalSettings.Instance.AppMessagingEvents.GroupsEvents.InviteDeclined, ((GroupDTO)InviteTo).Id);

                        await DialogService.ToastAsync("Child declined invite to group");
                    }
                }
                catch (OperationCanceledException) { }
                catch (ObjectDisposedException) { }
                catch (ServiceAuthenticationException) { }
                catch (Exception exc) {
                    Crashes.TrackError(exc);

                    await DialogService.ToastAsync(exc.Message);
                }
            });
        }
Пример #2
0
        public async Task <bool> GroupRequestDeclineAsync(GroupRequestDeclineDataModel dataModel, CancellationToken cancellationToken) =>
        await Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            bool isDecline = default(bool);

            GroupRequestDeclineRequest groupRequestDeclineRequest = new GroupRequestDeclineRequest {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Data        = dataModel,
                Url         = GlobalSettings.Instance.Endpoints.GroupsEndpoints.GroupRequestDeclineEndPoint
            };

            GroupRequestDeclineResponse groupRequestDeclineResponse = null;

            try {
                groupRequestDeclineResponse =
                    await _requestProvider.PostAsync <GroupRequestDeclineRequest, GroupRequestDeclineResponse>(groupRequestDeclineRequest);

                if (groupRequestDeclineResponse != null)
                {
                    isDecline = true;
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

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

            return(isDecline);
        });
Пример #3
0
        private async Task OnDecline(CancellationToken cancellationToken)
        {
            try {
                GroupRequestDeclineDataModel dataModel = new GroupRequestDeclineDataModel {
                    GroupId = this.GroupId,
                    Id      = GlobalSettings.Instance.UserProfile.Id
                };

                if (await _groupsService.GroupRequestDeclineAsync(dataModel, cancellationToken))
                {
                    MessagingCenter.Send <object, long>(this, GlobalSettings.Instance.AppMessagingEvents.GroupsEvents.InviteDeclined, GroupId);

                    await DialogService.ToastAsync($"You are declined invite to {GroupName}!");
                }
            }
            catch (OperationCanceledException) { }
            catch (ObjectDisposedException) { }
            catch (ServiceAuthenticationException) { }
            catch (Exception exc) {
                Crashes.TrackError(exc);

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