示例#1
0
        public async Task AcceptChallenge([FromBody] string FigherJson)
        {
            var     _userEmail        = userEmail().Result;
            Fighter challengedFighter = System.Text.Json.JsonSerializer.Deserialize <Fighter>(FigherJson);

            string myFighterId = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(FigherJson).ChallengerFighterId;

            Fighter myFighter = _arena.Fighters().Where(x => x.id == myFighterId).First();


            using (IDbConnection dbConnection =
                       DbProviderFactories.GetFactory("system.data.sqlclient").CreateConnection())
            {
                dbConnection.ConnectionString = "Server=tcp:cipherrex.database.windows.net,1433;Initial Catalog=cipherRexUmbraco;Persist Security Info=False;User ID=cipherrex;Password=R00ksp@wnR00ksp@wn;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";
                dbConnection.Open();
                Models.DAL.SqlDAL sqlDAL = new Models.DAL.SqlDAL(dbConnection);

                IPlayerRepo playerRepo = new PlayerRepo(sqlDAL);
                PlayerUoW   playerUoW  = new PlayerUoW(sqlDAL, playerRepo);

                playerUoW.updatePlayerBalance(myFighter.id, -10);
                playerUoW.updatePlayerBalance(challengedFighter.id, -10);
            }

            _combatManager.CreateCombatSession(myFighter, challengedFighter);

            //await _chatHubContext.AcceptChallenge(_userEmail, myFighter.ownerId, challengedFighter.ownerId, myFighter.id, challengedFighter.id);
            _chatHubContext.AcceptChallenge(_userEmail, myFighter.ownerId, challengedFighter.ownerId, myFighter.id, challengedFighter.id);
        }
        //public async Task<IEnumerable<Fighter>> PlayerFighters()
        public async void NewFighter([FromBody] string fighterJson)
        {
            var _userEmail = userEmail().Result;

            Fighter fighter = System.Text.Json.JsonSerializer.Deserialize <Fighter>(fighterJson);

            using (IDbConnection dbConnection =
                       DbProviderFactories.GetFactory("system.data.sqlclient").CreateConnection())
            {
                dbConnection.ConnectionString = "Server=tcp:cipherrex.database.windows.net,1433;Initial Catalog=cipherRexUmbraco;Persist Security Info=False;User ID=cipherrex;Password=R00ksp@wnR00ksp@wn;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";
                dbConnection.Open();
                Models.DAL.SqlDAL sqlDAL = new Models.DAL.SqlDAL(dbConnection);
                Models.Repositories.Fighter.IFighterRepository fighterRepository = new Models.Repositories.Fighter.FighterRepository(sqlDAL);
                Models.Repositories.PlayerRepos.IPlayerRepo    playerRepo        = new Models.Repositories.PlayerRepos.PlayerRepo(sqlDAL);

                PlayerUoW uow          = new PlayerUoW(sqlDAL, playerRepo);
                string    newFighterId = uow.CreateFighter(fighter.Name, _userEmail, fighter.Picture);
            }
        }