private void ButtonCreateNow_Click(object sender, RoutedEventArgs e) { FragmentCreateRecipe fragmentCreateRecipe = new FragmentCreateRecipe(); PageHome.SetButtonActive(PageHome.GlobalButtonCreate); NavigationService.Navigate(fragmentCreateRecipe); }
private void ButtonCreate_Click(object sender, RoutedEventArgs e) { string name = TextBoxName.Text; string type = ComboBoxType.Text; string priceString = TextBoxPrice.Text; int price; string description = TextBoxDescription.Text; string[] fields = new string[] { name, type, priceString, description }; string message = ""; if (fields.Contains("")) { message += "- All fields are required." + Environment.NewLine; } if (!Int32.TryParse(priceString, out price)) { message += "- Price must be a number." + Environment.NewLine; } if (price < 10 || price > 40) { message += "- Price must be between 10 and 40 cooks." + Environment.NewLine; } if (ProductsRequiredInRecipe.Count() == 0) { message += "- You must select at least one product." + Environment.NewLine; } if (message != "") { MessageBox.Show(message); return; } Recipe recipe = new Recipe(); recipe.Name = name; recipe.Type = type; recipe.Price = price; recipe.Description = description; recipe.Remuneration = 2; recipe.RecipeCreator = new RecipeCreator(); if (AuthUser.RecipeCreator != null) { recipe.RecipeCreator = AuthUser.RecipeCreator; } else { ServiceRecipeCreator = new ServiceRecipeCreator(); recipe.RecipeCreator = ServiceRecipeCreator.Save(AuthUser.Client); } recipe.Products = ProductsRequiredInRecipe.ToList(); ServiceRecipe = new ServiceRecipe(); if (ServiceRecipe.Save(recipe)) { if (AuthUser.Role != "Admin") { AuthUser.Role = "RecipeCreator"; } AuthUser.RecipeCreator = recipe.RecipeCreator; MessageBox.Show("Your recipe has been created successfully!"); FragmentCreateRecipe fragmentCreateRecipe = new FragmentCreateRecipe(); PageHome.SetButtonActive(PageHome.GlobalButtonCreate, true); NavigationService.Navigate(fragmentCreateRecipe); } else { ServiceRecipeCreator.Remove(recipe.RecipeCreator); MessageBox.Show("Something went wrong, your recipe has not been created!"); } }