Exemplo n.º 1
0
        public async Task <IActionResult> PutBoardGame([FromRoute] int id, [FromBody] BoardGame boardGame)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != boardGame.Id)
            {
                return(BadRequest());
            }

            _context.Entry(boardGame).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BoardGameExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutPlayer([FromRoute] int id, [FromBody] Player player)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != player.Id)
            {
                return(BadRequest());
            }

            _context.Update(player);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlayerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Title,ImageURL,ReleaseYear,AddedByUser,DateAdded")] Game game)
        {
            if (ModelState.IsValid)
            {
                if (_signManager.IsSignedIn(User))
                {
                    var user = await _userManager.GetUserAsync(User);

                    game.AddedByUser = user.Email;

                    var email = new Email();
                    email.SendAddedEmail(user.Email, game.Title).Wait();
                }
                else
                {
                    game.AddedByUser = "******";
                }

                game.DateAdded = DateTime.UtcNow;
                _context.Add(game);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(game));
        }
Exemplo n.º 4
0
        public async Task <BoardGame> AddAsync(BoardGame game)
        {
            var addedGame = await _context.BoardGames.AddAsync(game).ConfigureAwait(false);

            int countChanges = await _context.SaveChangesAsync().ConfigureAwait(false);

            if (countChanges > 0)
            {
                _cache.Set(game.Id, addedGame.Entity, _cacheOptions);
            }

            return(addedGame.Entity);
        }
Exemplo n.º 5
0
        public async Task AddBoardGameAsync(UpdateBoardGameRequest game)
        {
            var dbGames = await dbContext.BoardGames.Where(g => g.Name == game.Name).ToArrayAsync();

            if (dbGames.Length > 0)
            {
                throw new RequestedResourceHasConflictException("name");
            }

            await dbContext.BoardGames.AddAsync(mapper.Map <BoardGame>(game));

            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 6
0
        public async Task <IActionResult> PutQBoardSquare([FromRoute] int col, [FromRoute] int row, [FromBody] QBoardSquare qboardsquare)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Tblboardsquaresv2 boardsquare = await _context.Tblboardsquaresv2.SingleOrDefaultAsync(bs => (bs.Colposition == col) && (bs.Rowposition == row));

            Tblplayersv2 player = await _context.Tblplayersv2.SingleOrDefaultAsync(p => p.Id == boardsquare.Playerid);

            if (boardsquare != null)
            {
                boardsquare.Northwall   = qboardsquare.Northwall;
                boardsquare.Southwall   = qboardsquare.Southwall;
                boardsquare.Westwall    = qboardsquare.Westwall;
                boardsquare.Eastwall    = qboardsquare.Eastwall;
                boardsquare.Colposition = col;
                boardsquare.Rowposition = row;
                if (player != null)
                {
                    boardsquare.Playerid = player.Id;
                }
                else
                {
                    boardsquare.Playerid = null;
                }
            }
            else
            {
                return(NotFound());
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Tblboardsquaresv2Exists(boardsquare.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 7
0
        /// <inheritdoc/>
        public async Task CreateBoardGameAsync(BoardGame boardGame)
        {
            _context.BoardGames.Add(boardGame);

            var n = await _context.SaveChangesAsync();

            if (n > 0)
            {
                _cache.Set(boardGame.Id, boardGame, new MemoryCacheEntryOptions
                {
                    AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5)
                });
            }
        }
        public async Task <IActionResult> PutQPlayer([FromRoute] string playername, [FromBody] QPlayer qplayer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Tblplayersv2 player = await _context.Tblplayersv2.SingleOrDefaultAsync(p => p.Playername == playername);

            Tblboardsquaresv2 boardsquare = await _context.Tblboardsquaresv2.SingleOrDefaultAsync(bs => bs.Playerid == player.Id);

            if (player != null)
            {
                player.Playername      = qplayer.Playername;
                player.Facingdirection = qplayer.Facingdirection;

                /* Has Player Moved ?*/
                if ((boardsquare.Colposition == qplayer.Colposition) && (boardsquare.Rowposition == qplayer.Rowposition))
                {
                    /* Player has NOT moved */
                }
                else
                {
                    boardsquare.Playerid = null;
                    boardsquare.Player   = null;
                    Tblboardsquaresv2 newboardsquare = await _context.Tblboardsquaresv2.SingleOrDefaultAsync((bs => (bs.Colposition == qplayer.Colposition) && (bs.Rowposition == qplayer.Rowposition)));

                    newboardsquare.Player = player;
                }

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Tblplayersv2Exists(player.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(NoContent());
        }