public List <IResource> GetResource(eResourceType type, int id) { var list = new List <IResource>(); if (type == eResourceType.Channel) { list.AddRange(this.Channels.Where(c => c.Id == id)); } else if (type == eResourceType.UnitPhone) { list.AddRange(this.UnitPhones.Where(p => p.Id == id)); if (list.Count == 0) { var units = NovaAlertCommon.LoadUnitPhones(id); if (units.Count > 0) { foreach (var p in units) { var vm = new UnitPhoneViewModel(p); this.UnitPhones.Add(vm); list.Add(vm); } } } } else if (type == eResourceType.Modem) { list.Add(this.Modem); } return(list); }
private CommonResource() { this.Clients = new ObservableCollection <Client>(); this.Actions = new ClientActionQueue(); LoadPhones(); // Load UnitPhone from database this.UnitPhones = new ObservableCollection <UnitPhoneViewModel>(); this.UnitPhones.CollectionChanged += Resource_CollectionChanged; foreach (var item in NovaAlertCommon.LoadUnitPhones()) { this.UnitPhones.Add(new UnitPhoneViewModel(item)); } // Load PO list this.POes = new List <POViewModel>(); foreach (var po in NovaAlertCommon.GetPOes()) { this.POes.Add(new POViewModel(po)); } // Connection this.Connetions = new ObservableCollection <SwitchConnection>(); this.SoundChannels = new List <SoundChannel>(); this.SoundConfigVM = new SoundCardConfigViewModel(this.CreateSoundChannels); NovaAlertCommon.Instance.OnContactChanged += OnContactChanged; }
void OnContactChanged(object sender, EntityChangedEventArgs e) { var list = this.UnitPhones.Where(u => u.Id == e.Id).ToList(); foreach (var up in list) { this.UnitPhones.Remove(up); } foreach (var item in NovaAlertCommon.LoadUnitPhones(e.Id)) { this.UnitPhones.Add(new UnitPhoneViewModel(item)); } }