コード例 #1
0
        public async Task <IActionResult> PutSportsTb([FromRoute] int id, [FromBody] SportsTb sportsTb)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != sportsTb.SportsId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> PostSportsTb([FromBody] SportsTb sportsTb)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.SportsTb.Add(sportsTb);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (SportsTbExists(sportsTb.SportsId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetSportsTb", new { id = sportsTb.SportsId }, sportsTb));
        }