public async Task <List <Recipe> > GetRecipes() { List <Recipe> recipes = new List <Recipe>(); List <Models.DB.Recipe> fromDB = await this.foodDatabase.GetRecipes(); foreach (var recipeFromDB in fromDB) { Recipe recipe = ConvertFromDb(recipeFromDB); recipes.Add(recipe); List <Models.DB.RecipeItem> items = await this.foodDatabase.GetRecipeItems(recipeFromDB.Id); foreach (var recipeItemDB in items) { Models.DB.Food foodDb = await this.foodDatabase.FoodById(recipeItemDB.FoodId); RecipeItem recipeItem = ConvertFromDb(recipeItemDB); recipeItem.Food = FoodRepository.ConvertFromDb(foodDb); recipe.Items.Add(recipeItem); } } return(recipes); }
public static Food ConvertFromDb(Models.DB.Food dbFood) { return(new Food() { Id = dbFood.Id, Calories = dbFood.Calories, Carbs = dbFood.Carbs, Fat = dbFood.Fat, Fiber = dbFood.Fiber, Name = dbFood.Name, Natrium = dbFood.Natrium, Portion = dbFood.Portion, PortionType = (PortionType)dbFood.PortionType, Protein = dbFood.Protein, SaturatedFat = dbFood.SaturatedFat, Sugar = dbFood.Sugar, BarCode = dbFood.BarCode }); }
public async Task <int> SaveFood(Food food) { Models.DB.Food dbFood = ConvertToDb(food); return(await foodDatabase.SaveFood(dbFood)); }
public async Task <Food> FoodById(int id) { Models.DB.Food dbFood = await foodDatabase.FoodById(id); return(ConvertFromDb(dbFood)); }