public IActionResult CreateTeam([FromBody] Models.TeamInputModel team)
        {
            string outMessage = "";

            if (ValidateTeamInput(team, out outMessage) == false)
            {
                return(BadRequest(new { message = outMessage }));
            }

            var user1 = _UserRepository.GetUserByUsername(team.username);

            if (user1 == null)
            {
                return(BadRequest(new { message = "User does not exist." }));
            }

            Domain.Team team1 = new Domain.Team(user1);
            team1.teamname = team.teamname;
            bool validated = _TeamRepository.AddTeam(team1);

            if (!validated)
            {
                return(StatusCode(500));
            }

            Domain.Team madeTeam  = _TeamRepository.GetByTeamName(team1.teamname);
            bool        ranksMade = false;

            ranksMade = _RankRepository.InitializeRanks(madeTeam);
            if (!ranksMade)
            {
                _TeamRepository.DeleteTeam(madeTeam);
                return(StatusCode(500));
            }

            foreach (var user in madeTeam.Userlist)
            {
                user.password = null;
            }

            return(Created("app/team/create", madeTeam));
        }
        public IActionResult UpdateTeam([FromBody] Models.TeamInputModel team)
        {
            string outMessage = "";

            if (ValidateTeamInput(team, out outMessage) == false)
            {
                return(BadRequest(new { message = outMessage }));
            }

            var user1 = _UserRepository.GetUserByUsername(team.username);

            if (user1 == null)
            {
                return(BadRequest(new { message = "User does not exist." }));
            }

            var team1fromdb = _TeamRepository.GetByTeamName(team.teamname);

            if (team1fromdb == null)
            {
                return(BadRequest(new { message = "Team does not exist." }));
            }

            bool validated = team1fromdb.AddMember(user1);

            if (!validated)
            {
                return(StatusCode(500));
            }
            var validated2 = _TeamRepository.UpdateTeam(team1fromdb);

            if (!validated2)
            {
                return(StatusCode(500));
            }
            return(Ok());
        }
        public IActionResult ChangeLeader([FromBody] Models.TeamInputModel team)
        {
            string outMessage = "";

            if (ValidateTeamInput(team, out outMessage) == false)
            {
                return(BadRequest(new { message = outMessage }));
            }
            Domain.Team pullTeam  = _TeamRepository.GetByTeamName(team.teamname);
            bool        hasLeader = false;

            for (int i = 0; i < pullTeam.Roles.Count; i++)
            {
                pullTeam.Roles[i] = false;
                if (pullTeam.Userlist[i].username == team.username)
                {
                    pullTeam.Roles[i] = true;
                    hasLeader         = true;
                }
            }

            if (!hasLeader)
            {
                return(BadRequest(new { message = "User is not on the team." }));
            }

            bool success;

            success = _TeamRepository.UpdateTeam(pullTeam);
            if (!success)
            {
                return(StatusCode(500));
            }

            return(Ok());
        }