Beispiel #1
0
 public IResult <IReadOnlyCollection <Role> > GetAll()
 {
     return(_context.GetAll());
 }
Beispiel #2
0
        private Team BuildTeamModel(TeamDTO tDTO)
        {
            //team members
            PlayerDTO CaptainDTO = _playerContext.GetByID(tDTO.TeamCaptainID) ?? new PlayerDTO();
            PlayerDTO tm2DTO     = _playerContext.GetByID(tDTO.TeamMember2ID) ?? new PlayerDTO();
            PlayerDTO tm3DTO     = _playerContext.GetByID(tDTO.TeamMember3ID) ?? new PlayerDTO();
            PlayerDTO tm4DTO     = _playerContext.GetByID(tDTO.TeamMember4ID) ?? new PlayerDTO();
            PlayerDTO tm5DTO     = _playerContext.GetByID(tDTO.TeamMember5ID) ?? new PlayerDTO();
            //get player role with the role context
            var roles  = _roleContext.GetAll();
            var cRole  = roles.Where(i => i.RoleID == CaptainDTO.PlayerRoleID).FirstOrDefault() ?? new RoleDTO();
            var t2Role = roles.Where(i => i.RoleID == tm2DTO.PlayerRoleID).FirstOrDefault() ?? new RoleDTO();
            var t3Role = roles.Where(i => i.RoleID == tm3DTO.PlayerRoleID).FirstOrDefault() ?? new RoleDTO();
            var t4Role = roles.Where(i => i.RoleID == tm4DTO.PlayerRoleID).FirstOrDefault() ?? new RoleDTO();
            var t5Role = roles.Where(i => i.RoleID == tm5DTO.PlayerRoleID).FirstOrDefault() ?? new RoleDTO();
            //create list of team members excluding the captain
            List <Player> teamMembers = new List <Player>
            {
                new Player {
                    PlayerID = tm2DTO.PlayerID, PlayerName = tm2DTO.PlayerName, PlayerPlatformID = tm2DTO.PlayerPlatformID, PlayerRole = new Role {
                        RoleID = t2Role.RoleID, RoleName = t2Role.RoleName, RoleDescription = t2Role.RoleDescription
                    }
                },
                new Player {
                    PlayerID = tm3DTO.PlayerID, PlayerName = tm3DTO.PlayerName, PlayerPlatformID = tm3DTO.PlayerPlatformID, PlayerRole = new Role {
                        RoleID = t3Role.RoleID, RoleName = t3Role.RoleName, RoleDescription = t3Role.RoleDescription
                    }
                },
                new Player {
                    PlayerID = tm4DTO.PlayerID, PlayerName = tm4DTO.PlayerName, PlayerPlatformID = tm4DTO.PlayerPlatformID, PlayerRole = new Role {
                        RoleID = t4Role.RoleID, RoleName = t4Role.RoleName, RoleDescription = t4Role.RoleDescription
                    }
                },
                new Player {
                    PlayerID = tm5DTO.PlayerID, PlayerName = tm5DTO.PlayerName, PlayerPlatformID = tm5DTO.PlayerPlatformID, PlayerRole = new Role {
                        RoleID = t5Role.RoleID, RoleName = t5Role.RoleName, RoleDescription = t5Role.RoleDescription
                    }
                },
            };
            //TeamDivision
            DivisionDTO div = _divisionContext.GetByID(tDTO.TeamDivisionID) ?? new DivisionDTO(); //could do something with the division


            Team t = new Team
            {
                TeamID      = tDTO.TeamID,
                TeamName    = tDTO.TeamName,
                TeamLogo    = tDTO.TeamLogo,
                TeamCaptain = new Player {
                    PlayerID = CaptainDTO.PlayerID, PlayerName = CaptainDTO.PlayerName, PlayerPlatformID = CaptainDTO.PlayerPlatformID, PlayerRole = new Role {
                        RoleID = cRole.RoleID, RoleName = cRole.RoleName, RoleDescription = cRole.RoleDescription
                    }
                },
                TeamMembers  = teamMembers,
                TeamDivision = new Division {
                    DivisionID = div.DivisionID, DivisionName = div.DivisionName
                },
            };

            return(t);
        }