예제 #1
0
 /*
  * // PUT: api/Ingredients/5
  * [ResponseType(typeof(void))]
  * public IHttpActionResult PutIngredient(int id, Ingredient ingredient)
  * {
  * if (!ModelState.IsValid)
  * {
  * return BadRequest(ModelState);
  * }
  *
  * if (id != ingredient.IngredientId)
  * {
  * return BadRequest();
  * }
  *
  * db.Entry(ingredient).State = EntityState.Modified;
  *
  * try
  * {
  * db.SaveChanges();
  * }
  * catch (DbUpdateConcurrencyException)
  * {
  * if (!IngredientExists(id))
  * {
  *  return NotFound();
  * }
  * else
  * {
  *  throw;
  * }
  * }
  *
  * return StatusCode(HttpStatusCode.NoContent);
  * }
  *
  * // POST: api/Ingredients
  * [ResponseType(typeof(Ingredient))]
  * public IHttpActionResult PostIngredient(Ingredient ingredient)
  * {
  * if (!ModelState.IsValid)
  * {
  * return BadRequest(ModelState);
  * }
  *
  * db.Ingredients.Add(ingredient);
  * db.SaveChanges();
  *
  * return CreatedAtRoute("DefaultApi", new { id = ingredient.IngredientId }, ingredient);
  * }
  *
  * // DELETE: api/Ingredients/5
  * [ResponseType(typeof(Ingredient))]
  * public IHttpActionResult DeleteIngredient(int id)
  * {
  * Ingredient ingredient = db.Ingredients.Find(id);
  * if (ingredient == null)
  * {
  * return NotFound();
  * }
  *
  * db.Ingredients.Remove(ingredient);
  * db.SaveChanges();
  *
  * return Ok(ingredient);
  * }
  */
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
예제 #2
0
        private bool disposedValue = false;         // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    db.Dispose();
                }

                this.disposedValue = true;
            }
        }