示例#1
0
        public static Team ConvertToDbModel(TeamModel team)
        {
            var dbTeam = new Team()
            {
                teamId   = team.TeamId,
                teamName = team.Name,
                Image    = team.BannerImageFile == null ? null : new Image()
                {
                    imageFileName    = team.BannerImageFile.FileName,
                    imageContent     = ImageController.ConvertToBytes(team.BannerImageFile),
                    imageContentType = team.BannerImageFile.ContentType
                },
            };

            foreach (var player in team.Players)
            {
                dbTeam.Players.Add(PlayerController.ConvertToDbModel(player));
            }

            foreach (var stat in team.Stats)
            {
                dbTeam.Stats.Add(StatController.ConvertToDbModel(stat));
            }

            return(dbTeam);
        }
示例#2
0
        public static Player ConvertToDbModel(PlayerModel player)
        {
            var dbPlayer = new Player()
            {
                playerId         = player.PlayerId,
                playerFirstName  = player.FirstName,
                playerLastName   = player.LastName,
                playerScreenName = player.ScreenName,
                Image            = player.AvatarImageFile != null ? new Image()
                {
                    imageFileName    = player.AvatarImageFile.FileName,
                    imageContent     = ImageController.ConvertToBytes(player.AvatarImageFile),
                    imageContentType = player.AvatarImageFile.ContentType,
                } : null,
                teamId = player.TeamId,
            };

            foreach (var stat in player.Stats)
            {
                dbPlayer.Stats.Add(StatController.ConvertToDbModel(stat));
            }


            return(dbPlayer);
        }
示例#3
0
        public static PlayerModel ConvertToViewModel(Player dbPlayer)
        {
            var player = new PlayerModel()
            {
                PlayerId      = dbPlayer.playerId,
                FirstName     = dbPlayer.playerFirstName,
                LastName      = dbPlayer.playerLastName,
                ScreenName    = dbPlayer.playerScreenName,
                AvatarImageId = dbPlayer.imageId == null ? -1 : (int)dbPlayer.imageId,
                TeamName      = dbPlayer.Team.teamName,
                TeamId        = dbPlayer.teamId == null ? -1 : (int)dbPlayer.teamId,
            };

            foreach (var stat in dbPlayer.Stats)
            {
                player.Stats.Add(StatController.ConvertToViewModel(stat));
            }

            return(player);
        }
示例#4
0
        public static TeamModel ConvertToViewModel(Team dbTeam)
        {
            var team = new TeamModel()
            {
                TeamId        = dbTeam.teamId,
                Name          = dbTeam.teamName,
                BannerImageId = (dbTeam.imageId == null ? -1 : (int)dbTeam.imageId),
            };

            foreach (var player in dbTeam.Players)
            {
                team.Players.Add(PlayerController.ConvertToViewModel(player));
            }

            foreach (var stat in dbTeam.Stats)
            {
                team.Stats.Add(StatController.ConvertToViewModel(stat));
            }

            return(team);
        }