private String ValidateInputs(Models.ClosetModel cm)
        {
            // Validation
            _width = cm.Width;
            if (String.IsNullOrEmpty(_width))
            {// Width is not provided
                return("Please provide a value for the closet width in feet");
            }

            _depth = cm.Depth;
            if (String.IsNullOrEmpty(_depth))
            {// Depth is not provided
                return("Please provide a value for the closet depth in feet");
            }

            _height = cm.Height;
            if (String.IsNullOrEmpty(_height))
            {// Height is not provided
                return("Please provide a value for the closet height in feet");
            }

            _plyThickness = cm.PlyThickness;
            if (String.IsNullOrEmpty(_plyThickness))
            {// Ply Thickness is not provided
                return("Please provide a value for the Ply thickness in inches");
            }

            _doorHeightPercentage = cm.DoorHeightPercentage;
            if (String.IsNullOrEmpty(_doorHeightPercentage))
            {// Door Height is not provided
                return("Please provide a value for the door height as a percentage of total closet height");
            }

            _numberOfDrawers = cm.NumberOfDrawers;
            if (String.IsNullOrEmpty(_numberOfDrawers))
            {// Number of drawers is not provided
                return("Please provide the number of drawers");
            }
            _iNumOfDrawers = 1;
            if (!int.TryParse(_numberOfDrawers, out _iNumOfDrawers))
            {// Invalid entry for number of apps
                return("Please provide the number of drawers");
            }

            _isSplitDrawers = cm.IsSplitDrawers;

            return(String.Empty);
        }
        public ActionResult Index(Models.ClosetModel cm, String Command)
        {
            ViewBag.Message = " ";

            if (String.IsNullOrEmpty(Command))
            {
                cm.ViewerURN   = String.Empty;
                cm.AccessToken = _accessToken;

                return(View(cm));
            }

            // Validation
            String message = ValidateInputs(cm);

            if (!String.IsNullOrEmpty(message))
            {
                ViewData["Message"] = message;
                return(View(cm));
            }

            _emailAddress = cm.EmailAddress;
            if (Command.Contains("Email"))
            {
                if (String.IsNullOrEmpty(_emailAddress) || !IsValidEmail(_emailAddress))
                {// Invalid email address
                    ViewData["Message"] = "Please provide a valid email address";
                    return(View(cm));
                }
            }

            try
            {
                // Create a drawing with closet created based on the user inputs
                String baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

                // Create the closet drawing
                String templateDwgPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BlankIso.dwg");

                String script = String.Format("CreateCloset{0}{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}{0}_.VSCURRENT{0}sketchy{0}_.Zoom{0}Extents{0}_.SaveAs{0}{0}Result.dwg{0}", Environment.NewLine, _width, _depth, _height, _plyThickness, _doorHeightPercentage, _numberOfDrawers, (_isSplitDrawers == "Yes") ? 1 : 0);

                //make sure the activity has been created by other program!!

                if (Autodesk.AcadIOUtils.UpdateActivity(ForgeSrv.designAuto_Act_Id, script))
                {
                    String resultDrawingPath = String.Empty;

                    // Get the AutoCAD IO result by running "CreateCloset" activity
                    resultDrawingPath = GetAutoCADIOResult(templateDwgPath, ForgeSrv.designAuto_Act_Id);

                    if (!String.IsNullOrEmpty(resultDrawingPath))
                    {
                        // Get a PNG image from the drawing for email attachment

                        //optional: if you want to make snapshot of the new drawing.
                        //_imagePath = GetAutoCADIOResult(resultDrawingPath, "PlotToPNG");
                        //System.IO.File.Copy(_imagePath, System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images\\Preview.png"), true);

                        _imagePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images\\Preview.png");

                        DateTime dt = DateTime.Now;
                        _closetDrawingPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, String.Format("Closet{0}{1}{2}{3}{4}{5}{6}.dwg", dt.Year.ToString(), dt.Month.ToString(), dt.Day.ToString(), dt.Hour.ToString(), dt.Minute.ToString(), dt.Second.ToString(), dt.Millisecond.ToString()));
                        System.IO.File.Copy(resultDrawingPath, System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _closetDrawingPath), true);

                        // Send an email with drawing and image as attachments
                        if (Command.Contains("Email"))
                        {
                            if (SendEmail())
                            {
                                ViewData["Message"] = "Email sent !!";
                            }
                            else
                            {
                                ViewData["Message"] = "Sorry, Email was not sent !!";
                            }
                        }

                        // Preview the drawing in Viewer
                        if (Command.Contains("Preview"))
                        {
                            // Get the urn to show in viewer
                            if (_bucketFound)
                            {
                                UploadDrawingFile(_closetDrawingPath);

                                // Required for the view to reflect changes in the model
                                ModelState.Clear();
                                cm.ViewerURN   = _fileUrn;
                                cm.AccessToken = _accessToken;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                // An error !
                ViewData["Message"] = ex.Message;
            }
            //*/

            return(View(cm));
        }