internal static List<RecipeHeaderViewModel> CreateFilteredIndexByName(List<RecipeHeaderViewModel> index, string filter) { return index .SelectMany (rivm => rivm.Recipes) .Where(rvm => rvm.Recipe != null && rvm.Recipe.Name != null && rvm.Recipe.Name.IndexOf (filter, StringComparison.CurrentCultureIgnoreCase) >= 0) .OrderBy (rvm => rvm.Recipe.Name) .Aggregate ( new List<RecipeHeaderViewModel> (), (list, rvm) => { string key = rvm.Recipe.Name.FirstOrDefault(Char.IsLetterOrDigit).ToString ().ToUpper (); var ivm = list.FirstOrDefault(v => v.Key == key); if (ivm == null) { ivm = new RecipeHeaderViewModel (){Key = key, Recipes = new List<RecipeViewModel> ()}; list.Add (ivm); } ivm.Recipes.Add (rvm); return list; }) .OrderBy (ivm => ivm.Key) .ToList (); }
private static List<RecipeHeaderViewModel> GetIndex() { IRecipeService recipeService = ServiceController.Get<IRecipeService> (); return recipeService .SearchRecipeKeys () .Select (recipeId => recipeService.GetRecipeNoThrow (recipeId)) .Where (recipe => recipe != null) .OrderBy (recipe => recipe.Name) .Aggregate ( new List<RecipeHeaderViewModel> (), (list, recipe) => { string key = recipe.Name.FirstOrDefault(Char.IsLetterOrDigit).ToString ().ToUpper (); var vm = list.FirstOrDefault(v => v.Key == key); if (vm == null) { vm = new RecipeHeaderViewModel (){Key = key, Recipes = new List<RecipeViewModel> ()}; list.Add (vm); } vm.Recipes.Add (new RecipeViewModel {FileName=recipe.Key, Recipe=Sellars.Meal.UI.Model.Recipe.FromRecipe (recipe)}); return list; }) .OrderBy (vm => vm.Key) .ToList (); }
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 (); }
internal static List<RecipeHeaderViewModel> CreateFilteredIndexByTag(List<RecipeHeaderViewModel> index, string filter) { return index .SelectMany (rivm => rivm.Recipes) .OrderBy (rvm => rvm.Recipe.Name) .SelectMany ( r => (r.Recipe.Tags == null || r.Recipe.Tags.Count == 0) ? new KeyRecipePair[] {new KeyRecipePair{Key="Untagged", Recipe=r}} : r.Recipe.Tags.Select (t => new KeyRecipePair {Key = t.Name, Recipe = r})) .GroupBy ( pair => pair.Key, StringComparer.InvariantCultureIgnoreCase) .OrderBy (group => group.Key, StringComparer.InvariantCultureIgnoreCase) .Select ( group => { string key = group.Key; RecipeHeaderViewModel ivm; ivm = new RecipeHeaderViewModel (){Key = key, Recipes = new List<RecipeViewModel> ()}; ivm.Recipes = group .Select (pair => pair.Recipe) .ToList (); return ivm; }) .ToList (); }