private void OnSaveAsCommand(object obj)
        {
            var saveAsDialog = new AMSaveAsFormatView();
            var vm           = new SaveAsFormatViewModel();

            saveAsDialog.DataContext = vm;

            if (saveAsDialog.ShowDialog() == true)
            {
                IFeatureClass fc      = null;
                string        path    = null;
                var           fcUtils = new FeatureClassUtils();
                if (vm.FeatureShapeIsChecked)
                {
                    path = fcUtils.PromptUserWithGxDialog(ArcMap.Application.hWnd);
                    if (path != null)
                    {
                        if (System.IO.Path.GetExtension(path).Equals(".shp"))
                        {
                            fc = fcUtils.CreateFCOutput(path, SaveAsType.Shapefile, GraphicsList, ArcMap.Document.FocusMap.SpatialReference);
                        }
                        else
                        {
                            fc = fcUtils.CreateFCOutput(path, SaveAsType.FileGDB, GraphicsList, ArcMap.Document.FocusMap.SpatialReference);
                        }
                    }
                }
                else
                {
                    path = PromptSaveFileDialog();
                    if (path != null)
                    {
                        string        kmlName       = System.IO.Path.GetFileName(path);
                        string        folderName    = System.IO.Path.GetDirectoryName(path);
                        string        tempShapeFile = folderName + "\\tmpShapefile.shp";
                        IFeatureClass tempFc        = fcUtils.CreateFCOutput(tempShapeFile, SaveAsType.Shapefile, GraphicsList, ArcMap.Document.FocusMap.SpatialReference);

                        if (tempFc != null)
                        {
                            var kmlUtils = new KMLUtils();
                            kmlUtils.ConvertLayerToKML(path, tempShapeFile, ArcMap.Document.FocusMap);

                            // delete the temporary shapefile
                            fcUtils.DeleteShapeFile(tempShapeFile);
                        }
                    }
                }

                if (fc != null)
                {
                    AddFeatureLayerToMap(fc);
                }
            }
        }
        private void OnSaveAsCommand(object obj)
        {
            var saveAsDialog = new AMSaveAsFormatView();
            var vm           = new SaveAsFormatViewModel();

            saveAsDialog.DataContext = vm;

            if (saveAsDialog.ShowDialog() == true)
            {
                IFeatureClass fc      = null;
                string        path    = null;
                var           fcUtils = new FeatureClassUtils();
                if (vm.FeatureShapeIsChecked)
                {
                    path = fcUtils.PromptUserWithGxDialog(ArcMap.Application.hWnd);
                    if (path != null)
                    {
                        SaveAsType saveType = System.IO.Path.GetExtension(path).Equals(".shp") ? SaveAsType.Shapefile : SaveAsType.FileGDB;
                        fc = fcUtils.CreateFCOutput(path, saveType, GraphicsList, ArcMap.Document.FocusMap.SpatialReference);
                    }
                }
                else if (vm.KmlIsChecked)
                {
                    path = PromptSaveFileDialog("kmz", "KMZ File (*.kmz)|*.kmz", CoordinateConversionLibrary.Properties.Resources.KMLLocationMessage);
                    if (path != null)
                    {
                        string        kmlName       = System.IO.Path.GetFileName(path);
                        string        folderName    = System.IO.Path.GetDirectoryName(path);
                        string        tempShapeFile = folderName + "\\tmpShapefile.shp";
                        IFeatureClass tempFc        = fcUtils.CreateFCOutput(tempShapeFile, SaveAsType.Shapefile, GraphicsList, ArcMap.Document.FocusMap.SpatialReference);

                        if (tempFc != null)
                        {
                            var kmlUtils = new KMLUtils();
                            kmlUtils.ConvertLayerToKML(path, tempShapeFile, ArcMap.Document.FocusMap);

                            // delete the temporary shapefile
                            fcUtils.DeleteShapeFile(tempShapeFile);
                        }
                    }
                }
                else
                {
                    //Export to CSV
                    path = PromptSaveFileDialog("csv", "CSV File (*.csv)|*.csv", CoordinateConversionLibrary.Properties.Resources.CSVLocationMessage);
                    if (path != null)
                    {
                        string csvName    = System.IO.Path.GetFileName(path);
                        string folderName = System.IO.Path.GetDirectoryName(path);
                        string tempFile   = System.IO.Path.Combine(folderName, csvName);

                        var aiPoints = CoordinateAddInPoints.ToList();

                        if (aiPoints == null || !aiPoints.Any())
                        {
                            return;
                        }

                        var csvExport = new CsvExport();
                        foreach (var point in aiPoints)
                        {
                            csvExport.AddRow();
                            csvExport["Coordinates"] = point.Text;
                        }
                        csvExport.ExportToFile(tempFile);

                        System.Windows.Forms.MessageBox.Show(CoordinateConversionLibrary.Properties.Resources.CSVExportSuccessfulMessage + tempFile,
                                                             CoordinateConversionLibrary.Properties.Resources.CSVExportSuccessfulCaption);
                    }
                }

                if (fc != null)
                {
                    AddFeatureLayerToMap(fc);
                }
            }
        }
        /// <summary>
        /// Saves graphics to file gdb or shp file
        /// </summary>
        /// <param name="obj"></param>
        private void OnSaveAs(object obj)
        {
            var dlg = new GRSaveAsFormatView();

            dlg.DataContext = new SaveAsFormatViewModel();
            var vm = dlg.DataContext as SaveAsFormatViewModel;

            if (dlg.ShowDialog() == true)
            {
                IFeatureClass fc = null;

                // Get the graphics list for the selected tab
                List <Graphic> typeGraphicsList = new List <Graphic>();
                if (this is LinesViewModel)
                {
                    typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Line).ToList();
                }
                else if (this is CircleViewModel)
                {
                    typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Circle).ToList();
                }
                else if (this is EllipseViewModel)
                {
                    typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Ellipse).ToList();
                }
                else if (this is RangeViewModel)
                {
                    typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.RangeRing).ToList();
                }

                string path = null;
                if (vm.FeatureShapeIsChecked)
                {
                    path = fcUtils.PromptUserWithGxDialog(ArcMap.Application.hWnd);
                    if (path != null)
                    {
                        if (System.IO.Path.GetExtension(path).Equals(".shp"))
                        {
                            fc = fcUtils.CreateFCOutput(path, SaveAsType.Shapefile, typeGraphicsList, ArcMap.Document.FocusMap.SpatialReference);
                        }
                        else
                        {
                            fc = fcUtils.CreateFCOutput(path, SaveAsType.FileGDB, typeGraphicsList, ArcMap.Document.FocusMap.SpatialReference);
                        }
                    }
                }
                else
                {
                    path = PromptSaveFileDialog();
                    if (path != null)
                    {
                        string        kmlName       = System.IO.Path.GetFileName(path);
                        string        folderName    = System.IO.Path.GetDirectoryName(path);
                        string        tempShapeFile = folderName + "\\tmpShapefile.shp";
                        IFeatureClass tempFc        = fcUtils.CreateFCOutput(tempShapeFile, SaveAsType.Shapefile, typeGraphicsList, ArcMap.Document.FocusMap.SpatialReference);

                        if (tempFc != null)
                        {
                            kmlUtils.ConvertLayerToKML(path, tempShapeFile, ArcMap.Document.FocusMap);

                            // delete the temporary shapefile
                            fcUtils.DeleteShapeFile(tempShapeFile);
                        }
                    }
                }

                if (fc != null)
                {
                    IFeatureLayer outputFeatureLayer = new FeatureLayerClass();
                    outputFeatureLayer.FeatureClass = fc;

                    IGeoFeatureLayer geoLayer = outputFeatureLayer as IGeoFeatureLayer;
                    geoLayer.Name = fc.AliasName;

                    ESRI.ArcGIS.Carto.IMap map = ArcMap.Document.FocusMap;
                    map.AddLayer((ILayer)outputFeatureLayer);
                }
            }
        }