public AddEditSpotPage(ISpotsDataService data, FavouriteSpot spot, MediaFile image)
        {
            this.image = image;
            this.spot  = spot;
            this.data  = data;

            BindingContext = spot;

            InitializeComponent();

            mainLayout.Children.Insert(0, new FavSpotView());

            SaveImageToAzureBlobStorageAsync();
        }
        public async Task <bool> SaveFavoriteSpotAsync(FavouriteSpot spot)
        {
            Initialize();

            if (string.IsNullOrEmpty(spot.Id))
            {
                await favouriteSpotsTable.InsertAsync(spot);
            }
            else
            {
                await favouriteSpotsTable.UpdateAsync(spot);
            }

            return(true);
        }
        async Task SelectImage(bool selectImageFromCamera)
        {
            MediaFile image;

            if (selectImageFromCamera)
            {
                image = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions()
                {
                    AllowCropping      = true,
                    DefaultCamera      = CameraDevice.Rear,
                    CompressionQuality = 60,
                });
            }
            else
            {
                image = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions()
                {
                    CompressionQuality = 60
                });
            }

            if (image == null)
            {
                return;
            }

            var dlg = DependencyService.Get <IShowInProgressDialog>();

            dlg.Show("Processing the image...");

            var spot = new FavouriteSpot()
            {
                Name            = "Spot",
                RatingOutOfFive = 5,
                AddedById       = App.AuthenticatedUser != null ? App.AuthenticatedUser.UserId : "",
            };

            var processingTask = GetCurrentDevicePositionAsync().ContinueWith((locationTask) =>
            {
                var location = locationTask.Result;

                spot.Latitude  = location.Latitude;
                spot.Longitude = location.Longitude;

                new Geocoder()
                .GetAddressesForPositionAsync(new Position(location.Latitude, location.Longitude))
                .ContinueWith((possibleAddressMatches) =>
                {
                    if (possibleAddressMatches.Result.Count() > 0)
                    {
                        spot.Address = possibleAddressMatches.Result.First();
                    }
                });
            });

            // Get the description of the image using Azure Cognative Services
            var visionClient = new Microsoft.ProjectOxford.Vision.VisionServiceClient(MobileServiceClientConstants.CognativeServicesVisionApiKey);

            var processImage = visionClient.DescribeAsync(image.GetStream()).ContinueWith((imageDescriptionTask) =>
            {
                // Process the Cognative Services Result
                var suggestedCategories = String.Join(", ", imageDescriptionTask.Result.Description.Tags);
                if (String.IsNullOrEmpty(spot.Category))
                {
                    spot.Category = suggestedCategories;
                }

                var suggestedDescription = imageDescriptionTask.Result.Description.Captions.First();
                if (suggestedDescription != null && String.IsNullOrEmpty(spot.Description))
                {
                    spot.Description = suggestedDescription.Text;
                }
            });

            // Wait for the operations to finish
            await Task.WhenAll(processingTask, processImage);

            dlg.Hide();

            // Show the edit page to let them save the record or not
            var editPage = new AddEditSpotPage(Data, spot, image);
            await Navigation.PushAsync(editPage);
        }
        public async Task <bool> SaveFavoriteSpotAsync(FavouriteSpot spot)
        {
            FixedSpots.Add(spot);

            return(await Task.FromResult(true));
        }