/// <summary>
        /// This operation adds, updates and deletes features to the associated feature layer or table in a single call (POST only). 
        /// The apply edits operation is performed on a feature service layer resource. The results of this operation are 3 arrays of edit results (for adds, updates, and deletes respectively). 
        /// Each edit result identifies a single feature and indicates if the edits were successful or not. If not, it also includes an error code and an error description.  
        /// </summary>
        /// <param name="type"></param>
        private void EditFeatureService(EditType type, string geometryDef, string attributess)
        {
            string formattedRequest = string.Empty;
              string jsonResponse = string.Empty;
              string jsonToSend = string.Empty;
              string attributes = string.Empty;

              string url = CompleteServiceUrl();

              switch (type)
              {
            case EditType.add:
              {
            //NB: implementation from another project. Commented out so that the developer can see how to create this kind of
            //    REST call, but not of functional importance to what is being displayed herein.

            //if (_dataTable.Rows.Count == 0)
            //  return;

            //object[] row = _dataTable.Rows[_dataTable.Rows.Count - 1].ItemArray;
            //attributes = "\"attributes\":{\"";
            //int counter = 0;
            //foreach (DataColumn column in _dataTable.Columns)
            //{
            //  attributes += string.Format("{0}\":\"{1}\",\"", column.ColumnName, row[counter].ToString());
            //  counter++;
            //}

            //attributes = attributes.Remove(attributes.Length - 2, 2);

            ////NB: Sample does not provide an entry method for the user to enter an XY for the Geom value.
            ////this is for demo purposes with a point feature service with the spatial ref as below.
            ////Users of this code need to build this functionality into their app, either with text input or map click.
            ////Supplied XY places a point on the Coronado Bridge, San Diego, California
            ////jsonToSend = string.Format("adds=[{\"geometry\":{\"x\":-13041634.9497585,\"y\":3853952.46755234,\"spatialReference\":{\"wkid\":102100, \"latestWkid\" = 3857}},{0}}}]", attributes);
            //jsonToSend = "adds=[{\"geometry\":{\"x\":-13041634.9497585,\"y\":3853952.46755234,\"spatialReference\":{\"wkid\":102100, \"latestWkid\" = 3857}}," + attributes + "}}]";
            break;
              }
            case EditType.delete:
              {
            try
            {
              //NB: implementation from another project. Commented out so that the developer can see how to create this kind of
              //    REST call, but not of functional importance to what is being displayed herein.

              //jsonToSend = string.Format("deletes={0}", GetSelectedRowFID());
              //_featureEditResponse = RequestAndResponseHandler.FeatureEditRequest(url, jsonToSend, out jsonResponse);
            }
            catch { }
            break;
              }
            case EditType.update:
              {
            jsonToSend = "updates=[{\"" + geometryDef + ",\"spatialReference\":{\"wkid\":102100, \"latestWkid\":3857}},\"" + attributess + "}]";
            break;
              }
            default:
              break;
              }
              _featureEditResponse = RequestAndResponseHandler.FeatureEditRequest(url, jsonToSend, out jsonResponse);
        }
Example #2
0
        /// <summary>
        /// This operation adds, updates and deletes features to the associated feature layer or table(POST only).
        /// </summary>
        /// <param name="type"></param>
        private void EditFeatureService(EditType type, GeometryType geomType, MyPoint myPoint, MyPoly myPoly)
        {
            string formattedRequest = string.Empty;
              string jsonResponse = string.Empty;
              string jsonToSend = string.Empty;
              string attributes = string.Empty;
              string geometry = string.Empty;

              string url = CompleteServiceUrl();

              switch (type)
              {
            case EditType.add:
              {
            attributes = "\"attributes\":{\"";
            int counter = 0;

            if (_records != null)
            {
              foreach (IDataRecord record in _records)
              {
                foreach (string field in _fieldNames)
                {
                  attributes += string.Format("{0}\":\"{1}\",\"", field, record[counter].ToString());
                  counter++;
                }

                break;
              }
            }

            if (counter == 0) //no records added. Create a dummy record.
            {
              foreach (DataGridViewRow row in dataGridViewFields.Rows)
              {
                //todo: did I set a default color symbol?
                attributes += string.Format("{0}\":\"{1}\",\"", row.Cells[0].FormattedValue.ToString(), null);
              }
            }

            //remove the excess. Meaning remove the trailing rubbish
            attributes = attributes.Remove(attributes.Length - 8);

            if (geomType == GeometryType.polygon)
            {
              //Polygon geometry
              MyPoint p;
              jsonToSend = "adds=[{\"geometry\":{\"rings\":[[";
              for (int i = 0; i < myPoly.Ring.Count; i++)
              {
                p = myPoly.Ring[i];
                jsonToSend += "[" + p.X + "," + p.Y + "],";
              }
              jsonToSend = jsonToSend.Remove(jsonToSend.Length - 1, 1);
              jsonToSend += "]],\"spatialReference\":{\"wkid\":102100}}," + attributes + "}}]";

              //example
              // [{"geometry":{"rings":[[[-8304737.273855386,5018862.730810074],[-8286086.638953812,5017945.486470653],[-8280583.172917282,5006632.806284452],
              //[-8303820.029515964,4995931.622324532],[-8322164.916304397,5006938.554397592],[-8304737.273855386,5018862.730810074]]],
              //"spatialReference":{"wkid":102100}},"attributes":{"BUFF_DIST":"3","BufferArea":null,"BufferPerimeter":null}}]

            }
            else
            {
              //NB: Sample does not provide an entry method for the user to enter an XY for point geom types.
              //this is for demo purposes with a point feature service with the spatial ref as set below.
              //Users of this code need to build this functionality into their app, either with text input or map click.
              //Supplied XY places a point on the Coronado Bridge, San Diego, California

              jsonToSend = "adds=[{\"geometry\":{\"x\":" + myPoint.X + ",\"y\":" + myPoint.Y + ",\"spatialReference\":{\"wkid\":102100}}," + attributes + "}}]";
             }

            break;
              }
            case EditType.delete:
              {
            break;
              }
            case EditType.update:
              {
            break;
              }
            default:
              break;
              }

              //Make the HttpWebRequest
              _featureEditResponse = RequestAndResponseHandler.FeatureEditRequest(url, jsonToSend, out jsonResponse);

              switch (type)
              {
            case EditType.add:
              {
            if (_featureEditResponse.addResults == null)
              break;

            lblEditingResponse.Text = string.Format("Success: {0}, ObjectID: {1}, GlobalID: {2}, Error: {3}", _featureEditResponse.addResults[0].success,
              _featureEditResponse.addResults[0].objectId, _featureEditResponse.addResults[0].globalId, _featureEditResponse.addResults[0].error);

            break;
              }
            case EditType.delete:
              {
            break;
              }
            case EditType.update:
              {
            break;
              }
            default:
              break;
              }
        }