private void search() { if (searchString == null || searchString == "") { students.Clear(); foreach (var s in Students) { StudentCell cell = new StudentCell(s); cell.textColour = Application.Current.Resources["OnSurface"] as Color? ?? Color.Black; students.Add(cell); } } else { string searchStringTemp = searchString.ToLower(); List <Models.Student> searchResults = Students.Where <Models.Student>(s => $"{s.Forename.ToLower()} {s.Surname.ToLower()}".StartsWith(searchStringTemp) || s.Forename.ToLower().StartsWith(searchStringTemp) || s.Surname.ToLower().StartsWith(searchStringTemp) || s.SwimEnglandNumber.StartsWith(searchStringTemp)).ToList(); students.Clear(); foreach (var s in searchResults) { StudentCell cell = new StudentCell(s); cell.textColour = Application.Current.Resources["OnSurface"] as Color? ?? Color.Black; students.Add(cell); } } }
public static Models.Student ConvertToStudent(StudentCell cell) { return(new Models.Student() { Forename = cell.Forename, Surname = cell.Surname, SwimEnglandNumber = cell.SwimEnglandNumber, MedicalDetails = cell.MedicalDetails, DateOfBirth = cell.DateOfBirth, CurrentGradeNumber = cell.CurrentGradeNumber }); }
private void selectStudent(object obj) { StudentCell currentCell = obj as StudentCell; currentCell.textColour = Application.Current.Resources["OnSecondary"] as Color? ?? Color.Black; List <StudentCell> temp = students.Except <StudentCell>(new List <StudentCell>() { currentCell }).ToList(); foreach (var a in temp) { a.textColour = Application.Current.Resources["OnSurface"] as Color? ?? Color.Black; } Shell.Current.Navigation.PushAsync(new Views.StudentDetailPage(StudentCell.ConvertToStudent(currentCell))); }
private void loadData() { isRefreshing = true; Models.AllStudentsResponse resp; Task <Models.AllStudentsResponse> task = Task.Run(() => restService.GetAllStudentsAsync()); task.ContinueWith(t => Device.BeginInvokeOnMainThread( async() => { if (t.IsFaulted) { await App.Current.MainPage.DisplayAlert("Connection error", "There was an error connecting to the server", "Try Again"); } resp = t.Result; if (!resp.Success) { isRefreshing = false; await App.Current.MainPage.DisplayAlert(resp.Error.Message, resp.Error.Detail, "Try again"); return; } Students = resp.Students.values; students.Clear(); foreach (var s in Students) { StudentCell cell = new StudentCell(s); cell.textColour = Application.Current.Resources["OnSurface"] as Color? ?? Color.Black; students.Add(cell); } isRefreshing = false; search(); } )); }