Exemplo n.º 1
0
        public async Task <IActionResult> PostCelebrityInCelebrityJoke([FromBody] CelebrityInCelebrityJoke celebrityInCelebrityJoke)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.CelebrityInCelebrityJokes.Add(celebrityInCelebrityJoke);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (CelebrityInCelebrityJokeExists(celebrityInCelebrityJoke.CelebrityID))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetCelebrityInCelebrityJoke", new { id = celebrityInCelebrityJoke.CelebrityID }, celebrityInCelebrityJoke));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutCelebrityInCelebrityJoke([FromRoute] int id, [FromBody] CelebrityInCelebrityJoke celebrityInCelebrityJoke)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != celebrityInCelebrityJoke.CelebrityID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }