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

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

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

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

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

            _context.BulletPages.Add(bulletPage);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (BulletPageExists(bulletPage.Id))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetBulletPage", new { id = bulletPage.Id }, bulletPage));
        }