Beispiel #1
0
        public async Task Test8_RemoveUserFromTeamAsync()
        {
            //Arrange
            string user_id = "ryZJ4v8INRes4o2ZxEaNOPDtqgo2";

            string team_id = "Xu3FwHcyJpeDuXIk1vti";
            var    team    = await TeamsFirestore.GetTeamByIdAsync(team_id);

            //Act
            //Remove from database
            await TeamsFirestore.RemoveUserFromTeamAsync(user_id, team);

            //Fetch again
            var refreshTeam = await TeamsFirestore.GetTeamByIdAsync(team_id);

            //Assert
            Assert.DoesNotContain(user_id, refreshTeam.member);
        }
        async void JoinButtonClicked(object sender, EventArgs args)
        {
            switch (userStatus)
            {
            case (sbyte)relationshipType.isInside:
                var answer = await DisplayAlert("Exit", "Do you really want to leave your group ?", "Leave", "Cancel");

                if (answer)
                {
                    //If is already inside Team, then button is for leaving the team
                    await TeamsFirestore.RemoveUserFromTeamAsync(UsersFirestore.myProfile.Id, teamDetailsPageViewModel.Team);

                    await UsersFirestore.RemoveTeamFromUserAsync(UsersFirestore.myProfile.Id, teamDetailsPageViewModel.Team);

                    //Remove notifications in database
                    await NotificationsFirestore.DeleteNotificationAsync(UsersFirestore.myProfile.Id + teamDetailsPageViewModel.Team.Id);

                    joinTeamButton.Text = "Join Team";
                    userStatus          = (sbyte)relationshipType.isOutside;
                }

                break;

            case (sbyte)relationshipType.isRequesting:
                //If is requesting, then button is for cancelled
                await TeamsFirestore.RemoveUserRequestFromTeamAsync(UsersFirestore.myProfile.Id, teamDetailsPageViewModel.Team);

                //Remove arised notification
                await NotificationsFirestore.DeleteNotificationAsync(UsersFirestore.myProfile.Id + teamDetailsPageViewModel.Team.Id);

                await UsersFirestore.RemoveNotificationFromUserAsync(teamDetailsPageViewModel.Team.team_leader
                                                                     , /*Generate ID = User_id + Team_id*/ UsersFirestore.myProfile.Id + teamDetailsPageViewModel.Team.Id);

                joinTeamButton.Text = "Join Team";
                userStatus          = (sbyte)relationshipType.isOutside;
                break;

            case (sbyte)relationshipType.isOutside:
                //If is outside, then button is for request joining team
                await TeamsFirestore.AddUserRequestToTeamAsync(UsersFirestore.myProfile.Id, teamDetailsPageViewModel.Team);

                // Create a notification
                Notification notification = new Notification
                {
                    Id      = UsersFirestore.myProfile.Id + teamDetailsPageViewModel.Team.Id,
                    team_id = teamDetailsPageViewModel.Team.Id,
                    user_id = UsersFirestore.myProfile.Id,
                    status  = "",
                    type    = "member_request"
                };

                // Arise a notification to the team leader of that team
                await UsersFirestore.AddNotificationToUserAsync(teamDetailsPageViewModel.Team.team_leader, notification.Id);

                //Push notification online
                await NotificationsFirestore.CreateNotificationAsync(notification);

                joinTeamButton.Text            = "✔️ Requested";
                joinTeamButton.BackgroundColor = Color.FromHex("#D3D3D3");
                userStatus = (sbyte)relationshipType.isRequesting;
                break;
            }
        }