Exemple #1
0
        public CalendarGroupViewModel(XamScheduleDataManager dataManager, ICalendarService calendarService, IEventAggregator eventAggragator, IApplicationCommands applicationCommands)
        {
            CalendarUnselectedCommand         = new DelegateCommand <object>(CalendarUnselectedCommandExecuted);
            DateNavigatorSelectedDatesCommand = new DelegateCommand <ObservableCollection <DateTime> >(OnDateNavigatorSelectedDates);

            CalendarService = calendarService;
            EventAggregator = eventAggragator;

            ApplicationCommands = applicationCommands;

            DataManager = dataManager;

            GenerateMenu();

            _unselectedCalendarChangedEvent = EventAggregator.GetEvent <UnselectedCalendarChangedEvent>();
            _selectedCalendarChangedEvent   = eventAggragator.GetEvent <SelectedCalendarChangedEvent>();
            _selectedCalendarChangedEvent.Subscribe(OnSelectedCalendarChanged);

            _calendarClosedEvent = EventAggregator.GetEvent <CalendarClosedEvent>();
            _calendarClosedEvent.Subscribe(OnCalendarClosed);

            _dateNavigatorSelectedDatesChanged = EventAggregator.GetEvent <DateNavigatorSelectedDatesChanged>();

            _outlookDateNavigatorSelectedDatesChanged = EventAggregator.GetEvent <OutlookDateNavigatorSelectedDatesChanged>();
            _outlookDateNavigatorSelectedDatesChanged.Subscribe(OnOutlookDateNavigatorSelectedDatesChanged);
            _canExecuteDateNavigatorSelectedDatesCommand = true;
        }
        public CalendarViewModel(IEventAggregator eventAggragator, IDialogService dialogService, ICalendarService calendarService, ICategoryService categoryService, XamScheduleDataManager dataManager)
            : base(eventAggragator, dialogService, calendarService, categoryService, dataManager)
        {
            var unselectedCalendarChangedEvent = eventAggragator.GetEvent <UnselectedCalendarChangedEvent>();
            var selectedCalendarChangedEvent   = eventAggragator.GetEvent <SelectedCalendarChangedEvent>();

            calendarClosedEvent        = eventAggragator.GetEvent <CalendarClosedEvent>();
            viewItemsCountChangedEvent = EventAggregator.GetEvent <ViewItemsCountChangedEvent>();
            outlookDateNavigatorSelectedDatesChanged = EventAggregator.GetEvent <OutlookDateNavigatorSelectedDatesChanged>();

            this.DateNavigator = new OutlookDateNavigator();

            eventAggragator.GetEvent <DateNavigatorSelectedDatesChanged>().Subscribe(OnDateNavigatorSelectedDatesChanged);

            this.DateNavigator.SelectedDatesChanged += DateNavigator_SelectedDatesChanged;

            this.DataManager.DialogFactory = new CustomAppointmentDialogFactory(DialogService, eventAggragator);

            resourceCalendars = calendarService.GetResourceCalendars();

            var listScheduleDataConnector = new ListScheduleDataConnector();

            listScheduleDataConnector.ResourceCalendarPropertyMappings = new ResourceCalendarPropertyMappingCollection {
                UseDefaultMappings = true
            };
            listScheduleDataConnector.ResourcePropertyMappings = new ResourcePropertyMappingCollection {
                UseDefaultMappings = true
            };
            listScheduleDataConnector.AppointmentPropertyMappings = new AppointmentPropertyMappingCollection {
                UseDefaultMappings = true
            };
            listScheduleDataConnector.ActivityCategoryPropertyMappings = new ActivityCategoryPropertyMappingCollection {
                UseDefaultMappings = true
            };
            listScheduleDataConnector.AppointmentPropertyMappings.MetadataPropertyMappings = new Infragistics.MetadataPropertyMappingCollection();
            listScheduleDataConnector.AppointmentPropertyMappings.MetadataPropertyMappings.Add("IsMeetingRequest", "IsMeetingRequest");
            listScheduleDataConnector.AppointmentPropertyMappings.MetadataPropertyMappings.Add("AppointmentIds", "AppointmentIds");
            listScheduleDataConnector.AppointmentPropertyMappings.MetadataPropertyMappings.Add("To", "To");
            listScheduleDataConnector.AppointmentPropertyMappings.MetadataPropertyMappings.Add("IsNewVariance", "IsNewVariance");

            listScheduleDataConnector.ResourceItemsSource         = calendarService.GetResources();
            listScheduleDataConnector.ResourceCalendarItemsSource = resourceCalendars;
            listScheduleDataConnector.AppointmentItemsSource      = calendarService.GetAppointments();
            listScheduleDataConnector.ActivityCategoryItemsSource = categoryService.GetCategories();


            this.DataManager.DataConnector = listScheduleDataConnector;
            this.DataManager.CurrentUserId = "davids";
            this.DataManager.CalendarGroups.Add(new CalendarGroup {
                InitialCalendarIds = "davids[davidsCalendar]", InitialSelectedCalendarId = "davids[davidsCalendar]"
            });

            this.DataManager.ActivityRemoved  += DataManager_ActivityRemoved;
            this.DataManager.ActivityAdded    += DataManager_ActivityAdded;
            this.DataManager.ActivityChanging += DataManager_ActivityChanging;
            this.DataManager.ActivityChanged  += DataManager_ActivityChanged;

            //     selectedCalendarChangedEvent.Publish("Calendar");

            foreach (var calendar in resourceCalendars)
            {
                calendar.PropertyChanged += OnCalendarIsVisiblePropertyChanged;
            }

            unselectedCalendarChangedEvent.Subscribe(OnUnselectedCalendarChanged);

            SelectedTimeRangeChangedCommand = new DelegateCommand <Infragistics.DateRange?>(SelectedTimeRangeChanged);
            NewAppointmentCommand           = new DelegateCommand(NewAppointment);
            NewMeetingCommand = new DelegateCommand(NewMeeting);
        }