Exemplo n.º 1
0
 public async Task<IHttpActionResult> Post(Product product)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     db.Products.Add(product);
     await db.SaveChangesAsync();
     return Created(product);
 }
 public async Task<IHttpActionResult> Put([FromODataUri] int key, Product update)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     if (key != update.Id)
     {
         return BadRequest();
     }
     _db.Entry(update).State = EntityState.Modified;
     try
     {
         await _db.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!ProductExists(key))
         {
             return NotFound();
         }
         throw;
     }
     return Updated(update);
 }