public IHttpActionResult CreateTeam([FromBody]TeamDTO _team)
 {
     LeaguesApiController leaguesApiController = new LeaguesApiController();
     int leagueId = leaguesApiController.getLeagueIdByTeamId(_team.Id);
     team t = new team { Name = _team.Name, Description = _team.Description, League = leagueId, Enabled = true, Logo = _team.Logo };
     using (var context = new escorcenterdbEntities())
     {
         context.teams.Add(t);
         context.SaveChanges();
     }
     return Ok(t);
 }
        public IHttpActionResult CreateTeam([FromBody] TeamDTO _team)
        {
            LeaguesApiController leaguesApiController = new LeaguesApiController();
            int  leagueId = leaguesApiController.getLeagueIdByTeamId(_team.Id);
            team t        = new team {
                Name = _team.Name, Description = _team.Description, League = leagueId, Enabled = true, Logo = _team.Logo
            };

            using (var context = new escorcenterdbEntities())
            {
                context.teams.Add(t);
                context.SaveChanges();
            }
            return(Ok(t));
        }
        public IHttpActionResult GetScoreTableResult(int teamId)
        {
            scoretableview       _scoreTableView = null;
            LeaguesApiController leagueApi       = new LeaguesApiController();
            int position = 0;

            team _team = null;

            scoretableview[] _scoreTable = null;

            using (var context = new escorcenterdbEntities())
            {
                _scoreTableView = (from s in context.scoretableviews where s.team == teamId select s).FirstOrDefault <scoretableview>();
                _team           = (from t in context.teams where t.Id == teamId && t.Enabled == true select t).FirstOrDefault <team>();
                long seasonId = leagueApi.GetCurrentSeasonId(_team.League, DateTime.Now);
                _scoreTable = (from st in context.scoretableviews where st.season == seasonId select st).OrderBy(st => st.GamesWon.Value * 3 + st.GamesDrawn.Value * 1).ToArray <scoretableview>();
            }
            if (_scoreTableView == null)
            {
                return(Ok());
            }
            foreach (scoretableview st in _scoreTable)
            {
                if (st.team == teamId)
                {
                    break;
                }
                position++;
            }
            // scoretableview y ScoreTableResultDTO son incompatibles team del primero es Int32, team del segundo es TeamDTO
            TeamDTO             teamDTO             = AutoMapper.Mapper.Map <team, TeamDTO>(_team);
            ScoreTableResultDTO scoreTableResultDTO = new ScoreTableResultDTO()
            {
                League          = leagueApi.getLeagueNameById(_team.League),
                Position        = (long)position,
                GamesDrawn      = (long)_scoreTableView.GamesDrawn,
                GamesLost       = (long)_scoreTableView.GamesLost,
                GamesPlayed     = (long)_scoreTableView.GamesPlayed,
                GamesWined      = (long)_scoreTableView.GamesWon,
                Points          = (long)_scoreTableView.ScoreFavor,
                ScoreFavor      = (long)_scoreTableView.ScoreFavor,
                ScoreDifference = (long)_scoreTableView.ScoreDifference,
                ScoreAgainst    = (long)_scoreTableView.ScoreAgainst,
                Team            = teamDTO
            };

            return(Ok(scoreTableResultDTO));
        }
        public IHttpActionResult GetScoreTableResult(int teamId)
        {
            scoretableview _scoreTableView = null;
            LeaguesApiController leagueApi = new LeaguesApiController();
            int position = 0;

            team _team = null;
            scoretableview[] _scoreTable = null;

            using (var context = new escorcenterdbEntities())
            {
                _scoreTableView = (from s in context.scoretableviews where s.team == teamId select s).FirstOrDefault<scoretableview>();
                _team = (from t in context.teams where t.Id == teamId && t.Enabled == true select t).FirstOrDefault<team>();
                long seasonId = leagueApi.GetCurrentSeasonId(_team.League, DateTime.Now);
                _scoreTable = (from st in context.scoretableviews where st.season == seasonId select st).OrderBy(st => st.GamesWon.Value * 3 + st.GamesDrawn.Value * 1).ToArray<scoretableview>();
            }
            if (_scoreTableView == null)
                return Ok();
            foreach (scoretableview st in _scoreTable)
            {
                if (st.team == teamId)
                    break;
                position++;
            }
            // scoretableview y ScoreTableResultDTO son incompatibles team del primero es Int32, team del segundo es TeamDTO
            TeamDTO teamDTO = AutoMapper.Mapper.Map<team, TeamDTO>(_team);
            ScoreTableResultDTO scoreTableResultDTO = new ScoreTableResultDTO()
            {
                League = leagueApi.getLeagueNameById(_team.League),
                Position = (long)position,
                GamesDrawn = (long)_scoreTableView.GamesDrawn,
                GamesLost = (long)_scoreTableView.GamesLost,
                GamesPlayed = (long)_scoreTableView.GamesPlayed,
                GamesWined = (long)_scoreTableView.GamesWon,
                Points = (long)_scoreTableView.ScoreFavor,
                ScoreFavor = (long)_scoreTableView.ScoreFavor,
                ScoreDifference = (long)_scoreTableView.ScoreDifference,
                ScoreAgainst = (long)_scoreTableView.ScoreAgainst,
                Team = teamDTO
            };
            return Ok(scoreTableResultDTO);
        }