private void BuildItems()
 {
     replacement.Items = new List<ReplacementItem>();
     foreach (var patternsFor in patterns.GroupBy(p => p.For))
     {
         var ordered = patternsFor.OrderByDescending(p => p.RightnessPoints);
         var top = ordered.First();
         var rest = ordered.Skip(1).ToList();
         var replacementItem = new ReplacementItem { Pattern = top, Alternatives = rest };
         replacement.Items.Add(replacementItem);
     }
 }
 public ReplacementItemViewModel(ReplacementItem replacementItem, Factories factories,
     IList<InsulinCircumstanceViewModel> allCircumstances, IEnumerable<MealNameViewModel> names,
     MealNameViewModel defaultName, Navigator navigator, Action save, Action<IList<PatternViewModel>> showAlternatives)
 {
     ReplacementItem = replacementItem;
     Func<Pattern, bool, PatternViewModel> createPatternViewModel = (pattern, hasAlternatives) =>
         new PatternViewModel(pattern, factories, allCircumstances: allCircumstances,
             hasAlternatives: hasAlternatives, names: names, defaultName: defaultName, navigator: navigator,
             save: save, showAlternatives: ShowAlternatives);
     Pattern = createPatternViewModel(replacementItem.Pattern, replacementItem.Alternatives.Any());
     Alternatives = replacementItem.Alternatives
         .Select(pattern => createPatternViewModel(pattern, false))
         .ToList();
     this.showAlternatives = showAlternatives;
 }