ArcGIS Simple Edit service
ArcGIS_SimpleEdit_CSharp\ArcGIS_SimpleEdit_WebAppCSharp\App_Code\AddPointTool.cs
// Copyright 2010 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 

public class AddPointTool : ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction
{
    #region IMapServerToolAction Members

    void ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction(
        ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs toolEventArgs)
    {
        ESRI.ArcGIS.ADF.Web.UI.WebControls.Map adfMap =
                    (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)toolEventArgs.Control;

        try
        {
            // Retrieve the collection that will contain the tool parameters that were specified by the
            // user on the page's interface.
            System.Collections.Specialized.NameValueCollection toolArgsNameValueCollection = null;
            if (adfMap.Page.IsCallback)
            {
                // Since the page is using the callback framework, the tool parameters have been packaged 
                // along with the callback parameters.  This is done via custom javascript (see Default.aspx).
                string callbackArgs = adfMap.Page.Request.Params["__CALLBACKPARAM"];
                toolArgsNameValueCollection = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackUtility.
                    ParseStringIntoNameValueCollection(callbackArgs);
            }
            else
            {
                // Since the page is not using the callback framework, that means the tool has executed via
                // partial or full-page postback.  In the case of postbacks, the values of ASP.NET server 
                // controls (which contain user-specified tool parameters in this case) are automatically
                // passed in the page's request parameters.
                toolArgsNameValueCollection = adfMap.Page.Request.Params;
            }

            // Get the tool input from the arguments collection
            string serviceNameString = toolArgsNameValueCollection["serviceNameTextBox"];
            string serviceDetailsString = toolArgsNameValueCollection["serviceDetailsTextBox"];
            string serviceTypeString = toolArgsNameValueCollection["serviceTypeDropDownList"];

            // Get the point on the map clicked by the user
            ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs mapPointEventArgs = toolEventArgs as
                ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs;
            ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint = mapPointEventArgs.MapPoint;

            // Get a reference to the AddActionLocation web service
            AddActionLocationService.AddActionLocationService addActionLocationService =
                new AddActionLocationService.AddActionLocationService();

            // Create a new action location and initialize it with the coordiantes of the point clicked
            AddActionLocationService.ActionLocation actionLocation =
                new AddActionLocationService.ActionLocation();
            actionLocation.X = adfPoint.X;
            actionLocation.Y = adfPoint.Y;

            // Create a new action record and initialize it with the textbox and drop-down list values 
            // specified by the user
            AddActionLocationService.ActionRecord actionRecord = new AddActionLocationService.ActionRecord();
            actionRecord.Name = serviceNameString;
            actionRecord.Details = serviceDetailsString;
            // Convert the string representation of the selected service type to its counterpart in the
            // AddActionLocationService.ServiceType enumeration
            AddActionLocationService.ServiceType serviceType = (AddActionLocationService.ServiceType)
                System.Enum.Parse(typeof(AddActionLocationService.ServiceType), serviceTypeString, true);
            actionRecord.ServiceType = serviceType;

            // Set the action record's location to the clicked point
            actionRecord.Location = actionLocation;

            // Add the new action record to the map service, which in turn creates a new feature with the
            // specified attributes and adds it to the underlying feature class
            addActionLocationService.AddActionLocation(actionRecord);

            // Refresh the map so the new feature is displayed
            adfMap.Refresh();
        }
        catch (System.Exception exception)
        {
            ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult errorAlertCallbackResult =
                Utility.CreateErrorCallbackResult(exception);
            adfMap.CallbackResults.Add(errorAlertCallbackResult);
        }
    }

    #endregion
}