public async Task Recherche() { if (ResearchLabel != null) { Announcements.Clear(); bool trouvé = false; var AnnouncementsTemp = await GetAnnouncementsUser(); AnnouncementVisu anouncementTemp = null; foreach (AnnouncementVisu announc in AnnouncementsTemp) { if (trouvé) { break; } if (announc.idAnnoun == Int32.Parse(ResearchLabel)) { trouvé = true; anouncementTemp = announc; } } if (anouncementTemp != null) { Announcements.Add(anouncementTemp); } } }
public async Task <ObservableCollection <AnnouncementVisu> > GetAnnouncementsUser() { ObservableCollection <AnnouncementVisu> announcements = new ObservableCollection <AnnouncementVisu>(); try { SingleConnection.Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token.Id); if (Token.Id == null) { navPage.NavigateTo("Login"); await dialogService.ShowMessageBox("Votre session est expirée", "Session expiré"); } else { var response = await SingleConnection.Client.GetAsync(SingleConnection.Client.BaseAddress + "Account/Announcement/" + SelectedUser.User.UserName); if (response.IsSuccessStatusCode) { var jsonAnnouncement = response.Content.ReadAsStringAsync().Result; Announcements = AnnouncementVisu.Deserialize(jsonAnnouncement); } else { if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError) { await dialogService.ShowMessageBox("La connection au serveur a été perdue", "Erreur"); navPage.NavigateTo("Login"); } else { await dialogService.ShowMessageBox("Impossible de retrouve la liste des annonces, veuillez réessayer", "Erreur"); } } } } catch (HttpRequestException) { await dialogService.ShowMessageBox("La connection au serveur a été perdue", "Erreur connection"); navPage.NavigateTo("Login"); } NbAnnonceUser = Announcements.Count; return(Announcements); }