/// <summary>
        /// Handle deleted records for the requested time period
        /// </summary>
        /// <param name="community"></param>
        /// <param name="startingDate">Date must be in UTC</param>
        /// <param name="endingDate">Date must be in UTC</param>
        /// <param name="maxRecords"></param>
        /// <param name="recordsDeleted"></param>
        /// <returns></returns>
        public static string HandleDeletes(string community, string startingDate, string endingDate, int maxRecords, ref int recordsDeleted)
        {
            int pageNbr  = 1;
            int pageSize = 100;
            //string importError = "";
            //may want to just do all types!
            string              type     = "";
            List <string>       messages = new List <string>();
            List <ReadEnvelope> list     = new List <ReadEnvelope>();
            SaveStatus          status   = new SaveStatus();
            int    pTotalRows            = 0;
            int    cntr                  = 0;
            bool   isComplete            = false;
            int    exceptionCtr          = 0;
            string statusMessage         = "";
            string importResults         = "";
            string importNote            = "";
            bool   usingNewDeleteProcess = UtilityManager.GetAppKeyValue("usingNewDeleteProcess", false);

            LoggingHelper.DoTrace(1, string.Format("===  DELETE Check for: '{0}' to '{1}' ===", startingDate, endingDate));
            //startingDate = "2017-10-29T00:00:00";
            try
            {
                while (pageNbr > 0 && !isComplete)
                {
                    list = RegistryImport.GetDeleted(community, type, startingDate, endingDate, pageNbr, pageSize, ref pTotalRows, ref statusMessage);

                    if (list == null || list.Count == 0)
                    {
                        isComplete = true;
                        if (pageNbr == 1)
                        {
                            importNote = "Deletes: No records where found for date range ";
                            //Console.WriteLine( thisClassName + ".HandleDeletes() - " + importNote );
                            LoggingHelper.DoTrace(1, thisClassName + string.Format(".HandleDeletes() Community: {0} - ", community) + importNote);
                        }
                        break;
                    }
                    foreach (ReadEnvelope item in list)
                    {
                        cntr++;
                        string payload = item.DecodedResource.ToString();

                        string ctdlType = RegistryServices.GetResourceType(payload);
                        string ctid     = RegistryServices.GetCtidFromUnknownEnvelope(item);
                        //may not be available in database, may want to use ctid
                        string envelopeIdentifier = item.EnvelopeIdentifier;
                        string envelopeUrl        = RegistryServices.GetEnvelopeUrl(item.EnvelopeIdentifier);
                        //LoggingHelper.DoTrace( 5, "		envelopeUrl: " + envelopeUrl );

                        //LoggingHelper.DoTrace( 6, string.Format( "{0}. EnvelopeIdentifier: {1} ", cntr, item.EnvelopeIdentifier ) );
                        try
                        {
                            //only need the envelopeId and type
                            //so want a full delete, or set EntityStateId to 0 - just as a precaution
                            messages = new List <string>();
                            status   = new SaveStatus();
                            status.ValidationGroup = "Deletes";

                            //
                            if (usingNewDeleteProcess)
                            {
                                Program.HandleDeleteRequest(cntr, item.EnvelopeIdentifier, ctid, ctdlType, ref statusMessage);
                                continue;
                            }
                            //21-02-22 the old and new delete process seem to be the same, at lease the same xxxManager().Delete methods are being called.

                            //
                            //importError = "";
                            //each delete method will add an entry to SearchPendingReindex.
                            //at the end of the process, call method to handle all the deletes
                            switch (ctdlType.ToLower())
                            {
                            case "credentialorganization":
                            case "qacredentialorganization":
                            case "organization":
                                DisplayMessages(string.Format("{0}. Deleting {1} by ctid: {2} ", cntr, ctdlType, ctid));
                                if (!new OrganizationManager().Delete(ctid, ref statusMessage))
                                {
                                    DisplayMessages(string.Format("  Delete failed: {0} ", statusMessage));
                                }
                                break;

                            case "assessmentprofile":
                                DisplayMessages(string.Format("{0}. Deleting {1} by ctid: {2} ", cntr, ctdlType, ctid));
                                if (!new AssessmentManager().Delete(ctid, ref statusMessage))
                                {
                                    DisplayMessages(string.Format("  Delete failed: {0} ", statusMessage));
                                }
                                break;

                            case "learningopportunityprofile":
                                DisplayMessages(string.Format("{0}. Deleting {1} by ctid: {2} ", cntr, ctdlType, ctid));
                                if (!new LearningOpportunityManager().Delete(ctid, ref statusMessage))
                                {
                                    DisplayMessages(string.Format("  Delete failed: {0} ", statusMessage));
                                }
                                break;

                            case "conditionmanifest":
                                DisplayMessages(string.Format("{0}. Deleting ConditionManifest by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid));
                                if (!new ConditionManifestManager().Delete(envelopeIdentifier, ctid, ref statusMessage))
                                {
                                    DisplayMessages(string.Format("  Delete failed: {0} ", statusMessage));
                                }
                                break;

                            case "costmanifest":
                                DisplayMessages(string.Format("{0}. Deleting CostManifest by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid));
                                if (!new CostManifestManager().Delete(envelopeIdentifier, ctid, ref statusMessage))
                                {
                                    DisplayMessages(string.Format("  Delete failed: {0} ", statusMessage));
                                }
                                break;

                            case "competencyframework":                                     //CompetencyFramework
                                DisplayMessages(string.Format("{0}. Deleting CompetencyFramework by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid));
                                if (!new CompetencyFrameworkManager().Delete(ctid, ref statusMessage))
                                {
                                    DisplayMessages(string.Format("  Delete failed: {0} ", statusMessage));
                                }
                                break;

                            case "conceptscheme":                                     //
                            case "skos:conceptscheme":
                                DisplayMessages(string.Format("{0}. Deleting ConceptScheme by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid));
                                if (!new ConceptSchemeManager().Delete(envelopeIdentifier, ctid, ref statusMessage))
                                {
                                    DisplayMessages(string.Format("  Delete failed: {0} ", statusMessage));
                                }
                                break;

                            case "pathway":
                                DisplayMessages(string.Format("{0}. Deleting Pathway by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid));
                                if (!new PathwayManager().Delete(envelopeIdentifier, ctid, ref statusMessage))
                                {
                                    DisplayMessages(string.Format("  Delete failed: {0} ", statusMessage));
                                }
                                break;

                            case "pathwayset":
                                DisplayMessages(string.Format("{0}. Deleting PathwaySet by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid));
                                if (!new PathwaySetManager().Delete(envelopeIdentifier, ctid, ref statusMessage))
                                {
                                    DisplayMessages(string.Format("  Delete failed: {0} ", statusMessage));
                                }
                                break;

                            case "transfervalueprofile":
                                DisplayMessages(string.Format("{0}. Deleting transfervalue by Ctid: {1} ", cntr, ctid));
                                if (!new TransferValueProfileManager().Delete(ctid, ref statusMessage))
                                {
                                    DisplayMessages(string.Format("  Delete failed: {0} ", statusMessage));
                                }
                                break;

                            default:
                                //default to credential
                                DisplayMessages(string.Format("{0}. Deleting Credential ({2}) by EnvelopeIdentifier/ctid: {1}/{3} ", cntr, item.EnvelopeIdentifier, ctdlType, ctid));
                                if (!new CredentialManager().Delete(ctid, ref statusMessage))
                                {
                                    DisplayMessages(string.Format("  Delete failed: {0} ", statusMessage));
                                }
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            LoggingHelper.LogError(ex, string.Format("Exception encountered in envelopeId: {0}", item.EnvelopeIdentifier), false, "CredentialFinder Import exception");
                            //importError = ex.Message;
                        }

                        if (maxRecords > 0 && cntr > maxRecords)
                        {
                            break;
                        }
                    }                     //foreach ( ReadEnvelope item in list )

                    if ((maxRecords > 0 && cntr > maxRecords) || cntr > pTotalRows)
                    {
                        isComplete = true;
                        DisplayMessages(string.Format("Delete EARLY EXIT. Completed {0} records out of a total of {1} ", cntr, pTotalRows));
                    }
                    pageNbr++;
                }                 //while
                                  //delete from elastic
                if (cntr > 0)
                {
                    messages = new List <string>();
                    ElasticHelper.HandlePendingDeletes(ref messages);
                }

                importResults = string.Format("HandleDeletes - Processed {0} records, with {1} exceptions. \r\n", cntr, exceptionCtr);
                if (!string.IsNullOrWhiteSpace(importNote))
                {
                    importResults += importNote;
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, "Import.HandleDeletes");
            }
            //actually only attepted at this time, need to account for errors!
            recordsDeleted = cntr;
            return(importResults);
        }