Example #1
0
        /// <summary>
        /// Updates an exsting player entity in the database
        /// </summary>
        /// <param name="player">Player model containing the player's details</param>
        /// <returns>RequestResult object</returns>
        public Models.RequestResult Update(Data.Player player)
        {
            try
            {
                var existingPlayer = Context.Players.FirstOrDefault(p => p.Id == player.Id);

                if (existingPlayer == null)
                {
                    return(Models.RequestResult.GetFail(StatusCodes.Status404NotFound));
                }

                existingPlayer.FirstName = player.FirstName;
                existingPlayer.LastName  = player.LastName;

                Context.SaveChanges();

                return(Models.RequestResult.GetSuccess());
            }
            catch (Microsoft.EntityFrameworkCore.DbUpdateException)
            {
                return(Models.RequestResult.GetFail(StatusCodes.Status400BadRequest));
            }
            catch (Exception)
            {
                return(Models.RequestResult.GetFail(StatusCodes.Status500InternalServerError));
            }
        }
Example #2
0
 public void MockUp(Data.Player player)
 {
     floor.Value = player.floor;
     gold.Value  = player.gold;
     player.pool.ForEach(poolCardList.Add);
     player.deck.ForEach(deckCardList.Add);
 }
Example #3
0
        public async Task VieWModelContainsPlayers()
        {
            var player1 = new Data.Player {
                first_name = "Kevin", second_name = "De Bruyne"
            };
            var player2 = new Data.Player {
                first_name = "Dele", second_name = "Alli"
            };
            var expectedPlayer1Name = player1.first_name + " " + player1.second_name;
            var expectedPlayer2Name = player2.first_name + " " + player2.second_name;
            var players             = new[] { player1, player2 };

            var repository = new Mock <IPlayerRepository>();

            repository.Setup(r => r.Get()).ReturnsAsync(players);

            var playerController = new PlayerController(repository.Object);
            var result           = await playerController.Index() as ViewResult;

            Assert.NotNull(result);
            Assert.IsAssignableFrom <IEnumerable <Models.Player> >(result.Model);

            var actualPlayers = (IEnumerable <Models.Player>)result.Model;

            Assert.Collection(actualPlayers,
                              player => { Assert.Equal(expectedPlayer1Name, player.Name); },
                              player => { Assert.Equal(expectedPlayer2Name, player.Name); });
        }
Example #4
0
 /**
  * Handles the add layer packet, (handler "ap"). This is so we can add a Data.Player to the room as they join.
  *
  * @param receivedPacket
  *   The packet to handle.
  */
 private void HandleAddPlayer(Data.PenguinPacket receivedPacket)
 {
     Data.Player newPlayer = new Data.Player();
     newPlayer.LoadData(receivedPacket.Xt.Arguments[0]);
     if (newPlayer.Id != ID)
     {
         currentRoom.AddPlayer(newPlayer);
     }
 }
Example #5
0
 public Data.Player Create()
 {
     Data.Player p = new Data.Player();
     p.floor = 0;
     p.gold  = 100;
     for (int i = 0; i < 4; i++)
     {
         var card = cardFactory.Create();
         p.pool.Add(card);
         p.deck.Add(card);
     }
     return(p);
 }
Example #6
0
        /**
         * Handles the join room packet, (handler "jr"). This is so we can change the room numbers and load the new room object and Player objects.
         *
         * @param receivedPacket
         *   The packet to handle.
         */
        private void HandleJoinRoom(Data.PenguinPacket receivedPacket)
        {
            int    roomExtId = int.Parse(receivedPacket.Xt.Arguments[0]);
            string strName   = (roomExtId < 1000) ? Crumbs.Rooms.GetAttributeById(roomExtId, "name") : "Igloo";

            currentRoom.ChangeRoom(strName, receivedPacket.Xt.Room, roomExtId);
            for (int intIndex = 1; intIndex < receivedPacket.Xt.Arguments.Length; intIndex++)
            {
                Data.Player newPlayer = new Data.Player();
                newPlayer.LoadData(receivedPacket.Xt.Arguments[intIndex]);
                currentRoom.AddPlayer(newPlayer);
            }
        }
        public void Initialise()
        {
            var options = new DbContextOptionsBuilder <Data.PingPongContext>().UseInMemoryDatabase(databaseName: "PingPong" + Guid.NewGuid().ToString()).Options;

            Context = new Data.PingPongContext(options);

            Player1 = new Data.Player()
            {
                Id = Guid.NewGuid(), FirstName = "Test1Firstname", LastName = "Test1Lastname"
            };
            Player2 = new Data.Player()
            {
                Id = Guid.NewGuid(), FirstName = "Test2Firstname", LastName = "Test2Lastname"
            };
            Player3 = new Data.Player()
            {
                Id = Guid.NewGuid(), FirstName = "Test3Firstname", LastName = "Test3Lastname"
            };
            Player4 = new Data.Player()
            {
                Id = Guid.NewGuid(), FirstName = "Test4Firstname", LastName = "Test4Lastname"
            };
            Player5 = new Data.Player()
            {
                Id = Guid.NewGuid(), FirstName = "Test5Firstname", LastName = "Test5Lastname"
            };
            Player6 = new Data.Player()
            {
                Id = Guid.NewGuid(), FirstName = "Test6Firstname", LastName = "Test6Lastname"
            };

            Context.Players.Add(Player1);
            Context.Players.Add(Player2);
            Context.Players.Add(Player3);
            Context.Players.Add(Player4);
            Context.Players.Add(Player5);
            Context.Players.Add(Player6);

            //populate the games
            AddGame(Context, Player1.Id, Player2.Id, 5, 3, Player1.Id);
            AddGame(Context, Player1.Id, Player3.Id, 7, 4, Player1.Id);
            AddGame(Context, Player1.Id, Player4.Id, 6, 3, Player1.Id);
            AddGame(Context, Player2.Id, Player3.Id, 5, 3, Player2.Id);
            AddGame(Context, Player2.Id, Player4.Id, 5, 3, Player2.Id);
            AddGame(Context, Player3.Id, Player4.Id, 5, 3, Player3.Id);

            Context.SaveChanges();

            this.Context = new Data.PingPongContext(options);
            this.Service = new PlayerRanker(Context);
        }
Example #8
0
        private async Task <bool> IsUnlocked(Data.Player player, Data.Game game, string specId)
        {
            bool result = true;

            foreach (var prereq in game.Prerequisites.Where(p => p.TargetId == specId))
            {
                var condition = await Store.DbSet.AnyAsync(c =>
                                                           c.TeamId == player.TeamId &&
                                                           c.SpecId == prereq.RequiredId &&
                                                           c.Score >= prereq.RequiredScore
                                                           );

                result &= condition;
            }

            return(result);
        }
Example #9
0
        private void Done_Button_Click(object sender, EventArgs e)
        {
            int    count     = 0;
            int    position  = 0;
            string firstName = "";
            string lastName  = "";
            int    number;

            foreach (TextBox textbox in textBoxes)
            {
                if (string.IsNullOrWhiteSpace(textbox.Text.Trim()))
                {
                    MessageBox.Show("Please make sure all boxes are filled in.");
                    return;
                }
                else
                {
                    if (count == 0)
                    {
                        firstName = textbox.Text.Trim();
                        count++;
                    }
                    else if (count == 1)
                    {
                        lastName = textbox.Text.Trim();
                        count++;
                    }
                    else if (count == 2)
                    {
                        number = Convert.ToInt32(textbox.Text.Trim());
                        Data.Player newPlayer = new Data.Player(firstName, lastName, number, position);
                        team.roster.Add(newPlayer);
                        count = 0;
                        position++;
                    }
                    else
                    {
                        MessageBox.Show("ERROR - something went wrong. Please restart application.");
                        Application.Exit();
                    }
                }
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        public void Initialise()
        {
            var options = new DbContextOptionsBuilder <Data.PingPongContext>().UseInMemoryDatabase(databaseName: "PingPong" + Guid.NewGuid().ToString()).Options;

            Context = new Data.PingPongContext(options);

            //populate some players
            var player1 = new Data.Player()
            {
                Id = Guid.NewGuid(), FirstName = "Test1Firstname", LastName = "Test1Lastname"
            };
            var player2 = new Data.Player()
            {
                Id = Guid.NewGuid(), FirstName = "Test2Firstname", LastName = "Test2Lastname"
            };
            var player3 = new Data.Player()
            {
                Id = Guid.NewGuid(), FirstName = "Test3Firstname", LastName = "Test3Lastname"
            };
            var player4 = new Data.Player()
            {
                Id = Guid.NewGuid(), FirstName = "Test4Firstname", LastName = "Test4Lastname"
            };
            var player5 = new Data.Player()
            {
                Id = Guid.NewGuid(), FirstName = "Test5Firstname", LastName = "Test5Lastname"
            };
            var player6 = new Data.Player()
            {
                Id = Guid.NewGuid(), FirstName = "Test6Firstname", LastName = "Test6Lastname"
            };

            Context.Players.Add(player1);
            Context.Players.Add(player2);
            Context.Players.Add(player3);
            Context.Players.Add(player4);
            Context.Players.Add(player5);
            Context.Players.Add(player6);

            Context.SaveChanges();

            PlayersService = new Business.Services.Players(Context);
        }
        public void Save(SQLite.DataStore store, System.Data.SQLite.SQLiteConnection connection)
        {
            if (this.Saved == true)
            {
                return;
            }

            if (string.IsNullOrEmpty(this.PlayerName))
            {
                return;
            }

            this.PlayerId = -1;
            if (store.PlayerIdCache.ContainsKey(this.PlayerName))
            {
                this.PlayerId = store.PlayerIdCache[this.PlayerName];
            }
            else
            {
                Data.Player player = store.GetPlayer(this.SiteId, this.PlayerName, connection);
                if (player == null)
                {
                    this.PlayerId = store.InsertPlayer(this.SiteId, this.PlayerName, connection);
                }
                else
                {
                    this.PlayerId = player.Id;
                }

                store.PlayerIdCache[this.PlayerName] = this.PlayerId;
            }

            long handId    = this.HandId;
            long offButton = -1; // TODO

            this.Id = store.InsertHandPlayer(handId, this.PlayerId, this.Stack,
                                             this.SeatNumber, offButton, this.HoleCard1, this.HoleCard2,
                                             this.FinalHand, connection);

            this.Saved = true;
        }
Example #12
0
        /// <summary>
        /// Creates a new player entity in the database
        /// </summary>
        /// <param name="player">Player model containing the player's details</param>
        /// <returns>RequestResult object</returns>
        public Models.RequestResult Create(Data.Player player)
        {
            try
            {
                player.CreatedOn = DateTime.Now;
                player.Id        = Guid.NewGuid();

                Context.Players.Add(player);
                Context.SaveChanges();

                return(Models.RequestResult.GetSuccess());
            }
            catch (Microsoft.EntityFrameworkCore.DbUpdateException)
            {
                return(Models.RequestResult.GetFail(StatusCodes.Status400BadRequest));
            }
            catch (Exception)
            {
                return(Models.RequestResult.GetFail(StatusCodes.Status500InternalServerError));
            }
        }
Example #13
0
        public bool CreatePlayer(PlayerCreate model)
        {
            var entity =
                new Data.Player()
            {
                OwnerId    = _userId,
                Rank       = model.Rank,
                FirstName  = model.FirstName,
                LastName   = model.LastName,
                Position   = model.Position,
                Injured    = model.Injured,
                Drafted    = model.Drafted,
                Note       = model.Note,
                CreatedUtc = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Players.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #14
0
        private Api.PlayerCertificate CertificateFromTemplate(Data.Player player)
        {
            string certificateHTML = player.Game.CertificateTemplate;

            if (certificateHTML.IsEmpty())
            {
                return(null);
            }
            certificateHTML = certificateHTML.Replace("{{leaderboard_name}}", player.ApprovedName);
            certificateHTML = certificateHTML.Replace("{{user_name}}", player.User.ApprovedName);
            certificateHTML = certificateHTML.Replace("{{score}}", player.Score.ToString());
            certificateHTML = certificateHTML.Replace("{{rank}}", player.Rank.ToString());
            certificateHTML = certificateHTML.Replace("{{game_name}}", player.Game.Name);
            certificateHTML = certificateHTML.Replace("{{competition}}", player.Game.Competition);
            certificateHTML = certificateHTML.Replace("{{season}}", player.Game.Season);
            certificateHTML = certificateHTML.Replace("{{track}}", player.Game.Track);
            certificateHTML = certificateHTML.Replace("{{date}}", player.SessionEnd.ToString("MMMM dd, yyyy"));
            return(new Api.PlayerCertificate
            {
                Game = Mapper.Map <Game>(player.Game),
                Player = Mapper.Map <Player>(player),
                Html = certificateHTML
            });
        }
Example #15
0
 public Player(Data.Player data)
 {
     Data = data;
 }
Example #16
0
        public async Task <Player> Delete(string id, bool sudo = false)
        {
            var player = await Store.List()
                         .Include(p => p.Game)
                         .Include(p => p.Challenges)
                         .ThenInclude(c => c.Events)
                         .FirstOrDefaultAsync(
                p => p.Id == id
                )
            ;

            if (!sudo && !player.Game.AllowReset && player.SessionBegin.Year > 1)
            {
                throw new ActionForbidden();
            }

            if (!sudo && !player.Game.RegistrationActive)
            {
                throw new RegistrationIsClosed();
            }

            var challenges = player.Challenges;
            var players    = new Data.Player[] { player };

            if (player.IsManager && player.Game.AllowTeam)
            {
                challenges = await Store.DbContext.Challenges
                             .Where(c => c.TeamId == player.TeamId)
                             .Include(c => c.Events)
                             .ToArrayAsync()
                ;

                players = await Store.DbSet
                          .Where(p => p.TeamId == player.TeamId)
                          .ToArrayAsync()
                ;
            }

            if (challenges.Count > 0)
            {
                var toArchive   = Mapper.Map <ArchivedChallenge[]>(challenges);
                var teamMembers = players.Select(a => a.UserId).ToArray();
                foreach (var challenge in toArchive)
                {
                    // gamespace may be deleted in TopoMojo which would cause error and prevent reset
                    try
                    {
                        challenge.Submissions = (await Mojo.AuditChallengeAsync(challenge.Id)).ToArray();
                    }
                    catch
                    {
                        challenge.Submissions = new SectionSubmission[] {};
                    }
                    challenge.TeamMembers = teamMembers;
                }
                Store.DbContext.ArchivedChallenges.AddRange(Mapper.Map <Data.ArchivedChallenge[]>(toArchive));
                await Store.DbContext.SaveChangesAsync();
            }

            // courtesy call; ignore error (gamespace may have already been removed from backend)
            try
            {
                foreach (var challenge in challenges)
                {
                    if (challenge.HasDeployedGamespace)
                    {
                        await Mojo.CompleteGamespaceAsync(challenge.Id);
                    }
                }
            }
            catch {}

            foreach (var p in players)
            {
                await Store.Delete(p.Id);
            }

            return(Mapper.Map <Player>(player));
        }
Example #17
0
        public void Decode(byte[] array)
        {
            reader = new KrosmagaReader();
            reader.SetData(array);
            int tag;

            while (reader.B.BaseStream.Position < reader.B.BaseStream.Length && (tag = reader.ReadTag()) != 0)
            {
                if (tag <= 48)
                {
                    if (tag <= 18)
                    {
                        if (tag == 10)
                        {
                            Data.Player player = new Data.Player();
                            int         size   = (int)reader.ReadRawVarint32();
                            player.Decode(reader.ReadMessage(size));
                            PlayersList.Add(player);
                            continue;
                        }
                        if (tag == 18)
                        {
                            BackgroundName = reader.ReadString();
                            continue;
                        }
                    }
                    else
                    {
                        if (tag == 24)
                        {
                            BoardColumnsCount = (int)reader.ReadRawVarint32();
                            continue;
                        }
                        if (tag == 32)
                        {
                            BoardRowsCount = (int)reader.ReadRawVarint32();
                            continue;
                        }
                        if (tag == 48)
                        {
                            MyIndex = (int)reader.ReadRawVarint32();
                            continue;
                        }
                    }
                }
                else if (tag <= 72)
                {
                    if (tag == 56)
                    {
                        MyCardsCount = (int)reader.ReadRawVarint32();
                        continue;
                    }
                    if (tag == 64)
                    {
                        OpponentCardsCount = (int)reader.ReadRawVarint32();
                        continue;
                    }
                    if (tag == 72)
                    {
                        GameType = (Enums.GameType)Enum.Parse(typeof(Enums.GameType), reader.ReadRawVarint32().ToString());
                        continue;
                    }
                }
                else
                {
                    if (tag == 80)
                    {
                        DofusBaseLife = (int)reader.ReadRawVarint32();
                        continue;
                    }
                    if (tag == 88)
                    {
                        DraftAllInOwnAmount = (int)reader.ReadRawVarint32();
                        continue;
                    }
                    if (tag == 96)
                    {
                        DraftAllInOpponentAmount = (int)reader.ReadRawVarint32();
                        continue;
                    }
                }
            }
        }
 public Business.Models.RequestResult Create([FromBody] Data.Player player)
 {
     return(PlayersService.Create(player));
 }