예제 #1
0
        public async Task SaveRecipeAsync(AddEditRecipe item, bool isNewItem = false)
        {
            var uri = new Uri(string.Format(Constants.RcpAddEditUrl));

            try
            {
                var json    = JsonConvert.SerializeObject(item);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                HttpResponseMessage response = null;
                if (isNewItem)
                {
                    response = await client.PostAsync(uri, content);
                }
                else
                {
                    response = await client.PutAsync(uri, content);
                }

                if (response.IsSuccessStatusCode)
                {
                    Debug.WriteLine(@"				Recipe successfully saved.");
                }
                else
                {
                    Debug.WriteLine(@"      ******  Recipe write FAILED  ******");
                    Debug.WriteLine(json);
                    Debug.WriteLine(content);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(@"				ERROR {0}", ex.Message);
            }
        }
예제 #2
0
 public Task SaveRecipeAsync(AddEditRecipe item, bool isNewItem = false)
 {
     return(restService.SaveRecipeAsync(item, isNewItem));
 }
예제 #3
0
        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();
        }