예제 #1
0
        public IHttpActionResult PutRecipe(long id, RecipeDal.Recipe recipe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != recipe.RecipeId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        public IHttpActionResult PostRecipe(RecipeDal.Recipe recipe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Recipes.Add(recipe);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = recipe.RecipeId }, recipe));
        }
예제 #3
0
        public IHttpActionResult DeleteRecipe(long id)
        {
            RecipeDal.Recipe recipe = db.Recipes.Find(id);
            if (recipe == null)
            {
                return(NotFound());
            }

            db.Recipes.Remove(recipe);
            db.SaveChanges();

            return(Ok(recipe));
        }