public async Task<bool> CreateSpotAsync(SpotObject so)
 {
     MSSpotObject spot = SpotObject.ConvertToMSSpotObject(so);
     await App.MobileService.GetTable<MSSpotObject>().InsertAsync(spot);
     so.Id = spot.id;
     this.NewSpot = so;
     return true;
 }
 public SpotViewItem(SpotObject spot)
 {
     this.SpotName = spot.SpotName;
     this.AccountId = spot.PtcAccountId;
     this.AccountName = spot.PtcAccountName;
     this.SpotId = spot.Id;
     this.SpotDistance = spot.SpotDistance;
     this.DeleteImage = FileObjectViewModel.DELETE_IMAGE_URI;
     this.DeleteImagePress = true;
     this.SpotNameInitialImage = this.SpotName.Substring(0, 1);
     this.SpotPassword = spot.Password;
     this.CreateAt = spot.CreateAt;
 }
        private async void MakeNewSpot(string spotName, bool isPrivate, string spotPassword = NULL_PASSWORD)
        {
            if (NetworkInterface.GetIsNetworkAvailable())
            {
                // Check whether GPS is on or not
                if (GeoHelper.GetLocationStatus() != PositionStatus.Disabled)  // GPS is on
                {
                    // Show Pining message and Progress Indicator
                    base.Dispatcher.BeginInvoke(() =>
                    {
                        uiNewSpotMessage.Text = AppResources.PiningSpot;
                        uiNewSpotMessage.Visibility = Visibility.Visible;
                    });
                    base.SetProgressIndicator(true);

                    try
                    {
                        // Wait sign in tastk
                        // Get this Ptc account to make a new spot
                        await TaskHelper.WaitTask(App.AccountManager.GetPtcId());
                        PtcAccount account = await App.AccountManager.GetPtcAccountAsync();

                        // Make a new spot around position where the user is.
                        Geoposition geo = await GeoHelper.GetGeopositionAsync();
                        SpotObject spotObject = new SpotObject(spotName, geo.Coordinate.Latitude, geo.Coordinate.Longitude, account.Email, account.Name, 0, isPrivate, spotPassword, DateTime.Now.ToString());
                        await App.SpotManager.CreateSpotAsync(spotObject);
                        ((SpotViewModel)PhoneApplicationService.Current.State[SPOT_VIEW_MODEL_KEY]).IsDataLoaded = false;
                        this.SpotId = spotObject.Id;

                        // Move to Explorer page which is in the spot.
                        string parameters = "?spotId=" + this.SpotId + "&spotName=" + spotName + "&accountId=" + account.Email + "&accountName=" + account.Name;
                        NavigationService.Navigate(new Uri(EventHelper.EXPLORER_PAGE + parameters, UriKind.Relative));
                    }
                    catch
                    {
                        // Show Pining message and Progress Indicator
                        base.Dispatcher.BeginInvoke(() =>
                        {
                            uiNewSpotMessage.Text = AppResources.BadCreateSpotMessage;
                        });
                    }
                    finally
                    {
                        base.SetProgressIndicator(false);
                    }
                }
                else  // GPS is not on
                {
                    MessageBox.Show(AppResources.NoLocationServiceMessage, AppResources.NoLocationServiceCaption, MessageBoxButton.OK);
                }
            }
            else
            {
                MessageBox.Show(AppResources.InternetUnavailableMessage, AppResources.InternetUnavailableCaption, MessageBoxButton.OK);
            }
        }
 public static SpotObject ConvertToSpotObject(MSSpotObject msso)
 {
     SpotObject so = new SpotObject();
     so.Id = msso.id;
     so.SpotName = msso.spot_name;
     so.Latitude = msso.spot_latitude;
     so.Longtitude = msso.spot_longtitude;
     so.PtcAccountId = msso.account_id;
     so.PtcAccountName = msso.account_name;
     so.SpotDistance = msso.spot_distance;
     so.Password = msso.spot_password;
     so.IsPrivate = msso.is_private;
     so.CreateAt = msso.create_at;
     return so;
 }
 public static MSSpotObject ConvertToMSSpotObject(SpotObject so)
 {
     return new MSSpotObject(so.SpotName, so.Latitude, so.Longtitude, so.PtcAccountId, so.PtcAccountName, so.SpotDistance, so.IsPrivate, so.Password, so.CreateAt);
 }
        public async Task<List<SpotObject>> GetNearSpotListAsync(Geoposition currentGeoposition)
        {
            // Get current coordinate
            double currentLatitude = currentGeoposition.Coordinate.Latitude;
            double currentLongtitude = currentGeoposition.Coordinate.Longitude;

            // Get spots formed JArray
            // If loading spot doesn't occur error, Convert jarray spots to spot list
            List<SpotObject> list = new List<SpotObject>();
            JArray jSpots = await this.GetNearSpotsAsync(currentLatitude, currentLongtitude);
            foreach (JObject jSpot in jSpots)
            {
                // Set new spot view item
                string spotId = (string)jSpot["id"];
                string spotName = (string)jSpot["spot_name"];
                double spotLatitude = (double)jSpot["spot_latitude"];
                double spotLongtitude = (double)jSpot["spot_longtitude"];
                string accountId = (string)jSpot["ptcaccount_id"];
                string accountName = (string)jSpot["ptcaccount_name"];
                double spotDistance = (double)jSpot["spot_distance"];
                bool isPrivate = (bool)jSpot["is_private"];
                string spot_password = (string)jSpot["spot_password"];
                string create_at = (string)jSpot["create_at"];

                SpotObject spot = new SpotObject(spotName, spotLatitude, spotLongtitude, accountId, accountName, spotDistance, isPrivate, spot_password, create_at);
                spot.Id = spotId;
                list.Add(spot);
            }
            this.SpotList = list;
            return list;
        }
        public async Task<List<SpotObject>> GetMySpotList()
        {
            // Get signed in my spots formed JArray
            // If loading spot doesn't occur error, Convert jarray spots to spot list
            List<SpotObject> spots = new List<SpotObject>();
            JArray jSpots = await this.GetMySpotsAsync(App.AccountManager.GetPtcId());
            foreach (JObject jSpot in jSpots)
            {
                // Set new spot view item
                string spotId = (string)jSpot["id"];
                string spotName = (string)jSpot["spot_name"];
                double spotLatitude = (double)jSpot["spot_latitude"];
                double spotLongtitude = (double)jSpot["spot_longtitude"];
                string accountId = (string)jSpot["ptcaccount_id"];
                string accountName = (string)jSpot["ptcaccount_name"];
                double spotDistance = (double)jSpot["spot_distance"];
                bool isPrivate = (bool)jSpot["is_private"];
                string spot_password = (string)jSpot["spot_password"];
                string create_at = (string)jSpot["create_at"];

                SpotObject spot = new SpotObject(spotName, spotLatitude, spotLongtitude, accountId, accountName,
                    spotDistance, isPrivate, spot_password, create_at);
                spot.Id = spotId;
                spots.Add(spot);
            }
            this.MySpotList = spots;
            return spots;
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // Get Parameters
            this.LaunchLock = false;
            this.SpotId = NavigationContext.QueryString["spotId"];
            this.SpotName = NavigationContext.QueryString["spotName"];
            this.AccountId = NavigationContext.QueryString["accountId"];
            this.AccountName = NavigationContext.QueryString["accountName"];

            // Set this Spot
            uiSpotNameText.Text = this.SpotName;
            Switcher.SetStorageTo(Switcher.GetMainStorage().GetStorageName());
            this.CurrentSpot = App.SpotManager.GetSpotObject(this.SpotId);
            this.SetPickPivot(AppResources.Loading);
            this.SetPinPivot(AppResources.Loading);
        }