private void NewRecipeExecute(object parameter)
 {
     var recipe = new Sellars.Meal.UI.Model.Recipe ();
      recipe.Source = new Sellars.Meal.UI.Model.Source ();
      recipe.Parts.Add (new Sellars.Meal.UI.Model.RecipePart ());
      var rvm = new RecipeViewModel {Recipe=recipe, EditMode=true};
      m_index
     .Where(rhvm => rhvm.Key == "New")
     .First ()
     .Recipes.Add (rvm);
      Index = new List<RecipeHeaderViewModel> (m_index);
      SelectedItem = rvm;
 }
Esempio n. 2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var window = new Sellars.Meal.UI.View.MainWindow ();

             ServiceController.Put<IRecipeService>(new FileSystemRecipeService(AppConfig.Instance.RecipePath));
             //ServiceController.Put<IRecipeService> (IndexRecipeService.CreateIndex ());

             object dataContext;

             string [] args = Environment.GetCommandLineArgs ();

             //IRecipe irecipe;
             IRecipeService recipeService = ServiceController.Get<IRecipeService> ();
             SelectedIndexViewModel vm= new SelectedIndexViewModel ();
             //if (args.Length >= 2)
             //{
             //   irecipe = recipeService.GetRecipe (new ModelId<IRecipe> (args [1]));
             //   Sellars.Meal.UI.Model.Recipe recipe =
             //      irecipe as Sellars.Meal.UI.Model.Recipe
             //      ?? Sellars.Meal.UI.Model.Recipe.FromRecipe (irecipe);
             //   dataContext =
             //      new Sellars.Meal.UI.ViewModel.RecipeViewModel
             //         {Recipe = recipe};
             //}
             //else
             {
            var recipe = new Sellars.Meal.UI.Model.Recipe ();
            recipe.Source = new Sellars.Meal.UI.Model.Source ();
            recipe.Parts.Add (new Sellars.Meal.UI.Model.RecipePart (){Name="Recipe"});
            vm = new SelectedIndexViewModel {Index = GetIndex ()};
            var newRecipe = new RecipeViewModel{Recipe=recipe, EditMode=true};
            var newHeader =
               new RecipeHeaderViewModel
               {
                  Key = "New",
                  Recipes = new List<RecipeViewModel>{newRecipe}
               };
            vm.Index.Insert (0, newHeader);
            vm.Recipe = newRecipe;
            ServiceController.Put<ISourceService> (new IndexSourceService (vm.ObservableSources));
            ServiceController.Put<ITagService> (new IndexTagService (vm.ObservableTags));
            ServiceController.Put<Sellars.Meal.UI.Service.IIngredientService> (new IndexIngredientService (vm.ObservableIngredients));
            ServiceController.Put<IDocumentPrintingService> (new DocumentPrintingService ());
            dataContext = vm;
             }

             window.DataContext = dataContext;
             App.Current.MainWindow = window;
             window.ShowDialog ();
        }