Example #1
0
        private void RefreshAppointments()
        {
            Appointments = new ObservableAppointmentCollection();

            if (_allEvents != null && _allEvents.Any())
            {
                _allEvents
                    .Where(x => x.Event.ShowOnCalendar && x.StartTime != null && x.EndTime != null)
                    .ForEach(x => Application.Current.Dispatcher.BeginInvoke(
                        new Action(() => Appointments.Add(ConvertEventToAppointment(x)))));
            }

            if (_showCalendarNotes && _calendarNotes != null)
            {
                _calendarNotes.ForEach(x => Application.Current.Dispatcher.BeginInvoke(
                new Action(() => Appointments.Add(ConvertCalendarNoteToAppointment(x)))));
            }
        }
Example #2
0
        private void SelectableEventTypeOnPropertyChanged(object sender, PropertyChangedEventArgs args)
        {
            const string selectAllItem = "Select All"; // Define const variable to prevent spelling errors

            var obj = sender as SelectableObject<string>;
            if (obj != null && obj.Object == selectAllItem)
            {
                CalencarEventTypesFilterItems.Where(x => x.Object != selectAllItem).ForEach(item =>
                {
                    // Before changing IsSelected we need to remove PropertyChanged handler to prevent execution this method every time for every item
                    item.PropertyChanged -= SelectableEventTypeOnPropertyChanged;
                    item.IsSelected = obj.IsSelected;
                    item.PropertyChanged += SelectableEventTypeOnPropertyChanged;
                });
            }
            else
            {
                // Change selection from Select All if any item was deselected
                if (obj != null && !obj.IsSelected)
                {
                    var item = CalencarEventTypesFilterItems.FirstOrDefault(x => x.Object == selectAllItem);
                    if (item != null)
                    {
                        item.PropertyChanged -= SelectableEventTypeOnPropertyChanged;
                        item.IsSelected = false;
                        item.PropertyChanged += SelectableEventTypeOnPropertyChanged;
                    }
                }

                // If all items is selected select "Select All" item
                if (CalencarEventTypesFilterItems.Where(x => x.Object != selectAllItem).All(x => x.IsSelected))
                {
                    var item = CalencarEventTypesFilterItems.FirstOrDefault(x => x.Object == selectAllItem);
                    if (item != null)
                    {
                        item.PropertyChanged -= SelectableEventTypeOnPropertyChanged;
                        item.IsSelected = true;
                        item.PropertyChanged += SelectableEventTypeOnPropertyChanged;
                    }
                }
            }

            var selectedEventTypes =
                CalencarEventTypesFilterItems.Where(x => x.Object != selectAllItem && x.IsSelected)
                    .Select(x => x.Object);

            var selectedEvents = _allEvents.Where(x => selectedEventTypes.Contains(x.EventType.Name));

            Appointments = new ObservableAppointmentCollection();

            var eventsWithItems =
                selectedEvents.Where(x => x.Event.ShowOnCalendar && x.StartTime != null && x.EndTime != null);
            eventsWithItems.ForEach(
                x =>
                    Application.Current.Dispatcher.BeginInvoke(
                        new Action(() => Appointments.Add(ConvertEventToAppointment(x)))));

            if (_showCalendarNotes)
            {
                _calendarNotes.ForEach(x => Application.Current.Dispatcher.BeginInvoke(
                new Action(() => Appointments.Add(ConvertCalendarNoteToAppointment(x)))));
            }
        }