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(); }
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); }
/// <summary> /// Called when [imports satisfied]. /// </summary> public override void OnImportsSatisfied() { base.OnImportsSatisfied(); CurrentMappingBasis = ConfigurationService.HospitalRegion; ReferenceExists = !IsInitialMapping; AddStateToContextCommand = new DelegateCommand(OnAddState, CanAddState); RemoveStateFromContextCommand = new DelegateCommand <SelectListItem>(OnRemoveStateCommand, CanRemoveState); ApplyContextCommand = new DelegateCommand(OnApplyContextCommand, CanApplyContextCommand); NavigateBackCommand = new DelegateCommand(OnNavigateBackCommand); SelectedStates = CollectionHelper.EmptyListCollectionView <SelectListItem>(); var crit = PredicateBuilder.True <State>(); ListExtensions.ForEach(CurrentMappingBasis.DefaultStates.OfType <string>().ToList(), ab => crit = crit.And(st => st.Abbreviation != ab)); var availStates = new List <SelectListItem>(); availStates.Add(SELECT_STATE); var allStates = HospitalRegistryService.GetStates(null).ToList(); availStates.AddRange(allStates.AsQueryable() .Where(crit) .Select(state => new SelectListItem { Model = state, Text = state.Abbreviation, Value = state.Abbreviation }) //.Concat(new[] { SELECT_STATE }) .OrderBy(item => item.Text).ToList()); AvailableStates = availStates.ToListCollectionView(); crit = PredicateBuilder.False <State>(); ListExtensions.ForEach(CurrentMappingBasis.DefaultStates .OfType <string>(), ab => crit = crit.Or(st => st.Abbreviation == ab)); var selectedStates = allStates.AsQueryable().Where(crit).Select(st => new SelectListItem { Text = st.Abbreviation, Value = st.Abbreviation, Model = st }).ToList(); // Setting the Selected Reporting States for Global use. //if (!MonahrqContext.ReportingStatesContext.Any(s => selectedStates.Any(s1 => s.In(s1)) )) // MonahrqContext.ReportingStatesContext.AddRange(selectedStates); MonahrqContext.ReportingStatesContext.AddRange(selectedStates.Select(s => s.Text).ToList()); SelectedStates = selectedStates.ToListCollectionView(); SelectedStates.CommitNew(); AvailableStates.CommitEdit(); AvailableStates.MoveCurrentToFirst(); SelectedState = SELECT_STATE; // Regions for combo box, Object type return "SELECT" on display, and NULL on return using RegionTypes = (new[] { typeof(object), typeof(CustomRegion), typeof(HealthReferralRegion), typeof(HospitalServiceArea) }).ToListCollectionView(); SelectedRegionType = CurrentMappingBasis.SelectedRegionType; }