private static Int64 DeleteFormFilingQuestion(FormFilingQuestion filingQuestion, string url, string Username, string Drowssap)
        {
            //string payload = string.Empty;
            Int64 formFilingQuestionId = -1;

            try
            {
                // get post data.
                //payload = JsonConvert.SerializeObject(filingQuestion);
                //byte[] buf = Encoding.UTF8.GetBytes(payload);

                // create the http web request
                string query   = "/api/FormFilingQuestion/" + filingQuestion.FormFilingQuestionId.ToString();
                var    request = (HttpWebRequest)WebRequest.Create(url + query);
                request.Headers.Add(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(Username + ":" + Drowssap)));

                request.Method = "DELETE";
                //request.ContentLength = buf.Length;
                //request.ContentType = "application/json; charset=utf-8";
                //request.GetRequestStream().Write(buf, 0, buf.Length);

                // get response and deserialize it.
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    if (response != null)
                    {
                        var responseStream = response.GetResponseStream();
                        var streamReader   = new System.IO.StreamReader(responseStream, Encoding.UTF8);
                        var responseString = streamReader.ReadToEnd();

                        DeleteResponse responseDependency = responseString.Length > 0 ? JsonConvert.DeserializeObject <DeleteResponse>(responseString) : null;
                        if (responseDependency.deleted)
                        {
                            formFilingQuestionId = responseDependency.id;
                        }
                        else
                        {
                            Console.WriteLine("12: DeleteFormFilingQuestion: The following attempted delete failed: [{0}].  The unhandled exception that occurred: [{1}]", responseDependency.id.ToString(), responseDependency.deleted.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("11: DeleteFormFilingQuestion: The following attempted delete failed: [{0}].  The unhandled exception that occurred: [{1}]", filingQuestion.FormFilingQuestionId.ToString(), ex.Message);
            }

            return(formFilingQuestionId);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        /// <remarks>args[0] = File path and name</remarks>
        /// <remarks>args[1] = url for Tax Form Catalog</remarks>
        /// <remarks>args[2] = user id for Tax Form Catalog</remarks>
        /// <remarks>args[3] = password for Tax Form Catalog</remarks>
        static void Main(string[] args)
        {
            List <InputData> formList = new List <InputData>();

            //Populate object with source file
            using (FileStream fs = new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fs, false))
                {
                    WorkbookPart  workbookPart  = spreadsheetDocument.WorkbookPart;
                    WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
                    SheetData     sheetData     = worksheetPart.Worksheet.Elements <SheetData>().First();

                    foreach (Row row in sheetData.Elements <Row>())
                    {
                        InputData form      = new InputData();
                        int       rowcolumn = 1;

                        foreach (Cell c in row.Elements <Cell>())
                        {
                            switch (rowcolumn)
                            {
                            case 1: form.State = ReadExcelCell(c, workbookPart); break;

                            case 2: form.TaxFormCode = ReadExcelCell(c, workbookPart); break;

                            case 3: form.FormInfo = ReadExcelCell(c, workbookPart); break;

                            case 4: form.LucasNotes = ReadExcelCell(c, workbookPart); break;
                            }

                            rowcolumn++;
                        }

                        formList.Add(form);
                    }
                }
            }

            int   totalRecords    = formList.Count;
            Int64 formMasterId    = 0;
            int   recordsInserted = 0;
            int   recordsUpdated  = 0;
            int   recordsDeleted  = 0;
            int   recordsErrored  = 0;

            // Create List of FormCellDependency records to add
            foreach (InputData form in formList)
            {
                formMasterId = GetFormMasterId(form.TaxFormCode, args[1], args[2], args[3]);
                if (formMasterId <= 0)
                {
                    Console.WriteLine(string.Format("1: Unable to find a formmaster record for taxformcode [{0}].", form.TaxFormCode));
                }
                else
                {
                    try
                    {
                        List <FormFilingQuestion> existingFilingQuestions = GetFormFilingQuestions(formMasterId, args[1], args[2], args[3]);
                        FormFilingQuestion        formFilingQuestion      = existingFilingQuestions.Any() ? existingFilingQuestions.Where <FormFilingQuestion>(x => x.FilingQuestionId == 1272).FirstOrDefault() : null;
                        if (formFilingQuestion == null || formFilingQuestion == new FormFilingQuestion())
                        {
                            FormFilingQuestion filingQuestionToAdd = new FormFilingQuestion()
                            {
                                FormFilingQuestionId         = -1,
                                FormMasterId                 = formMasterId,
                                SortOrder                    = existingFilingQuestions.Count + 1,
                                FilingQuestionId             = 1272,
                                Required                     = false,
                                InternalOnly                 = false,
                                FormQuestionScopeId          = 0,
                                SkyscraperValidationRequired = false
                            };

                            Int64 insertedFilingQuestionId = -1;
                            insertedFilingQuestionId = InsertFormFilingQuestion(filingQuestionToAdd, args[1], args[2], args[3]);
                            if (insertedFilingQuestionId > 0)
                            {
                                recordsInserted++;
                            }
                            else
                            {
                                Console.WriteLine(string.Format("2: Insert to FormFilingQuestion did not return a valid FormFilingQuestionId for TaxFormCode [{0}].", form.TaxFormCode));
                                recordsErrored++;
                            }
                        }

                        /*                        else // set InternalOnly to True to remove from CUP
                         *                      {
                         *                          formFilingQuestion.InternalOnly = true;
                         *                          Int64 updateFilingQuestionId = -1;
                         *                          updateFilingQuestionId = UpdateFormFilingQuestion(formFilingQuestion, args[1], args[2], args[3]);
                         *                          if (updateFilingQuestionId > 0)
                         *                          {
                         *                              recordsUpdated++;
                         *                          }
                         *                          else
                         *                          {
                         *                              Console.WriteLine(string.Format("3: Update of existing FormFilingQuestion did not return a valid FormFilingQuestionId for TaxFormCode [{0}].", form.TaxFormCode));
                         *                              recordsErrored++;
                         *                          }
                         *                      }
                         */
                        else // remove the filing question from the form
                        {
                            Int64 deleteFilingQuestionId = -1;
                            deleteFilingQuestionId = DeleteFormFilingQuestion(formFilingQuestion, args[1], args[2], args[3]);
                            if (deleteFilingQuestionId >= 0)
                            {
                                recordsDeleted++;
                            }
                            else
                            {
                                Console.WriteLine(string.Format("3: Update of existing FormFilingQuestion did not return a valid FormFilingQuestionId for TaxFormCode [{0}].", form.TaxFormCode));
                                recordsErrored++;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(string.Format("4: LoadFormFilingQuestion: An error occurred [{0}] while processing TaxFormCode [{1}] and filing Question [{2}].", ex.Message, form.TaxFormCode, "1372"));
                        recordsErrored++;
                    }
                }
            }

            Console.WriteLine(string.Format("5: LoadFormFilingQuestion: {0} records inserted, {1} records updated, {2} records deleted and {3} records errored out of {4} total records.", recordsInserted.ToString(), recordsUpdated.ToString(), recordsDeleted.ToString(), recordsErrored.ToString(), totalRecords.ToString()));
            Console.ReadKey();
        }