Esempio n. 1
0
        async public void LoadPlaces()
        {
            var placesResponse = await ApiService.GetPlaces();

            if (placesResponse.HttpResponse.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var picturesResponse = await ApiService.GetPictures();

                if (picturesResponse.HttpResponse.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    Places = new List <PlaceViewModel>();
                    foreach (var place in placesResponse.Response)
                    {
                        var placeViewModel = new PlaceViewModel
                        {
                            Description = place.Description,
                            Id          = place.Id,
                            Likes       = place.Likes,
                            Location    = place.Location,
                            Name        = place.Name,
                            Thumbnail   = place.Thumbnail,
                            Pictures    = new ObservableCollection <PictureViewModel>()
                        };

                        var pictures = picturesResponse.Response.Where(x => x.PlaceId == place.Id);
                        if (pictures != null && pictures.Count() > 0)
                        {
                            foreach (var picture in pictures)
                            {
                                placeViewModel.Pictures.Add(new PictureViewModel {
                                    Id = picture.Id, Uri = picture.Uri
                                });
                            }
                        }
                        Places.Add(placeViewModel);
                    }
                }
                else
                {
                    await App.NavigationPage.DisplayAlert("Ups!", "Ha ocurrido un error obteniendo datos del servidor.", "Aceptar");
                }
            }
            else
            {
                await App.NavigationPage.DisplayAlert("Ups!", "Ha ocurrido un error obteniendo datos del servidor.", "Aceptar");
            }
        }
Esempio n. 2
0
        async public void SetLike(PlaceViewModel placeViewModel)
        {
            var placeResponse = await ApiService.UpdatePlace(new Dtos.PlaceDto
            {
                Description = placeViewModel.Description,
                Id          = placeViewModel.Id,
                Likes       = placeViewModel.Likes,
                Location    = placeViewModel.Location,
                Name        = placeViewModel.Name,
                Thumbnail   = placeViewModel.Thumbnail,
            });

            if (placeResponse.HttpResponse.StatusCode == System.Net.HttpStatusCode.OK ||
                placeResponse.HttpResponse.StatusCode == System.Net.HttpStatusCode.NoContent)
            {
                await App.NavigationPage.DisplayAlert("Exitoso!", "Gracias por proporcionar un voto por este lugar.", "Aceptar");
            }
            else
            {
                await App.NavigationPage.DisplayAlert("Ups!", "Ha ocurrido un error enviando datos a el servidor.", "Aceptar");
            }
        }