private void NotifyAllTrains(List<Train> trains)
 {
     List<MessageArgs> args = new List<MessageArgs>();
     foreach (var train in trains)
         args.Add(new MessageArgs
         {
             From = cmbBoxPointFrom.Text,
             To = cmbBoxPointTo.Text,
             Date = Helper.ConvertDate(datePicker.SelectedDate.Value.ToShortDateString()),
             TrainNumber = train.Number,
             PlacesCount = train.PlacesCount.ToString()
         });
     foreach (INotifier n in SearchSettings.Instance.Notifiers)
         n.Notify(args);
     new Notify("New ticket!",args).ShowNotify();
     SetToolTipNotify();
     List<Car> cars = new List<Car>();
     foreach (var t in trains)
         cars.AddRange(t.Cars);
     TicketsViewModel ticketViewModel = new TicketsViewModel(cars, trains);
     this.DataContext = ticketViewModel;
 }
 private void dispatcherTimer_Tick(object sender, EventArgs e)
 {
     //Search logic by parameters from search settings
     int lastCount = 0;
     int count = 0;
     if (cmbBoxTrainNumber.Text == "Все поезда")
     {
         List<Train> trains = Train.GetAllTrainsByRouteInfo(cmbBoxPointFrom.Text, cmbBoxPointTo.Text, Helper.ConvertDate(datePicker.SelectedDate.Value.ToShortDateString()), SearchSettings.Instance.EnableReserve, SearchSettings.Instance.ReservePriority);
         foreach (var train in trains)
         {
             if (SearchSettings.Instance.PlaceTypes.Count != 0 && SearchSettings.Instance.CarTypes.Count != 0)
             {
                 count = train.GetCountPlacesByCarAndPlaceTypes(SearchSettings.Instance.PlaceTypes, SearchSettings.Instance.CarTypes);
             }
             else if (SearchSettings.Instance.PlaceTypes.Count != 0 && SearchSettings.Instance.CarTypes.Count == 0)
             {
                 count = train.GetCountPlacesByPlaceType(SearchSettings.Instance.PlaceTypes);
             }
             else if (SearchSettings.Instance.PlaceTypes.Count == 0 && SearchSettings.Instance.CarTypes.Count != 0)
             {
                 count = train.GetCountPlacesByCarType(SearchSettings.Instance.CarTypes);
             }
             else
                 count = train.PlacesCount;
         }
         if (lastCount != count)
         {
             NotifyAllTrains(trains);
             lastCount = count;
         }
     }
     else
     {
         Train train = Train.GetAllTrainInfo(cmbBoxPointFrom.Text, cmbBoxPointTo.Text, Helper.ConvertDate(datePicker.SelectedDate.Value.ToShortDateString()), cmbBoxTrainNumber.Text, cmbBoxTrainNumber.SelectedIndex, SearchSettings.Instance.EnableReserve, SearchSettings.Instance.ReservePriority);
         if (SearchSettings.Instance.PlaceTypes.Count != 0 && SearchSettings.Instance.CarTypes.Count != 0)
         {
             count = train.GetCountPlacesByCarAndPlaceTypes(SearchSettings.Instance.PlaceTypes, SearchSettings.Instance.CarTypes);
         }
         else if (SearchSettings.Instance.PlaceTypes.Count != 0 && SearchSettings.Instance.CarTypes.Count == 0)
         {
             count = train.GetCountPlacesByPlaceType(SearchSettings.Instance.PlaceTypes);
         }
         else if (SearchSettings.Instance.PlaceTypes.Count == 0 && SearchSettings.Instance.CarTypes.Count != 0)
         {
             count = train.GetCountPlacesByCarType(SearchSettings.Instance.CarTypes);
         }
         else
             count = train.PlacesCount;
         if (lastCount != count)
         {
             foreach (INotifier n in SearchSettings.Instance.Notifiers)
             {
                 n.Notify(new List<MessageArgs>{new MessageArgs
             {
                 From = cmbBoxPointFrom.Text,
                 To = cmbBoxPointTo.Text,
                 Date = Helper.ConvertDate(datePicker.SelectedDate.Value.ToShortDateString()),
                 TrainNumber = train.Number,
                 PlacesCount = count.ToString()
             }});
             }
             new Notify("New ticket!",
                 new List<MessageArgs>{new MessageArgs
             {
                 From = cmbBoxPointFrom.Text,
                 To = cmbBoxPointTo.Text,
                 Date = Helper.ConvertDate(datePicker.SelectedDate.Value.ToShortDateString()),
                 TrainNumber = train.Number,
                 PlacesCount = train.PlacesCount.ToString()
             }}).ShowNotify();
             SetToolTipNotify();
             lastCount = count;
             TicketsViewModel t = new TicketsViewModel(train.Cars, null);
             this.DataContext = t;
         }
     }
 }