Ejemplo n.º 1
0
        public async Task <ActionResult <Child> > Put(int id, [FromBody] Child child)
        {
            if (child.ID != id)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            } catch (DbUpdateConcurrencyException)
            {
                if (!_context.Children.Any(c => c.ID == id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(child));
        }
Ejemplo n.º 2
0
        //[Authorize(Roles = "Admin")]
        public async Task <IActionResult> PutChild([FromRoute] int id, [FromBody] Child child)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }