Example #1
0
        public async Task <Guid> CreateGame(Game game)
        {
            game.Id = Guid.NewGuid();
            _context.Games.Add(game);
            await _context.SaveChangesAsync();

            return(game.Id);
            //return CreatedAtAction(
            //    nameof(GetGame),game.Id);
        }
        public async Task <ActionResult <Player> > CreatePlayer(Player player)
        {
            if ((await _context.Players.FindAsync(player.Id)) == null)
            {
                _context.Players.Add(player);
                await _context.SaveChangesAsync();
            }

            return(CreatedAtAction(
                       nameof(GetPlayer), player.Id));
        }
Example #3
0
        public async Task <Guid> CreateGamePlayer(GamePlayerPrototype gamePlayerPrototype)
        {
            var gamePlayer = new GamePlayer()
            {
                Id       = Guid.NewGuid(),
                Figure   = gamePlayerPrototype.Figure == "x" ? FigureType.x : FigureType.o,
                IsWon    = gamePlayerPrototype.IsWon,
                PlayerId = gamePlayerPrototype.PlayerId,
                GameId   = gamePlayerPrototype.GameId
            };

            _context.GamePlayers.Add(gamePlayer);
            await _context.SaveChangesAsync();

            return(gamePlayer.Id);
            //return Guid.NewGuid();
            //return CreatedAtAction(
            //    nameof(GetGamePlayer), gamePlayer.Id);
        }
        public async Task <bool> CreateGamePlayerSections(object sectionSectionPrototypesObj)
        {
            var sectionSectionPrototypes = JsonSerializer.Deserialize <List <SectionPrototype> >(sectionSectionPrototypesObj.ToString());
            var allSections = await _context.Sections.ToListAsync();

            foreach (var section in sectionSectionPrototypes)
            {
                var needSection = allSections.Where(sec => sec.XCoordinate == section.XCoordinate && sec.YCoordinate == section.YCoordinate)
                                  .FirstOrDefault();
                if (needSection != null)
                {
                    _context.GamePlayerSections.Add(new GamePlayerSection()
                    {
                        SectionId = needSection.Id, GamePlayerId = section.GamePlayerId
                    });
                }
            }
            await _context.SaveChangesAsync();

            return(true);
        }