Esempio n. 1
0
        public GetRecipeServiceResponse GetRecipes(GetRecipeServiceRequest request)
        {
            List<Recipe> result = new List<Recipe>();

               using (var db = new MatContext())
               {
               var query = from r in db.Recipes
                           orderby r.Name
                           select r;

               var rec = (from r in db.Recipes
                           select r).First();

               Console.WriteLine("test: " +rec.Ingredients[0].Item);

               foreach(Recipe r in query){
                   Console.WriteLine(r.Ingredients);
                   result.Add(r);
               }

               }

               GetRecipeServiceResponse response = new GetRecipeServiceResponse();
               response.ID = request.ID;
               response.Result = AbstractServiceResponse.flag.SUCCESS;
               response.Recipes = result;
               return response;
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //Initialize services, should use dependency  injection (unity)
            AddRecipeService sAdd = new AddRecipeService();
            GetRecipeService sGet = new GetRecipeService();
            AddIngredientService sAddIng = new AddIngredientService();
            GetIngredientService sGetIng = new GetIngredientService();
            DropDBService sDrop = new DropDBService();

            //Drop the database, probably should be removed before release
            DropDBServiceRequest dropReq = new DropDBServiceRequest { ID = 1};
            DropDBServiceResponse dropRe = sDrop.DropDB(dropReq);

            //Add a test ingredient
            Ingredient ing = new Ingredient { name = "Mjölk", description = "Mjölk av ko.",Measure = Ingredient.EMeasure.Liter };
            AddIngredientServiceRequest addIngSr = new AddIngredientServiceRequest { ID = 1, Ingredient = ing };

            AddIngredientServiceResponse reIngAdd = sAddIng.AddIngredient(addIngSr);

            //Get a list of all ingredients
            GetIngredientServiceRequest getISR = new GetIngredientServiceRequest { ID = 1 };
            GetIngredientServiceResponse reGetI = sGetIng.GetIngredient(getISR);
            Console.WriteLine("Ingredients: ");
            foreach (Ingredient i in reGetI.Ingredients)
            {
                Console.WriteLine(i);
            }

            //Add a recipe
            RecipeItem rItem = new RecipeItem();
            rItem.Item = ing;
            rItem.Quantity = 1.0f;
            RecipeItemList rIList = new RecipeItemList();
            rIList.Add(rItem);
            var recipe = new Recipe { Name = "Pannkakor", Ingredients = rIList };
            var addSR = new AddRecipeServiceRequest { Recipe = recipe, ID = 1 };

            AddRecipeServiceResponse re = sAdd.AddRecipe(addSR);

            //Get a list of all the recipes
            GetRecipeServiceRequest getSR = new GetRecipeServiceRequest { ID = 1 };
            GetRecipeServiceResponse reGet = sGet.GetRecipes(getSR);

            Console.WriteLine("Recipes: ");
            foreach (Recipe r in reGet.Recipes)
            {
                Console.WriteLine(r);
            }

            Console.ReadKey();
        }