public static void MapFromDB(DBEntity input, ThisEntity output, bool includingPathways = false) { output.Id = input.Id; output.RowId = input.RowId; output.CTID = input.CTID; output.Name = input.Name; output.Description = input.Description; output.SubjectWebpage = input.SubjectWebpage; output.EntityStateId = (int)(input.EntityStateId ?? 2); //TODO - get pathways if (includingPathways) { output.Pathways = Entity_PathwayManager.GetAll(output.RowId, true); output.HasPathway = output.Pathways.Select(m => m.CTID).ToList(); } else { //really only need the pathway ids for publishing - also ctid //might just get the lite versions of a pathway? output.Pathways = Entity_PathwayManager.GetAll(output.RowId, false); //always collect for now output.HasPathway = output.Pathways.Select(m => m.CTID).ToList(); } if (IsGuidValid(input.OwningAgentUid)) { output.OwningAgentUid = ( Guid )input.OwningAgentUid; output.OwningOrganization = OrganizationManager.GetForSummary(output.OwningAgentUid); //get roles OrganizationRoleProfile orp = Entity_AgentRelationshipManager.AgentEntityRole_GetAsEnumerationFromCSV(output.RowId, output.OwningAgentUid); output.OwnerRoles = orp.AgentRole; } // output.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration(output.RowId, true); //confustion over OrganizationRole and OwnerRoles (enum)!!! //to.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration( to.RowId, true ); output.CredentialRegistryId = input.CredentialRegistryId; if (IsValidDate(input.Created)) { output.Created = ( DateTime )input.Created; } if (IsValidDate(input.LastUpdated)) { output.LastUpdated = ( DateTime )input.LastUpdated; } var relatedEntity = EntityManager.GetEntity(output.RowId, false); if (relatedEntity != null && relatedEntity.Id > 0) { output.EntityLastUpdated = relatedEntity.LastUpdated; } }
} // public static void MapFromDB(DBEntity input, ThisEntity output, bool gettingAll = true) { output.Id = input.Id; output.RowId = input.RowId; output.EntityStateId = input.EntityStateId; output.Name = input.Name; output.Description = input.Description; output.CTID = input.CTID; if (input.Created != null) { output.Created = ( DateTime )input.Created; } if (input.LastUpdated != null) { output.LastUpdated = ( DateTime )input.LastUpdated; } if (IsGuidValid(input.OwningAgentUid)) { output.OwningAgentUid = ( Guid )input.OwningAgentUid; output.OwningOrganization = OrganizationManager.GetForSummary(output.OwningAgentUid); //get roles OrganizationRoleProfile orp = Entity_AgentRelationshipManager.AgentEntityRole_GetAsEnumerationFromCSV(output.RowId, output.OwningAgentUid); output.OwnerRoles = orp.AgentRole; } // output.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration(output.RowId, true); // //get related .... var relatedEntity = EntityManager.GetEntity(output.RowId, false); if (relatedEntity != null && relatedEntity.Id > 0) { output.EntityLastUpdated = relatedEntity.LastUpdated; } // output.SubjectWebpage = input.SubjectWebpage; output.CredentialRegistryId = input.CredentialRegistryId ?? ""; output.LifecycleStatusType = string.IsNullOrWhiteSpace(input.LifecycleStatusType) ? "lifecycle:Active" : input.LifecycleStatusType; //output.CodedNotation = input.CodedNotation; //20-12-16 changed to a string as partial dates are possible if (!string.IsNullOrWhiteSpace(input.StartDate)) { output.StartDate = input.StartDate; } else { output.StartDate = ""; } // if (!string.IsNullOrWhiteSpace(input.EndDate)) { output.EndDate = input.EndDate; } else { output.EndDate = ""; } //derived from .... //get json and expand output.IdentifierJson = input.IdentifierJson; output.TransferValueJson = input.TransferValueJson; output.TransferValueFromJson = input.TransferValueFromJson; output.TransferValueForJson = input.TransferValueForJson; // if (!string.IsNullOrWhiteSpace(output.IdentifierJson)) { output.Identifier = JsonConvert.DeserializeObject <List <Entity_IdentifierValue> >(output.IdentifierJson); } if (!string.IsNullOrWhiteSpace(output.TransferValueJson)) { output.TransferValue = JsonConvert.DeserializeObject <List <ValueProfile> >(output.TransferValueJson); } if (!gettingAll) { return; } //the top level object may not be enough. First need to confirm if reference lopps and asmts can have detail pages. if (!string.IsNullOrWhiteSpace(output.TransferValueFromJson)) { output.TransferValueFrom = JsonConvert.DeserializeObject <List <TopLevelObject> >(output.TransferValueFromJson); var lopps = output.TransferValueFrom.Where(s => s.EntityTypeId == 7).ToList(); foreach (var item in lopps) { output.TransferValueFromLopp.Add(LearningOpportunityManager.GetForDetail(item.Id)); } var assmts = output.TransferValueFrom.Where(s => s.EntityTypeId == 3).ToList(); foreach (var item in assmts) { output.TransferValueFromAsmt.Add(AssessmentManager.GetForDetail(item.Id)); } var creds = output.TransferValueFrom.Where(s => s.EntityTypeId == 1).ToList(); foreach (var item in creds) { output.TransferValueFromCredential.Add(CredentialManager.GetForDetail(item.Id)); } } // if (!string.IsNullOrWhiteSpace(output.TransferValueForJson)) { output.TransferValueFor = JsonConvert.DeserializeObject <List <TopLevelObject> >(output.TransferValueForJson); var lopps = output.TransferValueFor.Where(s => s.EntityTypeId == 7).ToList(); foreach (var item in lopps) { output.TransferValueForLopp.Add(LearningOpportunityManager.GetForDetail(item.Id)); } var assmts = output.TransferValueFor.Where(s => s.EntityTypeId == 3).ToList(); foreach (var item in assmts) { output.TransferValueForAsmt.Add(AssessmentManager.GetForDetail(item.Id)); } var creds = output.TransferValueFor.Where(s => s.EntityTypeId == 1).ToList(); foreach (var item in creds) { output.TransferValueForCredential.Add(CredentialManager.GetForDetail(item.Id)); } } //this should be a summary level, not the full TVP output.DerivedFrom = Entity_TransferValueProfileManager.GetAll(output.RowId); // List <ProcessProfile> processes = Entity_ProcessProfileManager.GetAll(output.RowId); foreach (ProcessProfile item in processes) { if (item.ProcessTypeId == Entity_ProcessProfileManager.DEV_PROCESS_TYPE) { output.DevelopmentProcess.Add(item); } else { //unexpected } } }
public static void MapFromDB_Basic(DBEntity input, ThisEntity output, bool includingComponents) { output.Id = input.Id; output.RowId = input.RowId; output.EntityStateId = ( int )(input.EntityStateId ?? 1); output.Name = input.Name; output.Description = input.Description == null ? "" : input.Description; output.CTID = input.CTID; if (IsGuidValid(input.OwningAgentUid)) { output.OwningAgentUid = ( Guid )input.OwningAgentUid; output.OwningOrganization = OrganizationManager.GetForSummary(output.OwningAgentUid); output.OrganizationId = output.OwningOrganization.Id; //get roles OrganizationRoleProfile orp = Entity_AgentRelationshipManager.AgentEntityRole_GetAsEnumerationFromCSV(output.RowId, output.OwningAgentUid); output.OwnerRoles = orp.AgentRole; } // output.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration(output.RowId, true); // output.SubjectWebpage = input.SubjectWebpage; if (IsValidDate(input.Created)) { output.Created = ( DateTime )input.Created; } if (IsValidDate(input.LastUpdated)) { output.LastUpdated = ( DateTime )input.LastUpdated; } if (string.IsNullOrWhiteSpace(output.CTID) || output.EntityStateId < 3) { output.IsReferenceVersion = true; return; } //===== var relatedEntity = EntityManager.GetEntity(output.RowId, false); if (relatedEntity != null && relatedEntity.Id > 0) { output.EntityLastUpdated = relatedEntity.LastUpdated; } //components if (includingComponents) { // output.ProgressionModelURI = input.HasProgressionModel; if (!string.IsNullOrWhiteSpace(output.ProgressionModelURI) && includingComponents) { //ensure this is not called always from ProgressionModel/CS or will get a stack overflow output.HasProgressionModel = ConceptSchemeManager.GetByCtid(output.ProgressionModelURI); } //include conditions //to.HasPart = PathwayComponentManager.GetAllForPathway( to.CTID, PathwayComponentManager.componentActionOfDeep ); //actual may be better to do through Entity_PathwayComponent // but only destination component is under pathway //will there be an issue with recursion? //compare //one less that parts??? //var parts1 = PathwayComponentManager.GetAllForPathway( to.CTID, PathwayComponentManager.componentActionOfDeep ); //and var parts = Entity_PathwayComponentManager.GetAll(output.RowId, PathwayComponentManager.componentActionOfDeep); //may want to split out here, do in context foreach (var item in parts) { if (item.ComponentRelationshipTypeId == PathwayComponent.PathwayComponentRelationship_HasDestinationComponent) { output.HasDestinationComponent.Add(item); } else if (item.ComponentRelationshipTypeId == PathwayComponent.PathwayComponentRelationship_HasChild) { output.HasChild.Add(item); } } //now get a unique list //var parts = to.HasPart; output.HasPart = new List <PathwayComponent>(); foreach (var item in parts) { int index = output.HasPart.FindIndex(a => a.CTID == item.CTID); if (index == -1) { output.HasPart.Add(item); } } } } //