Beispiel #1
0
        private async Task LoadTeamPlaying()
        {
            IsBusy = true;

            // Load Team
            try
            {
                teamPlaying.Clear();

                //For each ID reference from user --> Load into Team
                foreach (string team_uid in user.team_uid)
                {
                    //Load the team by its ID having in User
                    Team team = await TeamsFirestore.GetTeamByIdAsync(team_uid);

                    //Add it into collection of team
                    teamPlaying.Add(team);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
        protected async override void OnAppearing()
        {
            base.OnAppearing();

            //Establish relationship with team
            userStatus = await TeamsFirestore.GetRelationshipAsync(UsersFirestore.myProfile.Id, teamDetailsPageViewModel.Team);

            InfoFrame.IsVisible  = true;
            InfoButton.IsEnabled = false;

            switch (userStatus)
            {
            case (sbyte)relationshipType.isInside:
                joinTeamButton.Text = "Leave Team";
                break;

            case (sbyte)relationshipType.isRequesting:
                joinTeamButton.Text = "✔️ Requested";
                break;

            case (sbyte)relationshipType.isOutside:
                joinTeamButton.Text = "Join Team";
                break;
            }
        }
Beispiel #3
0
        public async Task Test7_AddTeamAsync()
        {
            //Arrange
            Team team = new Team
            {
                bio         = "bla bla bla bla",
                level       = "intermediate",
                location    = "Biota",
                name        = "TestingTeam",
                sport       = "badminton",
                team_leader = "6xyKcZwxg1cXjUkjaggIf8WGWzu1",
                avatar      = "https://image.freepik.com/free-vector/modern-sports-logo-template-with-flat-design_23-2147954941.jpg",
                member      = new List <string> {
                    "6xyKcZwxg1cXjUkjaggIf8WGWzu1"
                },
                memberRequest = new List <string>()
            };

            //Act
            //Push
            await TeamsFirestore.AddTeamAsync(team);

            //Fetch again
            var newTeam = await TeamsFirestore.GetTeamByNameAsync("TestingTeam");

            //Assert
            Assert.True(newTeam.location.Equals("Biota"));
        }
Beispiel #4
0
        async Task ExecuteLoadTeamsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                teamsList.Clear();
                var teams = await TeamsFirestore.GetAllTeamsAsync();

                foreach (var team in teams)
                {
                    teamsList.Add(team);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #5
0
        public async Task Test5_GetTeamByID()
        {
            //Arrange
            string user_id = "mTwtRUKrzfamBp6PUEMGPMCRNBy1";

            //Act
            var teams = await TeamsFirestore.GetUserTeamsAsync(user_id);

            //Assert
            Assert.True(teams.Count > 0);
        }
Beispiel #6
0
        public async Task Test4_GetTeamByID()
        {
            //Arrange
            string team_id = "sYvjfjfqarGNAptZ5myb";

            //Act
            var team = await TeamsFirestore.GetTeamByIdAsync(team_id);

            //Assert
            Assert.True(team.team_leader.Equals("HcHGkaJGpoOSNZ19hzqUjPqcoHj1"));
        }
Beispiel #7
0
        public async Task Test3_GetTeamByID()
        {
            //Arrange
            string team_id = "Xu3FwHcyJpeDuXIk1vti";

            //Act
            var team = await TeamsFirestore.GetTeamByIdAsync(team_id);

            //Assert
            Assert.Contains("6H7I6z5BsDcyU1xP53DG2CAHOj53", team.member);
        }
Beispiel #8
0
        public async Task Test2_GetTeamByID()
        {
            //Arrange
            string team_id = "1fhFeGGSZsIyQqwPkuMA";

            //Act
            var team = await TeamsFirestore.GetTeamByIdAsync(team_id);

            //Assert
            Assert.True(team.name.Equals("TeamB"));
        }
Beispiel #9
0
        public async Task Test1_GetAllTeams()
        {
            //Arrange
            List <Team> teams = new List <Team>();


            //Act
            teams = await TeamsFirestore.GetAllTeamsAsync();

            //Assert
            Assert.True(teams.Count > 1);
        }
Beispiel #10
0
        public async Task Test6_GetRelationship()
        {
            //Arrange
            string user_id = "mTwtRUKrzfamBp6PUEMGPMCRNBy1";
            string team_id = "Xu3FwHcyJpeDuXIk1vti";
            var    team    = await TeamsFirestore.GetTeamByIdAsync(team_id);

            //Act
            var relationship = await TeamsFirestore.GetRelationshipAsync(user_id, team);

            //Assert
            Assert.True(relationship.Equals(relationshipType.isRequesting));
        }
Beispiel #11
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);
        }
        public async Task Test6_RemoveTeamFromUser()
        {
            //Arrange
            string team_id = "1fhFeGGSZsIyQqwPkuMA";
            var    team    = await TeamsFirestore.GetTeamByIdAsync(team_id);

            string user_id = "6H7I6z5BsDcyU1xP53DG2CAHOj53";

            //Act
            //Remove the specific team from the user document
            await UsersFirestore.RemoveTeamFromUserAsync(user_id, team);

            //Fetch again the new document
            var user = await UsersFirestore.GetUserByUIDAsync(user_id);

            //Assert
            Assert.DoesNotContain(team_id, user.team_uid);
        }
Beispiel #13
0
        public async Task Test3_LoadMyProfile()
        {
            //Arrange
            string uid  = "6H7I6z5BsDcyU1xP53DG2CAHOj53";
            var    user = await UsersFirestore.GetUserByUIDAsync(uid);

            UsersFirestore.myProfile = user;

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

            var vm = new TeamDetailsPageViewModel(team);

            //Act


            //Assert
            Assert.True(vm.TeamLeader.Equals("HcHGkaJGpoOSNZ19hzqUjPqcoHj1"));
        }
Beispiel #14
0
        public async Task Test2_LoadMyProfile()
        {
            //Arrange
            string uid  = "6H7I6z5BsDcyU1xP53DG2CAHOj53";
            var    user = await UsersFirestore.GetUserByUIDAsync(uid);

            UsersFirestore.myProfile = user;

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

            var vm = new TeamDetailsPageViewModel(team);

            //Act


            //Assert
            Assert.True(vm.isTeamLeader);
        }
Beispiel #15
0
        async Task ExecuteLoadNotificationsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                notificationsList.Clear();
                var notifications = await NotificationsFirestore.GetMyNotificationsAsync();

                foreach (var notification in notifications)
                {
                    // Set the visibility of each notification
                    setVisibility(notification);

                    if (notification.isVisible)
                    {
                        // Load team & user
                        notification.team = await TeamsFirestore.GetTeamByIdAsync(notification.team_id);

                        notification.user = await UsersFirestore.GetUserByUIDAsync(notification.user_id);

                        // Create a message
                        setNotificationContent(notification);

                        notificationsList.Add(notification);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
        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;
            }
        }