client/src/Iri.Modernisation.Controls/ViewModel/NavigationBar/ConsultMenuVM.cs
changeset 0 249d70e7b32d
child 25 a9c815025a1b
equal deleted inserted replaced
-1:000000000000 0:249d70e7b32d
       
     1 using System;
       
     2 using System.Net;
       
     3 using System.Windows;
       
     4 using System.Windows.Controls;
       
     5 using System.Windows.Documents;
       
     6 using System.Windows.Ink;
       
     7 using System.Windows.Input;
       
     8 using System.Windows.Media;
       
     9 using System.Windows.Media.Animation;
       
    10 using System.Windows.Shapes;
       
    11 using SLExtensions.Input;
       
    12 using Iri.Modernisation.BaseMVVM.Commands;
       
    13 using Iri.Modernisation.BaseMVVM.ViewModel;
       
    14 using Iri.Modernisation.Data.Models;
       
    15 using System.Collections.Generic;
       
    16 using System.Linq;
       
    17 namespace Iri.Modernisation.Controls.ViewModel
       
    18 {
       
    19     public class ConsultMenuVM : BaseMVVM.ViewModel.ViewModel
       
    20     {
       
    21       private List<VideoBook> _videoBooks = new List<VideoBook>();
       
    22       private List<VideoBook> list = new List<VideoBook>();
       
    23       public List<VideoBook> VideoBooks
       
    24       {
       
    25           get 
       
    26           {
       
    27               _videoBooks.Sort(new VideoBookComparer());
       
    28               if (SearchWord != String.Empty)
       
    29               {
       
    30                   return list;
       
    31               }
       
    32               else
       
    33               {
       
    34                   return _videoBooks;
       
    35               }
       
    36           
       
    37           }
       
    38           set
       
    39           {
       
    40               list = value;
       
    41               OnPropertyChanged("VideoBooks");
       
    42           }
       
    43       }
       
    44 
       
    45       public bool SearchAuthor { get; set; }
       
    46       public bool SearchContributer { get; set; }
       
    47       public bool SearchTag { get; set; }
       
    48 
       
    49       private String _searchWord= "";
       
    50       public String SearchWord 
       
    51       { 
       
    52           get
       
    53           {
       
    54               return _searchWord;
       
    55           }
       
    56           
       
    57           set 
       
    58           {
       
    59               _searchWord = value;
       
    60               OnPropertyChanged("SearchWord");
       
    61           } 
       
    62       }
       
    63      
       
    64         public ConsultMenuVM()
       
    65         {
       
    66             SearchAuthor = true;
       
    67           InitializeCommands();
       
    68         }
       
    69 
       
    70         private void InitializeCommands()
       
    71         {
       
    72            Commands.ConsultMenu.GetBook.Executed += new EventHandler<ExecutedEventArgs>(GetBook_Executed);
       
    73          }
       
    74         public ConsultMenuVM(List<VideoBook> argList)
       
    75         {
       
    76             _videoBooks = argList;
       
    77             SearchAuthor = true;
       
    78             InitializeCommands();
       
    79         }
       
    80 
       
    81         
       
    82 
       
    83         void GetBook_Executed(object sender, ExecutedEventArgs e)
       
    84         {
       
    85            
       
    86            if (SearchAuthor)
       
    87             {
       
    88                 var query = from c in _videoBooks
       
    89                             where c.Author.UserName.Contains(_searchWord)
       
    90                             select c;
       
    91                 VideoBooks = query.ToList();
       
    92             }
       
    93             if (SearchContributer)
       
    94             {
       
    95                 List<VideoBook> temp = new List<VideoBook>();
       
    96                 foreach (VideoBook Book in _videoBooks)
       
    97                 {
       
    98                     foreach (VideoChapter Chapter in Book.Chapters)
       
    99                     {
       
   100                         foreach (Annotation Annotation in Chapter.Annotations)
       
   101                         {
       
   102                             if ( Annotation.Contributer.UserName.Contains(_searchWord))
       
   103                             {
       
   104                                 temp.Add(Book);
       
   105                             }
       
   106                         }
       
   107                     }
       
   108                 }
       
   109                 VideoBooks = temp;
       
   110             }
       
   111             if(SearchTag)
       
   112             {
       
   113                 List<VideoBook> temp = new List<VideoBook>();
       
   114                 foreach (VideoBook Book in _videoBooks)
       
   115                 {
       
   116                     foreach (VideoChapter Chapter in Book.Chapters)
       
   117                     {
       
   118                         foreach (Annotation Annotation in Chapter.Annotations)
       
   119                         {
       
   120                             if (Annotation.Tags.Contains(_searchWord))
       
   121                             {
       
   122                                 temp.Add(Book);
       
   123                             }
       
   124                         }
       
   125                         foreach (SegmentIndex Segment in Chapter.Index)
       
   126                         {
       
   127                             if (Segment.Tags.Contains(_searchWord))
       
   128                             {
       
   129                                 temp.Add(Book);
       
   130                             }
       
   131                         }
       
   132                     }
       
   133                 }
       
   134                 VideoBooks = temp;
       
   135             }
       
   136         }
       
   137        
       
   138     }
       
   139 }