private async void BtnUpdate_OnClick(object sender, RoutedEventArgs e) { if (!isCreate) { var pilotInput = ReadTextBoxesData(); if (pilotInput != null && _selectedPilot != null) { try { await Service.Update(pilotInput, _selectedPilot.Id); } catch { Info.Text = "Server error!"; } var itemIndex = Pilots.ToList().FindIndex(x => x.Id == _selectedPilot.Id); var item = Pilots.ToList().ElementAt(itemIndex); Pilots.RemoveAt(itemIndex); item = pilotInput; item.Id = _selectedPilot.Id; Pilots.Insert(itemIndex, item); TbId.Text = "Pilot Id :" + item.Id; TbFName.Text = "First name : " + item.FirstName; TbLName.Text = "Last name : " + item.LastName; TbBirth.Text = "Birth : " + item.DateOfBirth; TbExp.Text = "Experience : " + item.Experience; } } }
protected void SearchAsync() { List <Pilot> temp = Pilots.ToList(); Pilots.Clear(); if (string.IsNullOrWhiteSpace(SearchFilter)) { temp.Clear(); UpdateDataAsync(); } else { Pilots = new ObservableCollection <Pilot>(temp.Where(s => s.FirstName.StartsWith(SearchFilter, StringComparison.CurrentCultureIgnoreCase) || s.LastName.StartsWith(SearchFilter, StringComparison.CurrentCultureIgnoreCase)).ToList()); } RaisePropertyChanged(nameof(Pilots)); }