コード例 #1
0
 public static GameParticipantPlayerEditModel CreateFromModel(GameParticipantPlayer model)
 {
     return(new GameParticipantPlayerEditModel
     {
         Id = model.Id,
         PlayerName = model.Player.Name,
         GameParticipantPlayerProps = model.GameParticipantPlayerProps.ToList()
     });
 }
コード例 #2
0
ファイル: GameController.cs プロジェクト: viktortat/SportLib
        public ActionResult AddParticipantToGame(int particId, int gameId)
        {
            var game = DataContext.Games.Include("Sport").Single(x => x.Id == gameId);

            if (game.GameParticipants.Any(x => x.ParticipantId == particId))
            {
                return(Content("Уже добавлен"));
            }
            if (game.GameParticipants.Count == game.Sport.SidesCountMax)
            {
                return(Content("Превышен лимит команд"));
            }

            var participant = new GameParticipant
            {
                GameId        = gameId,
                ParticipantId = particId
            };

            DataContext.GameParticipants.Add(participant);

            if (game.Sport.IsTeamSport)
            {
                var team = DataContext.Teams.Single(x => x.Id == particId);
                foreach (var player in team.Players)
                {
                    var particPlayer = new GameParticipantPlayer
                    {
                        Player          = player,
                        GameParticipant = participant,
                    };
                    DataContext.GameParticipantPlayers.Add(particPlayer);

                    // свойства
                    var props = player.Properties.Where(x => x.PlayerPropertyType.IsDependsOnGame);
                    foreach (var playerProperty in props)
                    {
                        DataContext.GameParticipantPlayerProps.Add(new GameParticipantPlayerProp
                        {
                            GameParticipantPlayer = particPlayer,
                            PlayerPropertyType    = playerProperty.PlayerPropertyType,
                            PropValue             = playerProperty.Value
                        });
                    }
                }
            }
            else
            {
                var player       = DataContext.Players.Single(x => x.Id == particId);
                var particPlayer = new GameParticipantPlayer
                {
                    Player          = player,
                    GameParticipant = participant,
                };
                DataContext.GameParticipantPlayers.Add(particPlayer);
                var props = player.Properties.Where(x => x.PlayerPropertyType.IsDependsOnGame);
                foreach (var playerProperty in props)
                {
                    DataContext.GameParticipantPlayerProps.Add(new GameParticipantPlayerProp
                    {
                        GameParticipantPlayer = particPlayer,
                        PlayerPropertyType    = playerProperty.PlayerPropertyType,
                        PropValue             = playerProperty.Value
                    });
                }
            }
            DataContext.SaveChanges();

            return(GetGameParticipants(gameId));
        }