private void Finish_Clicked(object sender, RoutedEventArgs e) { // track a custom event GoogleAnalytics.EasyTracker.GetTracker().SendEvent("ui_action", "finish_click", "Finish: from RecipeOnboarding", 0); // track a timing (how long it takes your app to run a specific task) GoogleAnalytics.EasyTracker.GetTracker().SendTiming(DateTime.Now.Subtract(startTime), "Recipe Onboarding View Time", "RecipeOnboarding", "Exit By Finish"); SolidColorBrush errorRed = new SolidColorBrush(Color.FromArgb(255, 220, 20, 60)); Debug.WriteLine("category Selected: " + Cat_ComboBox.SelectedIndex + " |"); if (RecipeName_textBox_desktab.Text == "") { RecipeName_textBox_desktab.BorderBrush = errorRed; return; } if (Cat_ComboBox.SelectedItem == null) { Cat_ComboBox.BorderBrush = errorRed; return; } if (YieldTextBox.Text == "") { YieldTextBox.Text = "1 "; } if (TemperatureTextBox.Text == "") { TemperatureTextBox.Text = "0 "; } // read recipeBook to memory RecipeClass newRecipe = new RecipeClass(); List <RecipeClass> recipeBook = buildRecipeBook(newRecipe); string json = JsonConvert.SerializeObject(recipeBook); WriteRecipeBook(json); // navigate back to recipe feed SplitView.splitviewPage.MainContentFrame.Navigate(typeof(RecipeFeed)); SplitView.splitviewPage.MainNav.IsPaneOpen = true; }
private List <RecipeClass> buildRecipeBook(RecipeClass newRecipe) { // read local storage to get the list of existing recipes, and store into a list in memory List <RecipeClass> recipeBook = new List <RecipeClass>(); var roamingSettings = ApplicationData.Current.RoamingSettings; List <RecipeClass> recipe_Current; Task <List <RecipeClass> > readingTask = ReadRecipeBook(); readingTask.Start(); while (!readingTask.IsCompleted) { Debug.WriteLine("Task status was " + readingTask.Status.ToString()); } if (!readingTask.IsFaulted) { recipe_Current = ReadRecipeBook().Result; Debug.WriteLine("Task is not fualted."); } else { //you're probs f****d Debug.WriteLine("Task is else."); recipe_Current = null; } List <RecipeClass> recipeBookStore = recipe_Current; if (recipeBookStore != null) { recipeBook = recipeBookStore; } // get the new recipe from the UI and store into an object in memory newRecipe.ID = Guid.NewGuid(); newRecipe.Date = DateTime.UtcNow.Ticks; newRecipe.Name = RecipeName_textBox_desktab.Text; newRecipe.Description = RecipeDescription_textBox_desktab.Text; if (Cat_ComboBox.SelectedIndex == 0) { category_Selected = "Appetizer"; } if (Cat_ComboBox.SelectedIndex == 1) { category_Selected = "Breakfast & Brunch"; } if (Cat_ComboBox.SelectedIndex == 2) { category_Selected = "Cocktails"; } if (Cat_ComboBox.SelectedIndex == 3) { category_Selected = "Desserts"; } if (Cat_ComboBox.SelectedIndex == 4) { category_Selected = "Drinks"; } if (Cat_ComboBox.SelectedIndex == 5) { category_Selected = "Main Dishes"; } if (Cat_ComboBox.SelectedIndex == 6) { category_Selected = "Pasta"; } if (Cat_ComboBox.SelectedIndex == 7) { category_Selected = "Salad"; Debug.WriteLine("7: " + category_Selected); } if (Cat_ComboBox.SelectedIndex == 8) { category_Selected = "Seafood"; } if (Cat_ComboBox.SelectedIndex == 9) { category_Selected = "Soup"; } if (Cat_ComboBox.SelectedIndex == 10) { category_Selected = "Vegetarian"; } else { category_Selected = "unknown"; } newRecipe.Category = category_Selected; Debug.WriteLine("7 Selected: " + category_Selected); List <string> ingredList = new List <string>(); foreach (TextBox t in IngredientsStackPanel.Children) { string ingredient = t.Text; ingredList.Add(ingredient); } newRecipe.Ingredients = ingredList; List <DirectionClass> directionList = new List <DirectionClass>(); foreach (StackPanel sp in DirectionsStackPanel.Children) { DirectionClass newDirection = new DirectionClass(); newDirection.StepID = DirectionsStackPanel.Children.IndexOf(sp); foreach (TextBox t in sp.Children) { if (t.Tag.ToString() == "step") { newDirection.StepName = t.Text; } if (t.Tag.ToString() == "direction") { newDirection.StepDirection = t.Text; } } directionList.Add(newDirection); } newRecipe.Directions = directionList; newRecipe.Yeild = YieldTextBox.Text.Substring(0, YieldTextBox.Text.Length - 2); newRecipe.PrepTime = RecipePrepTime_timepicker_desktab.Time; newRecipe.CookTime = RecipeCookTime_timepicker_desktab.Time; newRecipe.Temp = TemperatureTextBox.Text.Substring(0, TemperatureTextBox.Text.Length - 3); // append the new recipe to the list, and return the list recipeBook.Add(newRecipe); return(recipeBook); }