Пример #1
0
        // GET api/<controller>
        public IEnumerable<Player> GetAllPlayers()
        {
            try
            {
                List<Player> players = new List<Player>();

                string connectionString = ConfigurationManager.ConnectionStrings["FreeFootieConnectionString"].ConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    var results = (from c in myData.players
                                   orderby c.id ascending
                                   select c).ToList();

                    foreach (var temp in results)
                    {
                        Player player = new Player();
                        player.id = temp.id;
                        player.name = temp.name;
                        player.dob = temp.dob.ToString("yyyy-MM-dd");
                        player.number = temp.number;

                        players.Add(player);
                    }
                }

                return players;
            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "PlayerController.GetAllPlayers");
                return null;
            }
        }
Пример #2
0
        // GET api/<controller>
        public IEnumerable<Location> GetAllLocations()
        {
            try
            {
                List<Location> locations = new List<Location>();

                string connectionString = ConfigurationManager.ConnectionStrings["FreeFootieConnectionString"].ConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    var results = (from c in myData.locations
                                   orderby c.id ascending
                                   select c).ToList();

                    foreach (var temp in results)
                    {
                        Location location = new Location();
                        location.id = temp.id;
                        location.name = temp.name;
                        location.latitude = temp.latitude;
                        location.longitude = temp.longitude;
                        locations.Add(location);
                    }
                }

                return locations;
            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "LocationController.GetAllLocations");
                return null;
            }
        }
Пример #3
0
        // GET api/<controller>
        public IEnumerable<Pool> GetAllPools()
        {
            try
            {
                List<Pool> pools = new List<Pool>();

                string connectionString = ConfigurationManager.ConnectionStrings["FreeFootieConnectionString"].ConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    var results = (from c in myData.pools
                                    orderby c.id ascending
                                    select c).ToList();

                    foreach (var temp in results)
                    {
                        Pool pool = new Pool();
                        pool.id = temp.id;
                        pool.name = temp.name;

                        pools.Add(pool);
                    }
                }

                return pools;
            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "PoolController.GetAllPools");
                return null;
            }
        }
Пример #4
0
        // GET api/<controller>
        public IEnumerable<Team> GetAllPools()
        {
            try
            {
                List<Team> teams = new List<Team>();

                string connectionString = ConfigurationManager.ConnectionStrings["FreeFootieConnectionString"].ConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    var results = (from c in myData.teams
                                   orderby c.id ascending
                                   select c).ToList();

                    foreach (var temp in results)
                    {
                        Team team = new Team();
                        team.id = temp.id;
                        team.name = temp.name;
                        team.coach = temp.coach;
                        team.loses = temp.losses;
                        team.wins = temp.wins;
                        team.ties = temp.ties;
                        team.phone = temp.phone;
                        team.school = temp.schoolID;

                        var playerIDs = (from c in myData.teamPlayers
                                         where c.teamID == temp.id
                                         select c.playerID).ToList().ToArray();

                        team.palyers = playerIDs;

                        teams.Add(team);
                    }
                }

                return teams;
            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "TeamController.GetAllPools");
                return null;
            }
        }
Пример #5
0
        //// PUT api/<controller>/5
        //public void Put(int id, [FromBody]string value)
        //{
        //}
        // DELETE api/<controller>/5
        public void DeleteLocation(int id)
        {
            try
            {
                string connectionString = Properties.Settings.Default.FreeFootieConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    using (TransactionScope myScope = new TransactionScope())
                    {
                        myData.locations.DeleteOnSubmit(myData.locations.Single(c => c.id == id));

                        myData.SubmitChanges();
                        myScope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "LocationController.DeleteLocation");
            }
        }
Пример #6
0
        // GET api/<controller>
        public IEnumerable<Game> GetAllGames()
        {
            try
            {
                List<Game> games = new List<Game>();

                string connectionString = ConfigurationManager.ConnectionStrings["FreeFootieConnectionString"].ConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    var results = (from c in myData.games
                                    join d in myData.locations on c.locationID equals d.id
                                    orderby c.id ascending
                                    select new { game = c, locationName = d.name }).ToList();

                    foreach (var temp in results)
                    {
                        Game game = new Game();
                        game.id = temp.game.id;
                        game.away = temp.game.awayTeamID;
                        game.duration = temp.game.duration;
                        game.home = temp.game.homeTeamID;
                        game.location = temp.game.locationID;
                        game.locationName = temp.locationName;
                        game.date = "<<" + temp.game.startTime.ToString("yyyy-MM-dd HH:mm:ss") + "~"+ temp.game.duration +"h>>";
                        game.state = temp.game.state;
                        game.homeTeamScore = temp.game.homeTeamScore;
                        game.awayTeamScore = temp.game.awayTeamScore;

                        games.Add(game);
                    }
                }

                return games;
            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "GameController.GetAllGames");
                return null;
            }
        }
Пример #7
0
        // POST api/<controller>
        public void PostLocation(Location location)
        {
            try
            {
                string connectionString = Properties.Settings.Default.FreeFootieConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    using (TransactionScope myScope = new TransactionScope())
                    {
                        location newLocation = new location();
                        var newID = (from c in myData.locations
                                     select c.id).Max();
                        newLocation.id = newID + 1;
                        newLocation.name = location.name;
                        newLocation.latitude = location.latitude;
                        newLocation.longitude = location.longitude;

                        myData.locations.InsertOnSubmit(newLocation);
                        myData.SubmitChanges();
                        myScope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "LocationController.PostLocation");
            }
        }
Пример #8
0
        // GET api/<controller>/5
        public Team GetTeamById(int id)
        {
            try
            {
                string connectionString = Properties.Settings.Default.FreeFootieConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    var temp = (from c in myData.teams
                                where c.id == id
                                orderby c.id ascending
                                select c).SingleOrDefault();

                    Team team = new Team();
                    team.id = temp.id;
                    team.name = temp.name;
                    team.coach = temp.coach;
                    team.loses = temp.losses;
                    team.wins = temp.wins;
                    team.ties = temp.ties;
                    team.phone = temp.phone;
                    team.school = temp.schoolID;

                    var playerIDs = (from c in myData.teamPlayers
                                     where c.teamID == temp.id
                                     select c.playerID).ToList().ToArray();

                    team.palyers = playerIDs;

                    return team;
                }

            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "TeamController.GetTeamById");
                return null;
            }
        }
Пример #9
0
        // POST api/<controller>
        public void PostTeam(Team team)
        {
            try
            {
                string connectionString = Properties.Settings.Default.FreeFootieConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    using (TransactionScope myScope = new TransactionScope())
                    {
                        team newTeam = new team();
                        var newID = (from c in myData.teams
                                     select c.id).Max();
                        newTeam.id = newID + 1;
                        newTeam.name = team.name;
                        newTeam.coach = team.coach;
                        newTeam.losses = team.loses;
                        newTeam.wins = team.wins;
                        newTeam.ties = team.ties;
                        newTeam.phone = team.phone;
                        newTeam.schoolID = team.school;

                        myData.teams.InsertOnSubmit(newTeam);

                        foreach (int playerID in team.palyers)
                        {
                            teamPlayer newTeamPlayer = new teamPlayer();
                            newTeamPlayer.teamID = newTeam.id;
                            newTeamPlayer.playerID = playerID;

                            myData.teamPlayers.InsertOnSubmit(newTeamPlayer);
                        }

                        myData.SubmitChanges();
                        myScope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "TeamController.PostTeam");

            }
        }
Пример #10
0
        // GET api/<controller>/5
        public Pool GetPoolById(int id)
        {
            try
            {
                string connectionString = Properties.Settings.Default.FreeFootieConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    var temp = (from c in myData.pools
                                   where c.id == id
                                   orderby c.id ascending
                                   select c).SingleOrDefault();

                    Pool pool = new Pool();
                    pool.id = temp.id;
                    pool.name = temp.name;

                    return pool;
                }

            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "PoolController.GetPoolById");
                return null;
            }
        }
Пример #11
0
        public void SetScore(int id, int homeTeamScore, int awayTeamScore)
        {
            try
            {
                string connectionString = Properties.Settings.Default.FreeFootieConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    using (TransactionScope myScope = new TransactionScope())
                    {
                        game newGame = new game();
                        var theGame = (from c in myData.games
                                     where c.id == id
                                     select c).SingleOrDefault();

                        theGame.homeTeamScore = homeTeamScore;
                        theGame.awayTeamScore = awayTeamScore;

                        myData.SubmitChanges();
                        myScope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "GameController.PostGame");
            }
        }
Пример #12
0
        // POST api/<controller>
        public void PostPool(Pool pool)
        {
            try
            {
                string connectionString = Properties.Settings.Default.FreeFootieConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    using (TransactionScope myScope = new TransactionScope())
                    {
                        pool newPool = new pool();
                        var newID = (from c in myData.pools
                                     select c.id).Max();
                        newPool.id = newID + 1;
                        newPool.name = pool.name;

                        myData.pools.InsertOnSubmit(newPool);
                        myData.SubmitChanges();
                        myScope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "PoolController.PostPool");

            }
        }
Пример #13
0
        // GET api/<controller>/5
        public Player GetPlayerById(int id)
        {
            try
            {
                string connectionString = Properties.Settings.Default.FreeFootieConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    var temp = (from c in myData.players
                                where c.id == id
                                select c).SingleOrDefault();

                    Player player = new Player();
                    player.id = temp.id;
                    player.name = temp.name;
                    player.dob = temp.dob.ToString("yyyy-MM-dd");
                    player.number = temp.number;

                    return player;
                }

            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "PlayerController.GetPlayerById");
                return null;
            }
        }
Пример #14
0
        // POST api/<controller>
        public void PostPlayer(Player player)
        {
            try
            {
                string connectionString = Properties.Settings.Default.FreeFootieConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    using (TransactionScope myScope = new TransactionScope())
                    {
                        player newPalyer = new player();
                        var newID = (from c in myData.players
                                     select c.id).Max();
                        newPalyer.id = newID + 1;
                        newPalyer.name = player.name;
                        newPalyer.dob = Convert.ToDateTime(player.dob);
                        newPalyer.number = player.number;

                        myData.players.InsertOnSubmit(newPalyer);
                        myData.SubmitChanges();
                        myScope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "PlayerController.PostPlayer");
            }
        }
Пример #15
0
        // GET api/<controller>/5
        public Game GetGameById(int id)
        {
            try
            {
                string connectionString = Properties.Settings.Default.FreeFootieConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    var temp = (from c in myData.games
                                   join d in myData.locations on c.locationID equals d.id
                                   where c.id == id
                                   select new { game = c, locationName = d.name }).SingleOrDefault();

                    Game game = new Game();
                    game.id = id;
                    game.away = temp.game.awayTeamID;
                    game.duration = temp.game.duration;
                    game.home = temp.game.homeTeamID;
                    game.location = temp.game.locationID;
                    game.locationName = temp.locationName;
                    game.date = "<<" + temp.game.startTime.ToString("yyyy-MM-dd HH:mm:ss") + "~" + temp.game.duration + "h>>";
                    game.state = temp.game.state;
                    game.homeTeamScore = temp.game.homeTeamScore;
                    game.awayTeamScore = temp.game.awayTeamScore;

                    return game;
                }

            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "GameController.GetGameById");
                return null;
            }
        }
Пример #16
0
        // GET api/<controller>/5
        public Location GetLocationById(int id)
        {
            try
            {
                string connectionString = Properties.Settings.Default.FreeFootieConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    var temp = (from c in myData.locations
                                where c.id == id
                                orderby c.id ascending
                                select c).SingleOrDefault();

                    Location location = new Location();
                    location.id = temp.id;
                    location.name = temp.name;
                    location.latitude = temp.latitude;
                    location.longitude = temp.longitude;

                    return location;
                }

            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "LocationController.GetLocationById");
                return null;
            }
        }
Пример #17
0
        // POST api/<controller>
        public void PostGame(Game game)
        {
            try
            {
                string connectionString = Properties.Settings.Default.FreeFootieConnectionString;
                using (FreeFootieDataContext myData = new FreeFootieDataContext(connectionString))
                {
                    using (TransactionScope myScope = new TransactionScope())
                    {
                        game newGame = new game();
                        var newID = (from c in myData.games
                                     select c.id).Max();
                        newGame.id = newID + 1;

                        newGame.awayTeamID = game.away;
                        newGame.duration = game.duration;
                        newGame.homeTeamID = game.home;
                        newGame.locationID = game.location;
                        string[] date_duration = game.date.Replace("<", string.Empty).Replace(">", string.Empty).Replace("h", string.Empty).Split('~');
                        if (date_duration.Count() > 0)
                        {
                            newGame.startTime = Convert.ToDateTime(date_duration[0]);
                        }
                        if (date_duration.Count() > 1)
                        {
                            newGame.duration = Convert.ToInt32(date_duration[1]);
                        }
                        newGame.state = game.state;
                        newGame.homeTeamScore = game.homeTeamScore;
                        newGame.awayTeamScore = game.awayTeamScore;

                        myData.games.InsertOnSubmit(newGame);

                        myData.SubmitChanges();
                        myScope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                Common.ErrorCatch(ex, "GameController.PostGame");
            }
        }