public MainWindowViewModel(
     IAssigmentsCache assigmentsCache, 
     ITagsCache tagsCache,
     IAddAssigmentService addAssigmentService,
     Func<IAssigment, IAssigmentViewModel> assigmentViewModelFactory,
     Func<ITag, ISelectableTagViewModel> tagViewModelFactory)
 {
     ApplicationTitle = "ToDo";
     Assigments = new ReadOnlyObservableCollection<IAssigmentViewModel>(_assigments);
     AvalibleTags = new ReadOnlyObservableCollection<ISelectableTagViewModel>(_avalibleTags);
     AddAssigment = new AddAssigmentCommand(this);
     _addAssigmentService = addAssigmentService;
     _assigmentViewModelFactory = assigmentViewModelFactory;
     _tagViewModelFactory = tagViewModelFactory;
     foreach (var assigment in assigmentsCache.Items)
     {
         _assigments.Add(assigmentViewModelFactory(assigment));
     }
     assigmentsCache.AssimentAdded += OnAssimentAdded;
     foreach (var tag in tagsCache.Items)
     {
         _avalibleTags.Add(_tagViewModelFactory(tag));
     }
     tagsCache.TagAdded += OnTagAdded;
 }
 public AddAssigmentService(IAssigmentsCache assigmentsCache, ITagsCache tagsCache, Func<string, ITag[], IAssigment> assigmentFactory, Func<string, ITag> tagFactory)
 {
     _assigmentsCache = assigmentsCache;
     _tagsCache = tagsCache;
     _assigmentFactory = assigmentFactory;
     _tagFactory = tagFactory;
 }
Example #3
0
 public static Func<string, ITag> CreateTagFactory(ITagsCache tagsCache)
 {
     return s =>
     {
         var existingTag = tagsCache.Items.FirstOrDefault(tag => tag.Text == s);
         if (existingTag != null) return existingTag;
         return new Tag(s);
     };
 }