示例#1
0
        private async void ExecuteSave(object obj)
        {
            var   store = AppStore.Instance;
            Place tmp   = null;

            switch (Type)
            {
            case PlaceType.CampingPlace:
                tmp = new CampingPlace();
                break;

            case PlaceType.Hotel:
                tmp = new Hotel();
                break;

            case PlaceType.MotorhomePlace:
                tmp = new MotorhomePlace();
                break;

            case PlaceType.Restaurant:
                tmp = new Restaurant();
                break;

            case PlaceType.Poi:
                tmp = new Poi();
                break;
            }

            tmp.Latitude    = Latitude;
            tmp.Longitude   = Longitude;
            tmp.Rating      = Rating;
            tmp.Altitude    = Altitude;
            tmp.Created     = DateTimeOffset.Now;
            tmp.Description = Description;
            tmp.Name        = Name;
            tmp.PlaceId     = Guid.NewGuid();
            tmp.Trip        = store.CurrentTrip;
            tmp.TripId      = store.CurrentTrip.TripId;

            var trips   = store.User.Trips;
            var tripIdx = trips.IndexOf(store.CurrentTrip);

            // Add new Place to local Collection
            store.User.Trips[tripIdx].Places.Add(tmp);

            // Save to CloudStore
            var tmpPlace = await PlaceStore.AddItemAsync(tmp);

            if (tmpPlace != null)
            {
                SavePlaceSuccessCallback?.Invoke(true);
            }
            else
            {
                SavePlaceSuccessCallback?.Invoke(false);
            }
        }
示例#2
0
        public async Task <bool> DeletePlace(int idx)
        {
            var result = await PlaceStore.DeleteItemAsync(Places[idx].Id);

            if (!result)
            {
                return(false);
            }
            Places.RemoveAt(idx);
            AppStore.Instance.CurrentTrip.Places.RemoveAt(idx);
            return(true);
        }
示例#3
0
        private async void ExecuteSavePlace(object obj)
        {
            _place.LastEdit    = DateTimeOffset.Now;
            _place.Name        = Name;
            _place.Description = Description;
            _place.Rating      = short.Parse(Rating);
            _place.Type        = SelectedPlaceType;
            var result = await PlaceStore.UpdateItemAsync(_place);

            if (result == null)
            {
                ErrorAction?.Invoke($"Update Place '{_place.Name}' failed:");
                App.LogOutLn($"Update Place '{_place.Name}' failed.");
                UpdateReady?.Invoke(false);
            }
            else
            {
                UpdateReady?.Invoke(true);
            }
        }
示例#4
0
        public async Task PullTrips()
        {
            if (App.AllDataFetched)
            {
                // Get Trips from Users collection
                Trips.Clear();
                foreach (var trip in AppStore.Instance.User.Trips)
                {
                    Trips.Add(trip);
                }
                return;
            }
            ;
            var store  = AppStore.Instance;
            var userId = store.User.Id;

            var trips = await TripStore.GetItemsByFkAsync(userId);

            if (trips == null)
            {
                return;
            }
            store.User.Trips = new System.Collections.Generic.List <Trip>();
            store.Trips.Clear();
            foreach (var trip in trips)
            {
                var places = await PlaceStore.GetItemsByFkAsync(trip.Id);

                trip.Places = places.ToList();
                store.User.Trips.Add(trip);
                Trips.Add(trip);
            }

            // All data for this User are fetched yet
            App.AllDataFetched = true;
            return;
        }