public async override void OnNavigatedTo(NavigationParameters parameters) { base.OnNavigatedTo(parameters); try { if (parameters.Any(a => a.Key.Equals("posterId"))) { Poster = await App.ApiService.GetPoster(parameters.GetValue <int>("posterId"), "bearer " + Settings.AuthToken); PetType = Poster.PetType == 1 ? "Cachorro" : "Gato"; State = Poster.State; foreach (var item in Poster.PetPictures) { byte[] file; try { file = await App.ApiService.Download(item.Url); } catch { continue; } PetImages.Add(new PetPictureItem { Id = Guid.NewGuid().ToString(), Image = file }); } EditPosterCommand.RaiseCanExecuteChanged(); } } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); } }
private async void PickPhotoCommandExecute() { try { var action = await DisplayPictureAlert(); var pictureService = Xamarin.Forms.DependencyService.Get <PictureService>(); var file = await pictureService.GetPicture(action); if (file != null) { using (var memoryStream = new MemoryStream()) { file.GetStream().CopyTo(memoryStream); file.Dispose(); PetImages.Add(new PetPictureItem { Id = Guid.NewGuid().ToString(), Image = memoryStream.ToArray() }); EditPosterCommand.RaiseCanExecuteChanged(); } } } catch (Exception ex) { await _dialogService.DisplayAlertAsync("Erro", ex.Message, "Fechar"); } }