public async Task<IHttpActionResult> PostFoodDescription(FoodDescription foodDescription) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.FoodDescriptions.Add(foodDescription); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (FoodDescriptionExists(foodDescription.Number)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = foodDescription.Number }, foodDescription); }
public async Task<IHttpActionResult> PutFoodDescription(string id, FoodDescription foodDescription) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != foodDescription.Number) { return BadRequest(); } db.Entry(foodDescription).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FoodDescriptionExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }