protected override void OnAppearing() { App.AddRecipeViewModel = new ViewModels.AddRecipeViewModel(); //App.AddRecipeViewModel.RefreshMenuAsync(); BindingContext = App.AddRecipeViewModel; Ingred2List = new IngredientListVM() { IngredName = "", IngredQty = 0m, IngredUnit = "" }; App.AddRecipeViewModel.IngredientsList.Add(Ingred2List); Steps2List = new RecipeStepIngredientVM() { StepNumber = 1, Instruction = "" }; App.AddRecipeViewModel.StepIngredList.Add(Steps2List); base.OnAppearing(); }
private void OnAddStepClicked(object sender, EventArgs e) { Steps2List = new RecipeStepIngredientVM() { StepNumber = 1, Instruction = "" }; App.AddRecipeViewModel.StepIngredList.Add(Steps2List); }
private void OnAddStepClicked(object sender, EventArgs e) { tempStepNumber++; Steps2List = new RecipeStepIngredientVM() { StepNumber = tempStepNumber, Instruction = "" }; App.AddRecipeViewModel.StepIngredList.Add(Steps2List); App.AddRecipeViewModel.StepHeight += Constants.addRcpDispRowHeight; }
public IActionResult GetRecipeSteps(int id) { var recipeSteps = from stepPtr in _context.Steps where stepPtr.RecipeId == id select stepPtr; var stepList = recipeSteps.ToList(); List <RecipeStepIngredientVM> recipeStepIngredients = new List <RecipeStepIngredientVM>(); foreach (Step stepPtr in stepList) { var stepIngred = from ingredPtr in _context.StepIngredient where ingredPtr.StepId == stepPtr.Id select ingredPtr; var tempStpIngred = stepIngred.ToList(); var stepIngredients = new RecipeStepIngredientVM(); List <IngredientListVM> ingredientList = new List <IngredientListVM>(); foreach (StepIngredient ingred in tempStpIngred) { var tempIngred = new IngredientListVM(); var tempIngredName = from ingredNamePtr in _context.Ingredients where ingred.IngredientId == ingredNamePtr.Id select ingredNamePtr.IngredName; tempIngred.IngredName = tempIngredName.Single().ToString(); tempIngred.IngredQty = ingred.IngredQty; tempIngred.IngredUnit = ingred.IngredUnit; ingredientList.Add(tempIngred); } stepIngredients.RecipeId = stepPtr.RecipeId; stepIngredients.StepId = stepPtr.Id; stepIngredients.StepNumber = stepPtr.StepNumber; stepIngredients.Instruction = stepPtr.Instruction; stepIngredients.IngredientList = ingredientList; recipeStepIngredients.Add(stepIngredients); } return(new ObjectResult(recipeStepIngredients)); }
async void OnSaveRecipeClicked(object sender, EventArgs e) { var newRecipe = new AddEditRecipe(); var isNewRecipe = true; var newUserRecFav = new UserRecipeFavorite(); newUserRecFav.UserId = userDetailsID; newUserRecFav.RecipeId = 0; newUserRecFav.Favorite = false; newRecipe.userRecipeFavorite = newUserRecFav; var tempRecipe = new RecipeVM(); tempRecipe.OwnerId = userDetailsID; tempRecipe.RecipeName = App.AddRecipeViewModel.NewRcp.RecipeName; tempRecipe.Description = App.AddRecipeViewModel.NewRcp.Description; tempRecipe.Shared = false; tempRecipe.MyRating = 0; tempRecipe.ShareRating = 0m; tempRecipe.NumShareRatings = 0m; tempRecipe.PrepTime = App.AddRecipeViewModel.NewRcp.PrepTime; tempRecipe.CookTime = App.AddRecipeViewModel.NewRcp.CookTime; tempRecipe.RecipeServings = App.AddRecipeViewModel.NewRcp.RecipeServings; tempRecipe.RecipePic = App.AddRecipeViewModel.NewRcp.RecipePic; newRecipe.recipe = tempRecipe; List <IngredientListVM> ingredientList = new List <IngredientListVM>(); foreach (IngredientListVM tempIngred in App.AddRecipeViewModel.IngredientsList) { var ingred = new IngredientListVM(); ingred.IngredName = tempIngred.IngredName; ingred.IngredQty = tempIngred.IngredQty; ingred.IngredUnit = tempIngred.IngredUnit; ingredientList.Add(ingred); } List <RecipeStepIngredientVM> stepList = new List <RecipeStepIngredientVM>(); foreach (RecipeStepIngredientVM tempStep in App.AddRecipeViewModel.StepIngredList) { var step = new RecipeStepIngredientVM(); List <IngredientListVM> emptyList = new List <IngredientListVM>(); step.StepNumber = tempStep.StepNumber; step.Instruction = tempStep.Instruction; if (step.StepNumber == 1) { step.IngredientList = ingredientList; } else { step.IngredientList = emptyList; } stepList.Add(step); } newRecipe.RecipeStepIngredients = stepList; var keyword = new Keyword(); keyword.SearchWord = " "; List <Keyword> keywords = new List <Keyword>(); keywords.Add(keyword); newRecipe.Keywords = keywords; await App.cabeMgr.SaveRecipeAsync(newRecipe, isNewRecipe); await Navigation.PopAsync(); }