Esempio n. 1
0
        public HttpResponseMessage DeleteRecipe(int id)
        {
            using (CookBookEntities cookbook = new CookBookEntities())
            {
                cookbook.Ingredients.Remove(cookbook.Ingredients.SingleOrDefault(r => r.Id == id));
                cookbook.SaveChanges();
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Esempio n. 2
0
        public HttpResponseMessage AddIngredient([FromBody] IngredientDTO ingredient)
        {
            var ingredientEDMX = new Ingredient()
            {
                Name   = ingredient.Name,
                UnitId = 1
            };

            using (CookBookEntities cookbook = new CookBookEntities())
            {
                cookbook.Ingredients.Add(ingredientEDMX);
                cookbook.SaveChanges();
            }

            return(Request.CreateResponse(HttpStatusCode.OK, ingredient));
        }
Esempio n. 3
0
        public HttpResponseMessage UpdateRecipe([FromBody] RecipeDTO recipeDTO)
        {
            using (CookBookEntities cookbook = new CookBookEntities())
            {
                var recipe = cookbook.Recipes.SingleOrDefault(r => r.Id == recipeDTO.Id);

                recipe.Name          = recipeDTO.Name;
                recipe.Level         = recipeDTO.Level;
                recipe.TimeToCook    = recipeDTO.TimeToCook;
                recipe.CountofPeople = recipeDTO.CountOfPeople;
                recipe.Description   = recipeDTO.Description;

                cookbook.SaveChanges();
            }

            return(Request.CreateResponse(HttpStatusCode.OK, recipeDTO));
        }
Esempio n. 4
0
        public HttpResponseMessage AddIngredientRecipes([FromBody] RecipeIngredientDTO ing)
        {
            var ingredient = new RecipeIngredient()
            {
                IngredientId = ing.IngredientId,
                RecipeId     = ing.RecipeId,
                Quantity     = ing.Quantity
            };

            using (CookBookEntities cookbook = new CookBookEntities())
            {
                cookbook.RecipeIngredients.Add(ingredient);
                cookbook.SaveChanges();
            }

            return(Request.CreateResponse(HttpStatusCode.OK, ingredient));
        }
Esempio n. 5
0
        public HttpResponseMessage CreateRecipe([FromBody] RecipeDTO vm)
        {
            var recipe = new Recipe()
            {
                Name          = vm.Name,
                Level         = vm.Level,
                TimeToCook    = vm.TimeToCook,
                CountofPeople = vm.CountOfPeople,
                Description   = vm.Description
            };



            using (CookBookEntities cookbook = new CookBookEntities())
            {
                cookbook.Recipes.Add(recipe);
                cookbook.SaveChanges();
            }

            //Recipe recipe = new Recipe { Name = vm.Name, Level = "c", TimeToCook = new DateTime(}

            return(Request.CreateResponse(HttpStatusCode.Created, recipe));
        }