예제 #1
0
        private void Initialize()
        {
            AddStateToContextCommand = new DelegateCommand(OnAddState, CanAddState);
            RemoveStateCommand       = new DelegateCommand <State>(OnRemoveStateCommand, CanRemoveState);

            SelectedStates  = CollectionHelper.EmptyListCollectionView <State>();
            EventAggregator = ServiceLocator.Current.GetInstance <IEventAggregator>();
            StateCollection = Context.HospitalRegistryService
                              .GetStates()
                              .Select(state => new KeyValuePair <string, State>(state.Abbreviation, state))
                              .Concat(new[] { new KeyValuePair <string, State>(SELECT_STATE, null) })
                              .OrderBy(item => item.Value != null)
                              .ThenBy(item => item.Key).ToListCollectionView();

            var defaultStates = HospitalRegion.Default.DefaultStates.OfType <string>().ToList();

            defaultStates.ForEach(s =>
            {
                var toRemove = StateCollection.OfType <KeyValuePair <string, State> >().First(kvp => kvp.Key == s);
                StateCollection.Remove(toRemove);
                SelectedStates.AddNewItem(toRemove.Value);
            });
            SelectedStates.CommitNew();
            StateCollection.CommitEdit();
            StateCollection.MoveCurrentToFirst();
            /*Regions for combo box, Object type return "SELECT" on display, and NULL on return using  */
            RegionTypes = (new[] {
                typeof(object),
                typeof(HealthReferralRegion),
                typeof(HospitalServiceArea)
            }).ToListCollectionView();

            SelectedRegionType = HospitalRegion.Default.SelectedRegionType;
        }
 /// <summary>
 /// Adds the state to context.
 /// </summary>
 /// <param name="stateKvp">The state KVP.</param>
 private void AddStateToContext(SelectListItem stateKvp)
 {
     SelectedStates.AddNewItem(stateKvp);
     AvailableStates.Remove(stateKvp);
     AvailableStates.MoveCurrentToFirst();
     SelectedStates.CommitNew();
     ApplyContextCommand.RaiseCanExecuteChanged();
 }
예제 #3
0
        private void OnAddState()
        {
            if (SelectedState.Value == null)
            {
                return;
            }

            var state = SelectedState.Value;

            SelectedStates.AddNewItem(SelectedState.Value);
            StateCollection.Remove(SelectedState);
            StateCollection.MoveCurrentToFirst();
            SelectedStates.CommitNew();

            RaisePropertyChanged(() => SelectedStates);
            RaisePropertyChanged(() => StateCollection);
        }