private void Page_Loaded(object sender, RoutedEventArgs e) { ServiceRecipeCreator = new ServiceRecipeCreator(); RecipeCreators = new ObservableCollection <RecipeCreator>(ServiceRecipeCreator.All()); ListViewRecipereators.ItemsSource = RecipeCreators; }
private void Page_Loaded(object sender, RoutedEventArgs e) { ServiceRecipeCreator = new ServiceRecipeCreator(); RecipeCreator recipeCreatorOfTheWeek = ServiceRecipeCreator.BestOfTheWeek(); if (recipeCreatorOfTheWeek != null) { TextBlockRecipeCreatorOfTheWeek.Text = recipeCreatorOfTheWeek.Client.FullName; TextBlockCountRecipesOfCreatorOfTheWeek.Text = $"{recipeCreatorOfTheWeek.RecipesSold} recipes sold last 7 days"; } else { TextBlockCountRecipesOfCreatorOfTheWeek.Text = "No recipes sold last 7 days"; } RecipeCreator recipeCreatorOfAllTime = ServiceRecipeCreator.BestOfAllTime(); ServiceRecipe = new ServiceRecipe(); if (recipeCreatorOfAllTime != null) { TextBlockRecipeCreatorOfAllTime.Text = recipeCreatorOfAllTime.Client.FullName; TextBlockCountRecipesOfCreatorOfAllTime.Text = $"{recipeCreatorOfAllTime.RecipesSold} recipes sold"; TextBlockTopOfBestCreatorTitle.Text = "Top 5 recipes of: " + recipeCreatorOfAllTime.Client.FullName; ListViewTopRecipesOfBestCreator.ItemsSource = ServiceRecipe.AllOf(recipeCreatorOfAllTime, 5); } else { TextBlockCountRecipesOfCreatorOfTheWeek.Text = "No recipes sold"; } ListViewTop5Recipes.ItemsSource = ServiceRecipe.Top(5); }
private void Page_Loaded(object sender, RoutedEventArgs e) { ServiceRecipeCreator = new ServiceRecipeCreator(); List <RecipeCreator> recipeCreators = ServiceRecipeCreator.AllWithRecipes(); ListViewRecipeCreators.ItemsSource = recipeCreators; TextBlockCountRecipeCreators.Text = (recipeCreators.Count).ToString(); ServiceProduct = new ServiceProduct(); ListViewProductsToRestock.ItemsSource = ServiceProduct.AllForDemo(); ServiceClient = new ServiceClient(); TextBlockCountClients.Text = ((ServiceClient.All()).Count).ToString(); ServiceRecipe = new ServiceRecipe(); TextBlockCountRecipes.Text = ((ServiceRecipe.All()).Count).ToString(); }
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!"); } }