Ejemplo n.º 1
0
        public async System.Threading.Tasks.Task DeletePlayerTestAsync()
        {
            DbContextOptions <GamesDbContext> options = new DbContextOptionsBuilder <GamesDbContext>().UseInMemoryDatabase("DeletePlayer").Options;

            using (GamesDbContext context = new GamesDbContext(options))
            {
                Player newPlayer = new Player()
                {
                    ID     = "1",
                    RoomID = "1",
                    Name   = "Farkus",
                    Score  = 500,
                    Toad   = true
                };

                context.Add(newPlayer);
                await context.SaveChangesAsync();

                Player foundPlayer = await context.Players.FirstOrDefaultAsync(player => player.ID == "1");

                foundPlayer.Score = 250;

                context.Remove(foundPlayer);
                await context.SaveChangesAsync();

                Player deletedPlayer = await context.Players.FirstOrDefaultAsync(player => player.ID == "1");

                Assert.True(deletedPlayer == null);
            }
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> PostUser([FromBody] User user, [FromUri] int bestScore = 0)
        {
            Guid userId;

            using (var dbContext = new GamesDbContext())
            {
                var currentUser = await dbContext.User.Where(x => x.Email == user.Email).FirstOrDefaultAsync();

                if (currentUser == null)
                {
                    userId  = Guid.NewGuid();
                    user.Id = userId;
                    await dbContext.Add(user);
                }
                else
                {
                    currentUser.Email = user.Email;
                    currentUser.Name  = user.Name;
                    userId            = currentUser.Id;
                    await dbContext.Edit(currentUser);
                }
                if (bestScore > 0)
                {
                    var currentGameScore = await dbContext.Score.Where(x => x.UserId == userId && x.ScorePoint == bestScore).FirstOrDefaultAsync();

                    if (currentGameScore == null)
                    {
                        await dbContext.Add(new Score {
                            UserId     = userId,
                            GameId     = 1,
                            Id         = Guid.NewGuid(),
                            ScorePoint = bestScore
                        });
                    }
                }
                await dbContext.SaveChangesAsync();

                return(Ok());
            }
        }
Ejemplo n.º 3
0
        public async Task PostUser([FromBody] User user)
        {
            using (var dbContext = new GamesDbContext())
            {
                var currentUser = await dbContext.User.Where(x => x.Email == user.Email).FirstOrDefaultAsync();

                if (currentUser == null)
                {
                    user.Id = Guid.NewGuid();
                    await dbContext.Add(user);
                }
                else
                {
                    currentUser.Email = user.Email;
                    currentUser.Name  = user.Name;
                    await dbContext.Edit(currentUser);
                }
                await dbContext.SaveChangesAsync();
            }
        }
        public IActionResult Post([FromBody] GameDto value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var game = new Game
                {
                    Console = value.Console,
                    Name    = value.Name,
                    Type    = value.Type
                };
                _context.Add(game);
                _context.SaveChanges();
                return(Ok());
            }
            catch (DbException e)
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 5
0
 public void CreateCredential(Credential credential)
 {
     _context.Add(credential);
 }