Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        private async void EditPosterCommandExecute()
        {
            ShowLoading = true;
            try
            {
                var posterInput = new PosterInput
                {
                    Id          = Poster.Id,
                    PetName     = Poster.PetName,
                    PetPictures = PetImages.Select(s => s.Image).ToList(),
                    PetType     = PetType == "Cachorro" ? 1 : 2,
                    Castrated   = Poster.Castrated,
                    Dewormed    = Poster.Dewormed,
                    IsAdopted   = Poster.IsAdopted,
                    Country     = "Brasil",
                    State       = Poster.State,
                    City        = Poster.City
                };

                await App.ApiService.UpdatePoster(posterInput, "bearer " + Settings.AuthToken);

                await _dialogService.DisplayAlertAsync("Sucesso!", "Anúncio atualizado com sucesso.", "Ok");

                await _navigationService.NavigateAsync($"{nameof(MyPostersPage)}");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.StackTrace);
            }finally
            {
                ShowLoading = false;
            }
        }
Esempio n. 3
0
        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");
            }
        }
        private async void CreatePosterCommandExecute()
        {
            ShowLoading = true;
            try
            {
                var posterInput = new PosterInput
                {
                    UserId      = int.Parse(Settings.UserId),
                    PetName     = PetName,
                    PetPictures = PetImages.Select(s => s.Image).ToList(),
                    PetType     = PetType == "Cachorro" ? 1 : 2,
                    Castrated   = IsCastrated,
                    Dewormed    = IsDewormed,
                    Country     = "Brasil",
                    State       = State,
                    City        = City
                };

                await App.ApiService.CreatePoster(posterInput, "bearer " + Settings.AuthToken);

                await _dialogService.DisplayAlertAsync("Sucesso!", "Anúncio criado com sucesso.", "Ok");

                await _navigationService.NavigateAsync($"app:///{nameof(MenuPage)}/NavigationPage/{nameof(MyPostersPage)}");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.StackTrace);
            }
            finally
            {
                ShowLoading = false;
            }
        }
Esempio n. 5
0
 private bool EditPosterCommandCanExecute()
 {
     return(PetImages.Any() &&
            !string.IsNullOrEmpty(Poster.PetName) &&
            Poster.PetType > 0 &&
            !string.IsNullOrEmpty(Poster.State) &&
            !string.IsNullOrEmpty(Poster.City));
 }
 private bool CreatePosterCommandCanExecute()
 {
     return(PetImages.Any() &&
            !string.IsNullOrEmpty(PetName) &&
            !string.IsNullOrEmpty(PetType) &&
            !string.IsNullOrEmpty(State) &&
            !string.IsNullOrEmpty(City));
 }
Esempio n. 7
0
        public IActionResult GetImage(int id)
        {
            // don't care about validation, if it's invalid
            // then just get the default image
            // this method returns the image path and the MIME type.
            var image = PetImages.GetImageById(id);

            return(File(image.Path, image.MIME));
        }
Esempio n. 8
0
 private void DeletePetPictureCommandExecute(string imageId)
 {
     PetImages.Remove(PetImages.Single(w => w.Id == imageId));
     EditPosterCommand.RaiseCanExecuteChanged();
 }