예제 #1
0
        public async Task <IActionResult> PostQBoardSquare([FromBody] QBoardSquare qboardsquare)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Tblboardsquaresv2 boardsquare = new Tblboardsquaresv2
            {
                Northwall = qboardsquare.Northwall,
                Southwall = qboardsquare.Southwall,
                Westwall  = qboardsquare.Westwall,
                Eastwall  = qboardsquare.Eastwall
            };

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

            _context.Tblboardsquaresv2.Add(boardsquare);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTblboardsquaresv2", new { id = boardsquare.Id }, boardsquare));
        }
예제 #2
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());
        }