コード例 #1
0
        public async Task <IActionResult> PutGame(int id, [FromBody] Exam.Data.Game game)
        {
            if (id != game.Id)
            {
                return(BadRequest());
            }
            _context.Entry(game).State = EntityState.Modified;
            if (game.GameStatus != null)
            {
                game.GameStatus = _context.GameStatuses.Where(u => u.Name == game.GameStatus.Name).FirstOrDefault();
            }
            for (int i = 0; i < game.Maps.Count; ++i)
            {
                game.Maps[i].Owner = _context.Users.Find(game.Maps[i].Owner.Id);
                game.Maps[i].Game  = game;
            }
            await _context.Maps.AddRangeAsync(game.Maps);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GameExist(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }
コード例 #2
0
        public async Task <ActionResult <Exam.Data.Game> > PostGame(Exam.Data.Game game)
        {
            if (game == null)
            {
                return(BadRequest());
            }
            _context.Games.Add(game);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGame", new { id = game.Id }, game));
        }
コード例 #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            var userId    = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var user_find = _context.Users.Include(u => u.Game).Where(u => u.Id == userId);
            var user      = user_find.FirstOrDefault();

            this.disableGame();
            List <Exam.Data.User> users = new List <Exam.Data.User>();

            users.Add((Exam.Data.User)user);
            var game = new Exam.Data.Game {
                Users      = users,
                GameStatus = _context.GameStatuses.Find(3),
                UserTurnId = user.Id,
            };

            Game = game;
            _context.Games.Add(game);
            _context.SaveChanges();
            return(Redirect("/Game/Game?id=" + Game.Id));
        }
コード例 #4
0
ファイル: API_Game.cs プロジェクト: qawsed281113/Battleship
 public async Task <IActionResult> PutGame(int id, [FromBody] Exam.Data.Game game)
 {
     if (id != game.Id)
     {
         return(BadRequest());
     }
     _context.Entry(game).State = EntityState.Modified;
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!GameExist(id))
         {
             return(NotFound());
         }
         else
         {
             throw;
         }
     }
     return(NoContent());
 }