private void Save()
        {
            BoardSquaresRepository db = new BoardSquaresRepository();

            foreach (var player in GetCombinedPlayers())
            {
                var userTeamPlayer = new UserTeamPlayer();
                userTeamPlayer.PlayerID   = player.PlayerID;
                userTeamPlayer.UserTeamID = Entity.UserTeamID;
                db.Context.UserTeamPlayers.Add(userTeamPlayer);
            }
            var tieBreaker1 = new UserTeamTieBreakerPlayers();

            tieBreaker1.PlayerID   = TieBreakerPlayer1.PlayerID;
            tieBreaker1.UserTeamID = Entity.UserTeamID;
            db.Context.TieBreakerPlayers.Add(tieBreaker1);

            var tieBreaker2 = new UserTeamTieBreakerPlayers();

            tieBreaker2.PlayerID   = TieBreakerPlayer2.PlayerID;
            tieBreaker2.UserTeamID = Entity.UserTeamID;
            db.Context.TieBreakerPlayers.Add(tieBreaker2);

            var ut = db.Context.UserTeams.Find(Entity.UserTeamID);

            ut.Complete = true;
            db.Context.SaveChanges();
        }
예제 #2
0
파일: Menu.cs 프로젝트: Bubbhas/Fifa
        //private void //ShowUserTeamMoney()
        //{
        //    UserTeam userTeam = dataAccess.GetCashOfUserTeam(dataAccess.GetActiveUserId());
        //    app.CenterText($"Du har kvar {userTeam.TeamMoney}kr");
        //}

        private void AddPlayerToTeam(int id)
        {
            using (var context = new FifaContext())
            {
                var userTeamPlayer = new UserTeamPlayer
                {
                    PlayerId   = id,
                    UserTeamId = dataAccess.GetActiveUserId()
                };
                context.UserTeamPlayers.Add(userTeamPlayer);
                //context.SaveChanges();
            }
        }
        // TODO : Add check for formation -> whether the formation has the given position !!!
        public void AddPlayerToTeam(AddUserTeamPlayerRequestModel dto)
        {
            _callerId = _authChecker.GetCallerId();

            var userTeam = _userTeamServiceP.Get(dto.UserTeamId);

            if (userTeam == null)
            {
                throw new UserTeamNotFound();
            }

            if (userTeam.UserId != _callerId)
            {
                throw new UserNotAuthorized();
            }

            var playerHistory = _playerHistoryServiceP.Get(dto.PlayerHistoryId);

            if (playerHistory == null)
            {
                throw new PlayerHistoryNotFound();
            }

            var position = _positionServiceP.Get(dto.PositionId);

            if (position == null)
            {
                throw new PositionNotFound();
            }

            var predicatePosition = PredicateBuilder.New <PlayerPosition>(true);

            predicatePosition = predicatePosition.And(x => x.PlayerId == playerHistory.PlayerId);
            predicatePosition = predicatePosition.And(x => x.PositionId == position.Id);

            var canPlayOnGivenPosition = _playerPositionServiceP.Queryable().Where(predicatePosition).Any();

            if (!canPlayOnGivenPosition)
            {
                throw new PlayerPositionNotValid();
            }

            var predicateUserTeamPlayer = PredicateBuilder.New <UserTeamPlayer>(true);

            predicateUserTeamPlayer = predicateUserTeamPlayer.And(x => x.UserTeamId == userTeam.Id);
            predicateUserTeamPlayer = predicateUserTeamPlayer.And(x => x.PlayerHistoryId == playerHistory.Id);
            predicateUserTeamPlayer = predicateUserTeamPlayer.And(x => x.PositionId == position.Id);

            var oldPlayerOnGivenPosition = _userTeamPlayerServiceP.Queryable().Where(predicateUserTeamPlayer).FirstOrDefault();

            if (oldPlayerOnGivenPosition != null)
            {
                _userTeamPlayerServiceP.Delete(oldPlayerOnGivenPosition);
            }

            var newPlayerOnGivenPosition = new UserTeamPlayer
            {
                Id = Guid.NewGuid(),
                PlayerHistoryId = playerHistory.Id,
                UserTeamId      = userTeam.Id,
                PositionId      = position.Id
            };

            _userTeamPlayerServiceP.Insert(newPlayerOnGivenPosition);
        }