/// <summary> /// Do delete based on import of deleted documents /// </summary> /// <param name="credentialRegistryId">NOT CURRENTLY HANDLED</param> /// <param name="ctid"></param> /// <param name="statusMessage"></param> /// <returns></returns> public bool Delete(string credentialRegistryId, string ctid, ref string statusMessage) { bool isValid = true; if (string.IsNullOrWhiteSpace(ctid)) { statusMessage = thisClassName + ".Delete() Error - a valid CTID must be provided"; return(false); } using (var context = new EntityContext()) { try { context.Configuration.LazyLoadingEnabled = false; var efEntity = context.EducationFramework .FirstOrDefault(s => s.CTID == ctid); if (efEntity != null && efEntity.Id > 0) { //TODO - may need a check for existing alignments Guid rowId = efEntity.RowId; var orgCtid = efEntity.OrganizationCTID ?? ""; //need to remove from Entity. //-using before delete trigger - verify won't have RI issues string msg = string.Format(" CompetencyFramework. Id: {0}, Name: {1}, Ctid: {2}", efEntity.Id, efEntity.FrameworkName, efEntity.CTID); //leaving as virtual? //need to check for in use. //context.EducationFramework.Remove( efEntity ); efEntity.EntityStateId = 0; efEntity.LastUpdated = System.DateTime.Now; int count = context.SaveChanges(); if (count >= 0) { new ActivityManager().SiteActivityAdd(new SiteActivity() { ActivityType = "CompetencyFramework", Activity = "Import", Event = "Delete", Comment = msg }); isValid = true; } if (!string.IsNullOrWhiteSpace(orgCtid)) { List <String> messages = new List <string>(); //mark owning org for updates // - nothing yet from frameworks var org = OrganizationManager.GetByCtid(orgCtid); if (org != null && org.Id > 0) { new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_ORGANIZATION, org.Id, 1, ref messages); } else { //issue with org ctid not found } } } else { statusMessage = thisClassName + ".Delete() Warning No action taken, as the record was not found."; } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".Delete(envelopeId)"); statusMessage = FormatExceptions(ex); isValid = false; if (statusMessage.ToLower().IndexOf("the delete statement conflicted with the reference constraint") > -1) { statusMessage = thisClassName + "Error: this record cannot be deleted as it is being referenced by other items, such as roles or credentials. These associations must be removed before this assessment can be deleted."; } } } return(isValid); }
} // public bool Import(EntityServices mgr, string payload, string envelopeIdentifier, SaveStatus status) { List <string> messages = new List <string>(); MappingHelperV3 helper = new MappingHelperV3(); bool importSuccessfull = true; InputEntity input = new InputEntity(); InputCompetency comp = new InputCompetency(); var mainEntity = new Dictionary <string, object>(); List <InputCompetency> competencies = new List <InputCompetency>(); Dictionary <string, object> dictionary = RegistryServices.JsonToDictionary(payload); object graph = dictionary["@graph"]; //serialize the graph object var glist = JsonConvert.SerializeObject(graph); //parse graph in to list of objects JArray graphList = JArray.Parse(glist); var bnodes = new List <BNode>(); int cntr = 0; foreach (var item in graphList) { cntr++; //note older frameworks will not be in the priority order var main = item.ToString(); if (cntr == 1 || main.IndexOf("ceasn:CompetencyFramework") > -1) { //HACK if (main.IndexOf("ceasn:CompetencyFramework") > -1) { input = JsonConvert.DeserializeObject <InputEntity>(main); } } else { //Error converting value "https://credentialengineregistry.org/resources/ce-949fcaba-45ed-44d9-88bf-43677277eb84" to type 'System.Collections.Generic.List`1[System.String]'. Path 'ceasn:isPartOf', line 11, position 108. //not set up to handle issues //comp = JsonConvert.DeserializeObject<InputCompetency>( item.ToString() ); //competencies.Add( comp ); //should just have competencies, but should check for bnodes var child = item.ToString(); if (child.IndexOf("_:") > -1) { bnodes.Add(JsonConvert.DeserializeObject <BNode>(child)); //ceasn:Competency } else if (child.IndexOf("ceasn:Competency") > -1) { competencies.Add(JsonConvert.DeserializeObject <InputCompetency>(child)); } else { //unexpected } } } //try //{ //input = JsonConvert.DeserializeObject<InputGraph>( item.DecodedResource.ToString() ); string ctid = input.CTID; status.Ctid = ctid; string referencedAtId = input.CtdlId; LoggingHelper.DoTrace(5, " ctid: "+ ctid); LoggingHelper.DoTrace(5, " @Id: "+ input.CtdlId); LoggingHelper.DoTrace(5, " name: "+ input.name.ToString()); string framework = input.name.ToString(); string orgCTID = ""; string orgName = ""; List <string> publisher = input.publisher; //should check creator first? Or will publisher be more likely to have an account Ctid? if (publisher != null && publisher.Count() > 0) { orgCTID = ResolutionServices.ExtractCtid(publisher[0]); //look up org name orgName = OrganizationManager.GetByCtid(orgCTID).Name ?? "missing"; } else { //try creator List <string> creator = input.creator; if (creator != null && creator.Count() > 0) { orgCTID = ResolutionServices.ExtractCtid(creator[0]); //look up org name orgName = OrganizationManager.GetByCtid(orgCTID).Name ?? "missing"; } } if (status.DoingDownloadOnly) { return(true); } //add updating educationFramework Framework ef = new Framework(); if (!DoesEntityExist(input.CTID, ref ef)) { //set the rowid now, so that can be referenced as needed output.RowId = Guid.NewGuid(); ef.RowId = Guid.NewGuid(); } helper.currentBaseObject = ef; ef.ExistsInRegistry = true; ef.FrameworkName = helper.HandleLanguageMap(input.name, ef, "Name"); ef.CTID = input.CTID; ef.OrganizationCTID = orgCTID; ef.CredentialRegistryId = envelopeIdentifier; //can only handle one source int pcnt = 0; foreach (var url in input.source) { pcnt++; ef.SourceUrl = url; break; } ef.FrameworkUri = input.CtdlId; new EducationFrameworkManager().Save(ef, ref status, true); // // //framework checks if (input.inLanguage == null || input.inLanguage.Count() == 0) { //document for followup //LoggingHelper.DoTrace( 5, " Framework missing inLanguage: " + input.name.ToString() ); } //output.Name = helper.HandleLanguageMap( input.name, output, "Name" ); //output.description = helper.HandleLanguageMap( input.description, output, "Description" ); output.Ctid = input.CTID; return(importSuccessfull); }