diff -r 000000000000 -r 249d70e7b32d client/src/Iri.Modernisation.Controls/ViewModel/NavigationBar/ConsultMenuVM.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/src/Iri.Modernisation.Controls/ViewModel/NavigationBar/ConsultMenuVM.cs Wed Nov 18 15:30:31 2009 +0100 @@ -0,0 +1,139 @@ +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using SLExtensions.Input; +using Iri.Modernisation.BaseMVVM.Commands; +using Iri.Modernisation.BaseMVVM.ViewModel; +using Iri.Modernisation.Data.Models; +using System.Collections.Generic; +using System.Linq; +namespace Iri.Modernisation.Controls.ViewModel +{ + public class ConsultMenuVM : BaseMVVM.ViewModel.ViewModel + { + private List _videoBooks = new List(); + private List list = new List(); + public List VideoBooks + { + get + { + _videoBooks.Sort(new VideoBookComparer()); + if (SearchWord != String.Empty) + { + return list; + } + else + { + return _videoBooks; + } + + } + set + { + list = value; + OnPropertyChanged("VideoBooks"); + } + } + + public bool SearchAuthor { get; set; } + public bool SearchContributer { get; set; } + public bool SearchTag { get; set; } + + private String _searchWord= ""; + public String SearchWord + { + get + { + return _searchWord; + } + + set + { + _searchWord = value; + OnPropertyChanged("SearchWord"); + } + } + + public ConsultMenuVM() + { + SearchAuthor = true; + InitializeCommands(); + } + + private void InitializeCommands() + { + Commands.ConsultMenu.GetBook.Executed += new EventHandler(GetBook_Executed); + } + public ConsultMenuVM(List argList) + { + _videoBooks = argList; + SearchAuthor = true; + InitializeCommands(); + } + + + + void GetBook_Executed(object sender, ExecutedEventArgs e) + { + + if (SearchAuthor) + { + var query = from c in _videoBooks + where c.Author.UserName.Contains(_searchWord) + select c; + VideoBooks = query.ToList(); + } + if (SearchContributer) + { + List temp = new List(); + foreach (VideoBook Book in _videoBooks) + { + foreach (VideoChapter Chapter in Book.Chapters) + { + foreach (Annotation Annotation in Chapter.Annotations) + { + if ( Annotation.Contributer.UserName.Contains(_searchWord)) + { + temp.Add(Book); + } + } + } + } + VideoBooks = temp; + } + if(SearchTag) + { + List temp = new List(); + foreach (VideoBook Book in _videoBooks) + { + foreach (VideoChapter Chapter in Book.Chapters) + { + foreach (Annotation Annotation in Chapter.Annotations) + { + if (Annotation.Tags.Contains(_searchWord)) + { + temp.Add(Book); + } + } + foreach (SegmentIndex Segment in Chapter.Index) + { + if (Segment.Tags.Contains(_searchWord)) + { + temp.Add(Book); + } + } + } + } + VideoBooks = temp; + } + } + + } +}