public IActionResult PostNewGame(Game gameToAdd)
        {
            var currentUserId = _userRepo.GetUserIdByUid(UserId);
            var newGameId     = _gameRepo.AddNewGame(currentUserId, gameToAdd);

            return(Ok(newGameId));
        }
示例#2
0
        public void CreateGameServer()
        {
            Game game = new Game();

            game.serverid   = 12312313;
            game.serverName = "asdasd";

            Game returnobject = customerrepo.AddNewGame(game);

            var FindObject = customerrepo.GetById(game.Id);

            Assert.IsNotNull(returnobject);
            Assert.IsNotNull(FindObject);
            Assert.AreEqual(returnobject.serverid, FindObject.serverid);


            //   var returnObject= customerrepo.GetById()
        }
示例#3
0
        public void SeedData()
        {
            var IsNotEmpty = _context.GameSessions.Any();

            if (IsNotEmpty)
            {
                var temp = _context.GameSessions.Include(c => c.Chatlog).AsEnumerable <GameSession>();
                foreach (var game in temp)
                {
                    if (game.Chatlog != null)
                    {
                        foreach (var chat in game.Chatlog.ToList())
                        {
                            _context.GameSessions.Where(u => u == game).FirstOrDefault().Chatlog.Remove(chat);
                        }
                    }
                }
                _context.SaveChanges();
                _context.GameSessions.RemoveRange(temp);
                _context.SaveChanges();
            }

            IsNotEmpty = _context.Users.Any();
            if (IsNotEmpty)
            {
                var temp2 = _context.Users.Include(g => g.Friends).AsEnumerable <User>();
                foreach (var user in temp2)
                {
                    if (user.Friends != null)
                    {
                        foreach (var friend in user.Friends.ToList())
                        {
                            _context.Users.Where(u => u == user).FirstOrDefault().Friends.Remove(friend);
                        }
                    }
                }
                _context.SaveChanges();
                _context.Users.RemoveRange(temp2);
                _context.SaveChanges();
            }
            //Add cappe, alex, nick, emil, and philip as users
            AddNewUsers();
            _context.SaveChanges();

            //cappe and philip are friends with everyone else. Everyone else are only friends with cappe and philip
            repo.AddFriend("19cd7126-2f69-4b1d-9326-d92fcb438f2d",
                           "08e03d0c-bfb1-437a-a877-1d370bd92cc5");

            repo.AddFriend("b6d5de24-98f5-4e29-9fe8-5419f5140a02",
                           "08e03d0c-bfb1-437a-a877-1d370bd92cc5");

            repo.AddFriend("7e3fc3e1-5049-4567-96a2-a50db094cc3d",
                           "19cd7126-2f69-4b1d-9326-d92fcb438f2d");

            repo.AddFriend("b6d5de24-98f5-4e29-9fe8-5419f5140a02",
                           "19cd7126-2f69-4b1d-9326-d92fcb438f2d");

            repo.AddFriend("bc64fdac-65bf-4e91-b9cf-cdbc6c542e2c",
                           "19cd7126-2f69-4b1d-9326-d92fcb438f2d");

            repo.AddFriend("b6d5de24-98f5-4e29-9fe8-5419f5140a02",
                           "7e3fc3e1-5049-4567-96a2-a50db094cc3d");

            repo.AddFriend("bc64fdac-65bf-4e91-b9cf-cdbc6c542e2c",
                           "b6d5de24-98f5-4e29-9fe8-5419f5140a02");


            //Some games
            string gameId = repo.AddNewGame("19cd7126-2f69-4b1d-9326-d92fcb438f2d",
                                            "08e03d0c-bfb1-437a-a877-1d370bd92cc5");

            _context.GameSessions.Find(gameId).MovesCounter = 15;
            _context.GameSessions.Find(gameId).Board        =
                "br,ee,ee,ee,ee,ee,ee,br," +
                "bp,ee,bp,bk,ee,bp,ee,ee," +
                "ee,ee,bp,ee,ee,ee,ee,bp," +
                "ee,ee,ee,bp,ee,ee,wb,bb," +
                "ee,ee,ee,ee,ee,ee,ee,ee," +
                "ee,ee,ee,wb,ee,ee,ee,ee," +
                "wp,wp,wp,ee,wr,bb,wp,wp," +
                "wr,wn,ee,ee,ee,ee,ee,wk";
            _context.GameSessions.Find(gameId).IsWhitePlayerTurn = true;

            gameId = repo.AddNewGame("b6d5de24-98f5-4e29-9fe8-5419f5140a02",
                                     "08e03d0c-bfb1-437a-a877-1d370bd92cc5");
            _context.GameSessions.Find(gameId).MovesCounter = 23;
            _context.GameSessions.Find(gameId).Board        =
                "ee,ee,ee,ee,ee,wb,ee,ee," +
                "ee,ee,ee,ee,ee,ee,wr,ee," +
                "ee,br,ee,ee,ee,ee,ee,bk," +
                "ee,br,ee,bp,ee,wr,ee,ee," +
                "bp,ee,ee,ee,ee,ee,wp,bp," +
                "wp,ee,wp,ee,ee,ee,bn,ee," +
                "ee,wp,ee,ee,ee,ee,wp,ee," +
                "ee,ee,ee,ee,ee,ee,wk,ee,";
            _context.GameSessions.Find(gameId).IsWhitePlayerTurn = true;

            gameId = repo.AddNewGame("7e3fc3e1-5049-4567-96a2-a50db094cc3d",
                                     "19cd7126-2f69-4b1d-9326-d92fcb438f2d");

            _context.GameSessions.Find(gameId).MovesCounter = 18;
            _context.GameSessions.Find(gameId).Board        =
                "br,bk,ee,ee,ee,ee,ee,br," +
                "bp,bp,ee,wq,ee,bp,ee,bp," +
                "ee,bq,ee,bp,ee,wn,ee,ee," +
                "ee,ee,ee,ee,ee,ee,ee,ee," +
                "ee,ee,ee,ee,ee,ee,ee,ee," +
                "ee,ee,ee,ee,ee,ee,wp,ee," +
                "wp,wp,ee,ee,ee,wp,wb,wp," +
                "ee,ee,wr,ee,ee,ee,wk,ee,";
            _context.GameSessions.Find(gameId).IsWhitePlayerTurn = false;

            gameId = repo.AddNewGame("b6d5de24-98f5-4e29-9fe8-5419f5140a02",
                                     "19cd7126-2f69-4b1d-9326-d92fcb438f2d");

            _context.GameSessions.Find(gameId).MovesCounter = 16;
            _context.GameSessions.Find(gameId).Board        =
                "ee,ee,ee,ee,ee,br,bk,ee," +
                "bp,bp,ee,ee,ee,ee,bp,bp," +
                "ee,ee,bp,ee,ee,ee,bn,ee," +
                "ee,ee,ee,bp,ee,ee,wn,ee," +
                "ee,ee,wp,ee,ee,wp,wk,ee," +
                "ee,ee,ee,wb,ee,ee,wp,ee," +
                "wp,wp,ee,ee,ee,ee,ee,bq," +
                "wr,ee,wb,wq,ee,wr,ee,ee,";
            _context.GameSessions.Find(gameId).IsWhitePlayerTurn = false;

            gameId = repo.AddNewGame("bc64fdac-65bf-4e91-b9cf-cdbc6c542e2c",
                                     "19cd7126-2f69-4b1d-9326-d92fcb438f2d");

            _context.GameSessions.Find(gameId).MovesCounter = 14;
            _context.GameSessions.Find(gameId).Board        =
                "br,ee,ee,ee,ee,br,ee,bk," +
                "ee,bp,bp,bq,wn,bp,bp,bp," +
                "bp,ee,bp,ee,bb,ee,ee,ee," +
                "ee,ee,ee,bn,ee,ee,wb,wq," +
                "ee,ee,ee,bp,wr,ee,ee,ee," +
                "ee,ee,ee,ee,ee,ee,ee,ee," +
                "wp,wp,wp,ee,ee,wp,wp,wp," +
                "ee,ee,ee,ee,ee,ee,wk,ee,";
            _context.GameSessions.Find(gameId).IsWhitePlayerTurn = true;

            gameId = repo.AddNewGame("b6d5de24-98f5-4e29-9fe8-5419f5140a02",
                                     "7e3fc3e1-5049-4567-96a2-a50db094cc3d");

            _context.GameSessions.Find(gameId).MovesCounter = 12;
            _context.GameSessions.Find(gameId).Board        =
                "br,ee,bb,bk,ee,ee,bn,br," +
                "bp,ee,ee,bp,ee,bp,wn,bp," +
                "bn,ee,ee,wb,ee,ee,ee,ee," +
                "ee,bp,ee,wn,wp,ee,ee,wp," +
                "ee,ee,ee,ee,ee,ee,wp,ee," +
                "ee,ee,ee,wp,ee,wq,ee,ee," +
                "wp,ee,wp,ee,wk,ee,ee,ee," +
                "bq,ee,ee,ee,ee,ee,bb,ee,";
            _context.GameSessions.Find(gameId).IsWhitePlayerTurn = true;

            gameId = repo.AddNewGame("bc64fdac-65bf-4e91-b9cf-cdbc6c542e2c",
                                     "b6d5de24-98f5-4e29-9fe8-5419f5140a02");

            _context.GameSessions.Find(gameId).MovesCounter = 3;
            _context.GameSessions.Find(gameId).Board        =
                "ee,ee,ee,ee,ee,ee,ee,ee," +
                "ee,ee,ee,ee,ee,ee,ee,ee," +
                "ee,ee,ee,ee,ee,bk,ee,ee," +
                "ee,wr,ee,ee,ee,ee,ee,ee," +
                "wr,ee,ee,ee,ee,ee,ee,ee," +
                "ee,ee,ee,ee,ee,ee,ee,ee," +
                "ee,ee,ee,ee,ee,ee,ee,ee," +
                "ee,ee,ee,ee,wk,ee,ee,ee,";
            _context.GameSessions.Find(gameId).IsWhitePlayerTurn = true;

            //b6d5de24-98f5-4e29-9fe8-5419f5140a02

            gameId = repo.AddNewGame("bc64fdac-65bf-4e91-b9cf-cdbc6c542e2c",
                                     "b6d5de24-98f5-4e29-9fe8-5419f5140a02");

            _context.GameSessions.Find(gameId).MovesCounter = 30;
            _context.GameSessions.Find(gameId).Board        =
                "br,bn,bb,bq,bk,bb,bn,br," +
                "ee,bp,bp,bp,bp,wq,bp,bp," +
                "ee,ee,ee,ee,ee,ee,ee,ee," +
                "ee,ee,ee,ee,ee,ee,ee,ee," +
                "bp,ee,wb,ee,wp,ee,ee,ee," +
                "ee,ee,ee,ee,ee,ee,ee,ee," +
                "wp,wp,wp,wp,ee,wp,wp,wp," +
                "wr,wn,wb,ee,wk,ee,wn,wr";
            _context.GameSessions.Find(gameId).IsActive          = false;
            _context.GameSessions.Find(gameId).IsWhitePlayerTurn = false;


            gameId = repo.AddNewGame("7e3fc3e1-5049-4567-96a2-a50db094cc3d",
                                     "19cd7126-2f69-4b1d-9326-d92fcb438f2d");

            _context.GameSessions.Find(gameId).MovesCounter = 75;
            _context.GameSessions.Find(gameId).Board        =
                "ee,ee,ee,ee,bk,ee,ee,ee," +
                "ee,bb,ee,ee,wp,ee,ee,ee," +
                "ee,ee,ee,ee,wk,wn,ee,ee," +
                "ee,ee,ee,ee,ee,ee,ee,ee," +
                "ee,ee,ee,ee,ee,ee,ee,ee," +
                "ee,ee,ee,ee,ee,ee,ee,bp," +
                "ee,ee,ee,ee,ee,ee,ee,ee," +
                "ee,ee,ee,ee,ee,ee,ee,ee";
            _context.GameSessions.Find(gameId).IsActive          = false;
            _context.GameSessions.Find(gameId).IsWhitePlayerTurn = false;


            gameId = repo.AddNewGame("19cd7126-2f69-4b1d-9326-d92fcb438f2d",
                                     "7e3fc3e1-5049-4567-96a2-a50db094cc3d");

            _context.GameSessions.Find(gameId).MovesCounter = 46;
            _context.GameSessions.Find(gameId).Board        =
                "ee,ee,bk,wq,ee,ee,bn,br," +
                "bp,bp,bp,ee,ee,bp,bp,ee," +
                "ee,ee,bq,ee,ee,ee,ee,ee," +
                "ee,ee,ee,ee,bp,ee,ee,ee," +
                "ee,wp,ee,ee,ee,ee,ee,bp," +
                "wp,ee,ee,ee,wp,ee,ee,ee," +
                "ee,ee,ee,ee,wb,wp,wp,wp," +
                "ee,ee,ee,wr,ee,ee,wk,ee";
            _context.GameSessions.Find(gameId).IsActive          = false;
            _context.GameSessions.Find(gameId).IsWhitePlayerTurn = false;


            gameId = repo.AddNewGame("19cd7126-2f69-4b1d-9326-d92fcb438f2d",
                                     "bc64fdac-65bf-4e91-b9cf-cdbc6c542e2c");

            _context.GameSessions.Find(gameId).MovesCounter = 54;
            _context.GameSessions.Find(gameId).Board        =
                "ee,bk,ee,ee,ee,ee,ee,br," +
                "wq,bp,bp,ee,ee,ee,ee,br," +
                "ee,bn,ee,ee,ee,ee,bn,ee," +
                "ee,wp,ee,ee,ee,ee,bp,ee," +
                "ee,ee,ee,ee,wp,ee,ee,bp," +
                "ee,ee,ee,bq,wp,ee,wp,wb," +
                "ee,ee,ee,ee,ee,ee,ee,wp," +
                "wr,ee,ee,ee,ee,ee,wk,ee";
            _context.GameSessions.Find(gameId).IsActive          = false;
            _context.GameSessions.Find(gameId).IsWhitePlayerTurn = false;



            _context.SaveChanges();
        }