public List<GameModel> AllGames()
        {
            List<GameModel> ret = new List<GameModel>();

            using (ADayInTheLifeEntities db = new ADayInTheLifeEntities())
            {
                try
                {
                    List<Game> games = db.Games.ToList();

                    foreach(Game g in games)
                    {
                        GameModel gm = new GameModel()
                        {
                            GameId = g.GameId,
                            Players = g.Players,
                            WinCondition1 = g.WinCondition1,
                            WinCondition2 = g.WinCondition2,
                            WinCondition3 = g.WinCondition3,
                            WinCondition4 = g.WinCondition4
                        };

                        ret.Add(gm);
                    }
                }
                catch (Exception e)
                {
                    //TODOL: Log This
                }
            }

            return ret;
        }
        public GameModel GameById(int id)
        {
            GameModel ret = new GameModel();

            using (ADayInTheLifeEntities db = new ADayInTheLifeEntities())
            {
                try
                {
                    Game game = db.Games.Where(o => o.GameId == id).FirstOrDefault();

                    if (game == null)
                    {
                        throw new Exception(String.Format("Issue: Game {0} cannot be found", id));
                    }

                    ret = new GameModel()
                    {
                        GameId = game.GameId,
                        Players = game.Players,
                        WinCondition1 = game.WinCondition1,
                        WinCondition2 = game.WinCondition2,
                        WinCondition3 = game.WinCondition3,
                        WinCondition4 = game.WinCondition4
                    };
                }
                catch (Exception e)
                {
                    //TODO: Log This.
                }
            }
            return ret;
        }
        public List<TurnModel> AllTurns(int playerId)
        {
            List<TurnModel> listing = new List<TurnModel>();

            using (ADayInTheLifeEntities db = new ADayInTheLifeEntities())
            {
                try
                {
                    List<Turn> turns = db.Turns.Where(o => o.PlayerId == playerId).ToList();

                    foreach (Turn t in turns)
                    {
                        TurnModel tm = new TurnModel()
                        {
                            TurnId = t.TurnId,
                            PlayerId = t.PlayerId,
                            GameId = t.GameId,
                            TimeLeft = t.TimeLeft,
                            TurnInGame = t.TurnInGame
                        };

                        listing.Add(tm);
                    }
                }
                catch (Exception e)
                {
                    //TODO: Log this
                }
            }

            return listing;
        }
        public Account AccountById(int id)
        {
            Account acc = new Account();

            using (ADayInTheLifeEntities data = new ADayInTheLifeEntities())
            {
                acc = data.Accounts.Where(o => o.AccountId == id).FirstOrDefault();
            }

            return acc;
        }
        public TurnMoveModel AddMove(TurnMoveModel item)
        {
            TurnMoveModel ret = null;

            using (ADayInTheLifeEntities db = new ADayInTheLifeEntities())
            {
                try
                {
                    TurnMove tm = new TurnMove()
                    {
                        TurnId = item.TurnId,
                        TurnFrom = item.TurnFrom,
                        TurnTo = item.TurnTo,
                        Bought = item.Bought,
                        TimeUsed = item.TimeUsed
                    };

                    db.TurnMoves.Add(tm);
                    db.SaveChanges();

                    ret = new TurnMoveModel()
                    {
                        TurnMoveId = tm.TurnMoveId,
                        Bought = tm.Bought,
                        TurnTo  = tm.TurnTo,
                        TurnFrom = tm.TurnFrom,
                        TimeUsed = tm.TimeUsed,
                        TurnId = tm.TurnId,
                    };

                }
                catch (Exception e)
                {
                    //TODO: Log this
                }
            }

            return ret;
        }
        public List<Account> GetAccounts()
        {
            List<Account> list = new List<Account>();

            using (ADayInTheLifeEntities data = new ADayInTheLifeEntities())
            {
                list = data.Accounts.ToList();
            }

            return list;
        }
        public GameModel NewGame(GameModel item)
        {
            GameModel ret = new GameModel();

            using (ADayInTheLifeEntities db = new ADayInTheLifeEntities())
            {
                try
                {
                    if (item.GameId == 0)
                    {
                        if (item.PlayerNames.Count > 0)
                        {
                            Game game = new Game()
                            {
                                Players = item.Players,
                                WinCondition1 = item.WinCondition1,
                                WinCondition2 = item.WinCondition2,
                                WinCondition3 = item.WinCondition3,
                                WinCondition4 = item.WinCondition4
                            };

                            db.Games.Add(game);
                            db.SaveChanges();

                            List<int> used = new List<int>();

                            foreach (String name in item.PlayerNames)
                            {
                                //Check for existing Id:
                                int id = db.Players.Where(o => o.PlayerName.Equals(name)).Select(o => o.PlayerId).FirstOrDefault();

                                if (id == 0)
                                {
                                    Player p = new Player()
                                    {
                                        PlayerName = name
                                    };

                                    db.Players.Add(p);
                                    db.SaveChanges();

                                    id = p.PlayerId;
                                }

                                Random r = new Random(game.Players);

                                int position = (int)r.Next(game.Players);

                                while ((position < 0 || position > game.Players) || used.Contains(position))
                                {
                                    position = (int)r.Next(game.Players);
                                }

                                used.Add(position);

                                PlayerInGame pig = new PlayerInGame()
                                {
                                    GameId = game.GameId,
                                    PlayerId = id,
                                    PlayerPosition = position
                                };

                                db.PlayerInGames.Add(pig);
                                db.SaveChanges();
                            }

                            ret = new GameModel()
                            {
                                GameId = game.GameId,
                                Players = game.Players,
                                WinCondition1 = game.WinCondition1,
                                WinCondition2 = game.WinCondition2,
                                WinCondition3 = game.WinCondition3,
                                WinCondition4 = game.WinCondition4
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    //TODO: Log this.
                }
            }

            return ret;
        }
        public GameModel NewGame(GameModel item)
        {
            GameModel ret = null;

            using (ADayInTheLifeEntities db = new ADayInTheLifeEntities())
            {
                try
                {
                    Game g = new Game()
                    {
                        Players = item.Players,
                        WinCondition1 = item.WinCondition1,
                        WinCondition2 = item.WinCondition2,
                        WinCondition3 = item.WinCondition3,
                        WinCondition4 = item.WinCondition4,
                        CurrentTurn = item.CurrentTurn
                    };

                    db.Games.Add(g);
                    db.SaveChanges();

                    ret = new GameModel()
                    {
                        Players = g.Players,
                        WinCondition4 = g.WinCondition4,
                        WinCondition3 = g.WinCondition3,
                        WinCondition2 = g.WinCondition2,
                        WinCondition1 = g.WinCondition1,
                        CurrentTurn = g.CurrentTurn ?? 0
                    };
                }
                catch (Exception e)
                {
                    //TODO: Log This.
                }
            }

            return ret;
        }
        public TurnModel TurnById(int playerId, int turnId)
        {
            TurnModel ret = null;

            using (ADayInTheLifeEntities db = new ADayInTheLifeEntities())
            {
                try
                {
                    Turn t = db.Turns.Where(o => o.PlayerId == playerId && o.TurnId == turnId).FirstOrDefault();

                    if (t == null)
                    {
                        throw new Exception("Couldn't find that Turn record.");
                    }

                    ret = new TurnModel()
                    {
                        PlayerId = t.PlayerId,
                        GameId = t.GameId,
                        TurnInGame = t.TurnInGame,
                        TimeLeft = t.TimeLeft,
                        TurnId = t.TurnId
                    };
                }
                catch (Exception e)
                {
                    //TODO: Log This.
                }
            }

            return ret;
        }
        public TurnModel NewTurn(TurnModel item)
        {
            TurnModel ret = new TurnModel();

            using (ADayInTheLifeEntities db = new ADayInTheLifeEntities())
            {
                try
                {
                    Turn t = new Turn()
                    {
                        PlayerId = item.PlayerId,
                        GameId = item.GameId,
                        TimeLeft = item.TimeLeft,
                        TurnInGame = item.TurnInGame
                    };

                    db.Turns.Add(t);
                    db.SaveChanges();

                    ret = new TurnModel()
                    {
                        TurnId = t.TurnId,
                        PlayerId = t.PlayerId,
                        GameId = t.GameId,
                        TurnInGame = t.TurnInGame,
                        TimeLeft = t.TimeLeft
                    };
                }
                catch (Exception e)
                {
                    //TODO: Log this
                }
            }

            return ret;
        }