Esempio n. 1
0
 void OnCounterpartyChanged(Counterparty newCounterparty)
 {
     if (newCounterparty != null)
     {
         SelectedCounterparty = newCounterparty;
         CounterpartyChangeEvent evt = eventAggregator.GetEvent <CounterpartyChangeEvent>();
         evt.Publish(newCounterparty);
     }
 }
Esempio n. 2
0
        public CounterpartyViewModel(
            ICounterpartyService dataService,
            IEventAggregator eventAggregator)
        {
            this.dataService     = dataService;
            this.eventAggregator = eventAggregator;
            this.counterparties  = new ObservableCollection <Counterparty>(dataService.FindAll());

            this.addCommand = new DelegateCommand(
                () =>
            {
                NewCounterparty = Counterparty.CreateNewCounterparty();
                NewCounterparty.PropertyChanged += (s, e) =>
                {
                    saveCommand.RaiseCanExecuteChanged();
                };
                // when first displayed the new counterparty will be invalid so we should disable the Save button
                saveCommand.RaiseCanExecuteChanged();
            }
                );

            this.saveCommand = new DelegateCommand(
                () =>
            {
                dataService.Add(NewCounterparty);
                this.Counterparties = new ObservableCollection <Counterparty>(dataService.FindAll());
                RaisePropertyChanged("Counterparties");

                // Don't use the NewCounterparty object as it won't be in the Counterparties list
                var newCounterparty = this.Counterparties.Where(c => c.Id == NewCounterparty.Id).Single();
                OnCounterpartyChanged(newCounterparty);
            },
                () =>
            {
                return((NewCounterparty == null) ? false : NewCounterparty.IsValid);
            }
                );

            if (counterparties.Count() > 0)
            {
                SelectedCounterparty = counterparties.First();
                CounterpartyChangeEvent evt = eventAggregator.GetEvent <CounterpartyChangeEvent>();
                evt.Publish(SelectedCounterparty);
            }
        }