Ejemplo n.º 1
0
 private void UpdatePlace(Place place, PlaceData placeData)
 {
     place.Name      = placeData.Name;
     place.Radius    = placeData.Radius;
     place.Latitude  = placeData.Latitude;
     place.Longitude = placeData.Longitude;
     place.Image     = placeData.Image;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Update list of places
        /// </summary>
        /// <returns></returns>
        public async Task <PlacesResponse> GetPlaces()
        {
            var resp = await Request.GetPlaces();

            if (!resp.IsSuccessful)
            {
                FSLog.Error("Request failed", resp.HttpStatus);
                return(resp);
            }

            var places       = SettingsManager.Places;
            var removedPlace = new List <Place>();

            foreach (var place in places)
            {
                if (resp.Places.ContainsKey(place.Id))
                {
                    PlaceData data = resp.Places[place.Id];
                    UpdatePlace(place, data);

                    // Remove so not added as new
                    resp.Places.Remove(place.Id);
                }
                else
                {
                    removedPlace.Add(place);
                }
            }

            // Add new
            foreach (string id in resp.Places.Keys)
            {
                PlaceData data = resp.Places[id];

                var place = new Place();
                place.Id = id;
                UpdatePlace(place, data);

                places.Add(place);
            }

            foreach (Place place in removedPlace)
            {
                places.Remove(place);
            }

            // TODO: Check for accidental duplicates. Would use dictionary but there's no builtin ObservableDictionary

            SettingsManager.Save();

            return(resp);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create new place for user
        /// </summary>
        /// <returns></returns>
        public Task <UpdatePlaceResponse> UpdatePlace(string id, string name, double lat, double lon, double radius)
        {
            var uri  = GetUserUri("place/" + id);
            var exec = new RequestExecutor <UpdatePlaceResponse>(this);

            var data = new PlaceData();

            data.Name      = name;
            data.Latitude  = lat;
            data.Longitude = lon;
            data.Radius    = radius;
            data.Image     = "";
            return(exec.Execute(uri, data, method: "PUT"));
        }