Exemple #1
0
        public void JoinAdventure(string adventureName)
        {
            //check list if players in adventure has same name as joining player
            //if same name, dont do anything.
            //if not, add the user to the adventure.

            UserClient client = new UserClient();

            try
            {
                User      user      = client.Find(User.Identity.Name);
                Adventure adventure = adventureClient.Find(adventureName);
                if (adventure.Players.Count >= adventure.MaxPlayers)
                {
                    ModelState.AddModelError("", "This adventure is not available for joining.");
                }
                if (adventure.Players.FirstOrDefault(x => x.UserName == user.UserName) == null)
                {
                    adventure.Players.Add(user);
                    int       a          = adventureClient.Update(adventure);
                    Adventure Adventure2 = adventureClient.Find(adventure.Name);
                }
                else
                {
                    ModelState.AddModelError("", "You are already on that adventure.");
                }
            }
            catch (Exception Ex)
            {
                ModelState.AddModelError("", "Failed to join adventure, no open spots.");
            }
        }
        public void CreateAdventureTest()
        {
            Adventure adventure = new Adventure()
            {
                Active     = true,
                Date       = DateTime.Now,
                Logbook    = "The war has yet to end, and will be continued in the next mission",
                MaxPlayers = 3,
                Name       = "War At The Riverside"
            };

            adventureClient.Create(adventure);

            Assert.AreEqual(adventure.Name, adventureClient.Find(adventure.Name).Name);
        }