Ejemplo n.º 1
0
        public IActionResult Trade(int id, [FromBody] PlayerStatusUpdateRequest assignToInjuredReserveRequest)
        {
            assignToInjuredReserveRequest.PlayerId = id;
            if (_playerService.UpdateStatusToTraded(assignToInjuredReserveRequest))
            {
                return(Ok());
            }

            return(BadRequest());
        }
Ejemplo n.º 2
0
        public bool UpdateStatusToInjured(PlayerStatusUpdateRequest playerStatusUpdateRequest)
        {
            var playerDetails = _playerRepository.GetDetails(playerStatusUpdateRequest.PlayerId);

            if (playerDetails?.LastRosterTransaction.RosterTransactionType == RosterTransactionType.Healthy ||
                playerDetails?.LastRosterTransaction.RosterTransactionType == RosterTransactionType.Signed ||
                playerDetails?.LastRosterTransaction.RosterTransactionType == RosterTransactionType.Traded)
            {
                playerStatusUpdateRequest.RosterTransactionType = RosterTransactionType.Injured;
                playerStatusUpdateRequest.TeamCode = playerDetails.TeamCode;

                return(_playerRepository.UpdateStatus(playerStatusUpdateRequest));
            }

            return(false);
        }
Ejemplo n.º 3
0
        public bool UpdateStatusToHealthy(PlayerStatusUpdateRequest playerStatusUpdateRequest)
        {
            var playerDetails = _playerRepository.GetDetails(playerStatusUpdateRequest.PlayerId);

            var teamDetails = _teamRepository.GetDetails(playerDetails.TeamCode);

            if (teamDetails.ActivePlayers.Count() < 10 &&
                playerDetails?.LastRosterTransaction.RosterTransactionType == RosterTransactionType.Injured)
            {
                playerStatusUpdateRequest.RosterTransactionType = RosterTransactionType.Healthy;
                playerStatusUpdateRequest.TeamCode = playerDetails.TeamCode;

                return(_playerRepository.UpdateStatus(playerStatusUpdateRequest));
            }

            return(false);
        }
Ejemplo n.º 4
0
        public bool UpdateStatusToTraded(PlayerStatusUpdateRequest playerStatusUpdateRequest)
        {
            var playerDetails = _playerRepository.GetDetails(playerStatusUpdateRequest.PlayerId);

            var currentTeamDetails = _teamRepository.GetDetails(playerDetails.TeamCode);

            var destinationTeamDetails = _teamRepository.GetDetails(playerStatusUpdateRequest.TeamCode);

            if (currentTeamDetails.ActivePlayers.Count() > 4 &&
                destinationTeamDetails.ActivePlayers.Count() < 10 &&
                playerDetails?.LastRosterTransaction.RosterTransactionType != RosterTransactionType.Injured)
            {
                playerStatusUpdateRequest.RosterTransactionType = RosterTransactionType.Traded;

                return(_playerRepository.UpdateStatus(playerStatusUpdateRequest));
            }

            return(false);
        }
Ejemplo n.º 5
0
        public bool UpdateStatus(PlayerStatusUpdateRequest playerStatusUpdateRequest)
        {
            using (var dbConnection = Db.CreateConnection())
            {
                using (var dbCommand = dbConnection.CreateCommand())
                {
                    dbCommand.CommandText = @"
                                    INSERT INTO
                                        roster_transaction(roster_transaction_type_id, player_id, team_code, effective_date)
                                        VALUES (@roster_transaction_type_id, @player_id, @team_code, @effective_date)";

                    var rosterTransactionTypeParameter = dbCommand.CreateParameter();
                    rosterTransactionTypeParameter.DbType        = System.Data.DbType.Int32;
                    rosterTransactionTypeParameter.ParameterName = "@roster_transaction_type_id";
                    rosterTransactionTypeParameter.Value         = playerStatusUpdateRequest.RosterTransactionType;
                    dbCommand.Parameters.Add(rosterTransactionTypeParameter);

                    var playerIdParameter = dbCommand.CreateParameter();
                    playerIdParameter.DbType        = System.Data.DbType.Int32;
                    playerIdParameter.ParameterName = "@player_id";
                    playerIdParameter.Value         = playerStatusUpdateRequest.PlayerId;
                    dbCommand.Parameters.Add(playerIdParameter);

                    var teamCodeParameter = dbCommand.CreateParameter();
                    teamCodeParameter.DbType        = System.Data.DbType.String;
                    teamCodeParameter.ParameterName = "@team_code";
                    teamCodeParameter.Value         = playerStatusUpdateRequest.TeamCode;
                    dbCommand.Parameters.Add(teamCodeParameter);

                    var effectiveDateParameter = dbCommand.CreateParameter();
                    effectiveDateParameter.DbType        = System.Data.DbType.DateTime;
                    effectiveDateParameter.ParameterName = "@effective_date";
                    effectiveDateParameter.Value         = playerStatusUpdateRequest.EffectiveDate;
                    dbCommand.Parameters.Add(effectiveDateParameter);

                    dbCommand.ExecuteNonQuery();

                    return(true);
                }
            }
        }