예제 #1
0
 public void Commit()
 {
     using (var ctx = new DatabContext())
     {
         ctx.SaveChanges();
     }
 }
예제 #2
0
 public void Add(Admin entity)
 {
     using (var ctx = new DatabContext())
     {
         ctx.Admins.Add(entity);
         ctx.SaveChanges();
     }
 }
예제 #3
0
 /**************************************************************/
 public void Add(Command entity)
 {
     using (var ctx = new DatabContext())
     {
         ctx.Commands.Add(entity);
         ctx.SaveChanges();
     }
 }
예제 #4
0
 public void Delete(Admin entity)
 {
     using (var ctx = new DatabContext())
     {
         ctx.Admins.Remove(entity);
         ctx.SaveChanges();
     }
 }
예제 #5
0
 public void Delete(Claim entity)
 {
     using (var ctx = new DatabContext())
     {
         ctx.Claims.Remove(entity);
         ctx.SaveChanges();
     }
 }
예제 #6
0
 public void Add(Claim entity)
 {
     using (var ctx = new DatabContext())
     {
         ctx.Claims.Add(entity);
         ctx.SaveChanges();
     }
 }
예제 #7
0
 public void Delete(Command entity)
 {
     using (var ctx = new DatabContext())
     {
         ctx.Commands.Attach(entity);
         ctx.Commands.Remove(entity);
         ctx.SaveChanges();
     }
 }
예제 #8
0
 public void Update(Command entity)
 {
     using (var ctx = new DatabContext())
     {
         ctx.Commands.Attach(entity);
         ctx.Entry(entity).State = EntityState.Modified;
         ctx.SaveChanges();
     }
 }
예제 #9
0
 public void Delete(Expression <Func <Admin, bool> > where)
 {
     using (var ctx = new DatabContext())
     {
         IEnumerable <Admin> objects = ctx.Admins.Where(where).AsEnumerable();
         foreach (Admin obj in objects)
         {
             ctx.Admins.Remove(obj);
         }
         ctx.SaveChanges();
     }
 }
예제 #10
0
        public void Delete(Expression <Func <Claim, bool> > where)
        {
            IEnumerable <Claim> objects;

            using (var ctx = new DatabContext())
            {
                objects = ctx.Claims.Where(where).AsEnumerable();
                foreach (Claim obj in objects)
                {
                    ctx.Claims.Remove(obj);
                }
                ctx.SaveChanges();
            }
        }
예제 #11
0
        public void Delete(Expression <Func <Command, bool> > where)
        {
            IEnumerable <Command> objects;

            using (var ctx = new DatabContext())
            {
                objects = ctx.Commands.Where(where).AsEnumerable();


                ctx.Commands.RemoveRange(objects);



                ctx.SaveChanges();
            }
        }
예제 #12
0
 public void Commit()
 {
     dataContext.SaveChanges();
 }
예제 #13
0
        public Game PlayAGame()
        {
            //instantiate a Player and give a value to the Name all at once.
            Player computer = new Player()
            {
                Name = "Computer"
            };

            //try to find an existing player named "computer"
            if (_context.Players.Any(x => x.Name == "Computer"))
            {
                computer = _context.Players.Where(x => x.Name == "Computer").FirstOrDefault();
            }
            else
            {
                computer.Name = "Computer";
                _context.Players.Add(computer);                //add the computer to List<Player> players
                _context.SaveChanges();
            }

            Player p1;            //the out variable for the player

            if (!_cache.TryGetValue("loggedInPlayer", out p1))
            {
                _logger.LogInformation("There was no loggedInPlayer in the cache");
                throw new NullReferenceException("There was no loggedInPlayer in the cache");
            }

            p1 = _context.Players.Where(x => x.PlayerId == p1.PlayerId).FirstOrDefault();
            Game game = new Game();            // create a game

            //_context.Players.Add(p1);
            game.Player1  = p1;           //
            game.Computer = computer;     //

            while (game.winner.Name == "null")
            {
                Round round = new Round();                      //declare a round for this iteration
                round.player1  = p1;                            // add user (p1) to this round
                round.Computer = computer;                      // add computer to this round

                //get the choices for the 2 players and insert the players choices directly into the round
                round.p1Choice       = Rps_GameMethods.GetRandomChoice();          //this will give a random number starting at 0 to arg-1;
                round.ComputerChoice = Rps_GameMethods.GetRandomChoice();
                round.Outcome        = Rps_GameMethods.GetRoundWinner(round);      //check the choices to see who won.
                _context.Rounds.Add(round);
                _context.SaveChanges();
                game.rounds.Add(round);                           //add this round to the games' List of rounds
                int gameWinner = Rps_GameMethods.GetWinner(game); //get a number ot say is p1(1) or computer(2) won

                //assign the winner to the game and increment wins and losses for both
                if (gameWinner == 1)
                {
                    game.winner = p1;
                    p1.Wins++;                    //increments wins and losses.
                    computer.Losses++;            //increments wins and losses.
                }
                else if (gameWinner == 2)
                {
                    game.winner = computer;
                    p1.Losses++;      //increments wins and losses.
                    computer.Wins++;  //increments wins and losses.
                }
            }                         //end of rounds loop
            _context.Games.Add(game); //save the game
            _context.SaveChanges();
            return(game);
        }