Esempio n. 1
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;
            }
        }
        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;
            }
        }