Ejemplo n.º 1
0
        public Location UpdateLocation(Location MyLocation)
        {
            Console.WriteLine("Updating location " + MyLocation.Name + "...");

            RestRequest request = new RestRequest("/{version}/admin/locations/{location_id}", Method.PATCH);

            request.AddParameter("version", _ver, ParameterType.UrlSegment);
            request.AddParameter("location_id", MyLocation.Id, ParameterType.UrlSegment);
            request.AddParameter("application/json", API.LocationJson(MyLocation), ParameterType.RequestBody);
            request.AddParameter("Authorization", _token.token_type + " " + _token.access_token, ParameterType.HttpHeader);

            IRestResponse  response    = _client.Execute(request);
            HttpStatusCode statusCode  = response.StatusCode;
            int            numericCode = (int)statusCode;

            if (numericCode != 200)
            {
                throw new FoundryException(response.ErrorMessage, numericCode, response.Content);
            }

            LocationDataJson locationData = JsonConvert.DeserializeObject <LocationDataJson>(response.Content);
            Location         location     = locationData.LocationData.LocationAttributes;

            location.AddIdFromData(locationData.LocationData);

            FoundryLocations.Remove(MyLocation);
            FoundryLocations.Add(location);

            return(location);
        }
Ejemplo n.º 2
0
        public Location AddLocation(Location MyLocation)
        {
            Console.WriteLine("Adding location " + MyLocation.Name + "...");

            RestRequest request = new RestRequest("/{version}/admin/locations", Method.POST);

            request.AddParameter("version", _ver, ParameterType.UrlSegment);
            request.AddParameter("application/json", API.LocationJson(MyLocation), ParameterType.RequestBody);
            request.AddParameter("Authorization", _token.token_type + " " + _token.access_token, ParameterType.HttpHeader);

            IRestResponse  response    = _client.Execute(request);
            HttpStatusCode statusCode  = response.StatusCode;
            int            numericCode = (int)statusCode;

            if (numericCode != 201)
            {
                throw new FoundryException(response.ErrorMessage, numericCode, response.Content);
            }

            //verify if adding was okay with status code

            LocationDataJson locationData = JsonConvert.DeserializeObject <LocationDataJson>(response.Content);

            Console.WriteLine("Location successfully added.");

            Location location = locationData.LocationData.LocationAttributes;

            location.Id = locationData.LocationData.Id;

            FoundryLocations.Add(location);
            return(location);
        }