예제 #1
0
        public IHttpActionResult PutBeverage(int id, Beverage beverage)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BeverageExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
예제 #2
0
        public IHttpActionResult PostBeverage(Beverage beverage)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Beverages.Add(beverage);
            db.SaveChanges();

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