Ejemplo n.º 1
0
        public IHttpActionResult PutFood(int id, Food food)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != food.Id)
            {
                return BadRequest();
            }
            try
            {
                repository.EditFood(id, food);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!repository.FoodExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Ejemplo n.º 2
0
        public IHttpActionResult PostFood(Food food)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            repository.AddFood(food);

            return CreatedAtRoute("DefaultApi", new { id = food.Id }, food);
        }