public static string HandleDeletes(string community, string startingDate, string endingDate, int maxRecords, ref int recordsDeleted) { int pageNbr = 1; int pageSize = 50; //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 = ""; LoggingHelper.DoTrace(1, string.Format("=== DELETES ===", thisClassName)); //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 + ".HandleDeletes() - " + 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 4 or greater - just as a precaution messages = new List <string>(); status = new SaveStatus(); status.ValidationGroup = "Deletes"; //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 {3} by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid, ctdlType)); if (!new OrganizationManager().Delete(envelopeIdentifier, ctid, ref statusMessage)) { DisplayMessages(string.Format(" Delete failed: {0} ", statusMessage)); } break; case "assessmentprofile": DisplayMessages(string.Format("{0}. Deleting Assessment by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid)); if (!new AssessmentManager().Delete(envelopeIdentifier, ctid, ref statusMessage)) { DisplayMessages(string.Format(" Delete failed: {0} ", statusMessage)); } break; case "learningopportunityprofile": DisplayMessages(string.Format("{0}. Deleting LearningOpportunity by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid)); if (!new LearningOpportunityManager().Delete(envelopeIdentifier, 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 EducationFrameworkManager().Delete(envelopeIdentifier, 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(envelopeIdentifier, 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 ) pageNbr++; 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)); } } //while //delete from elastic if (cntr > 0) { messages = new List <string>(); ElasticServices.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); }