Exemplo n.º 1
0
        public async Task <IHttpActionResult> PutNoteBody(int id, NoteBody noteBody)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        // PUT: odata/NoteBodies(5)
        public async Task <IHttpActionResult> Put([FromODataUri] int key, Delta <NoteBody> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            NoteBody noteBody = await db.NoteBodies.FindAsync(key);

            if (noteBody == null)
            {
                return(NotFound());
            }

            patch.Put(noteBody);

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

            return(Updated(noteBody));
        }