Пример #1
0
        public HttpResponseMessage Post(Recipe recipe)
        {
            if (ModelState.IsValid)
            {
                if (recipe.Id== 0)
                {
                    _db.Recipes.Add(recipe);
                    _db.SaveChanges();
                    return Request.CreateResponse(HttpStatusCode.Created, recipe);
                }
                else
                {
                    var original = _db.Recipes.Find(recipe.Id);
                    original.RecipeName = recipe.RecipeName;
                    _db.SaveChanges();
                    return Request.CreateResponse(HttpStatusCode.OK, recipe);

                }
            }
            return Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState);
        }
Пример #2
0
 public void EditRecipe(Recipe recipe)
 {
     var original = this.FindRecipe(recipe.Id);
     original.RecipeName = recipe.RecipeName;
 }
Пример #3
0
 public void CreateRecipe(Recipe recipe)
 {
     _repo.Add<Recipe>(recipe);
     _repo.SaveChanges();
 }