Пример #1
0
        public async Task<IHttpActionResult> PutMovieDb(int id, MovieDb movieDb)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != movieDb.ID)
            {
                return BadRequest();
            }

            db.Entry(movieDb).State = EntityState.Modified;

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #2
0
        public async Task<IHttpActionResult> PostMovieDb(MovieDb movieDb)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Movies.Add(movieDb);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = movieDb.ID }, movieDb);
        }