public static void MapFromDB(DBEntity from, ThisEntity to, bool includingComponents = false)
        {
            to.Id                = from.Id;
            to.RowId             = from.RowId;
            to.ParentComponentId = from.ParentComponentId;
            to.Name              = from.Name;
            to.Description       = from.Description;
            to.PathwayCTID       = from.PathwayCTID;

            to.RelatedEntity = EntityManager.GetEntity(to.RowId, false);
            if (to.RelatedEntity != null && to.RelatedEntity.Id > 0)
            {
                to.EntityLastUpdated = to.RelatedEntity.LastUpdated;
            }

            if (from.PathwayComponent != null && from.PathwayComponent.Id > 0)
            {
                //assign parent pathway component
            }
            to.RequiredNumber = from.RequiredNumber != null ? ( int )from.RequiredNumber : 0;
            //
            if (IsValidDate(from.Created))
            {
                to.Created = ( DateTime )from.Created;
            }
            if (IsValidDate(from.LastUpdated))
            {
                to.LastUpdated = ( DateTime )from.LastUpdated;
            }

            //components
            //actually may always want these, but a list (shallow get) of components
            if (includingComponents)
            {
                //get all target components
                //do we want a deep get or summary? Likely summary here
                to.TargetComponent = Entity_PathwayComponentManager.GetAll(to.RowId, PathwayComponent.PathwayComponentRelationship_TargetComponent, PathwayComponentManager.componentActionOfSummary);
            }
        }
        //


        /// <summary>
        ///
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="childComponentsAction">0-none; 1-summary; 2-deep </param>
        public static void MapFromDB(DBEntity input, ThisEntity output, int childComponentsAction = 1)
        {
            output.Id            = input.Id;
            output.RowId         = input.RowId;
            output.EntityStateId = input.EntityStateId < 1 ? 1 : input.EntityStateId;
            output.CTID          = input.CTID;
            output.Name          = input.Name;
            output.Description   = input.Description;
            output.PathwayCTID   = input.PathwayCTID;
            //if ( input.Entity_HasPathwayComponent != null && input.Entity_HasPathwayComponent.Count > 0 )
            //{
            //	//
            //}

            var relatedEntity = EntityManager.GetEntity(output.RowId, false);

            if (relatedEntity != null && relatedEntity.Id > 0)
            {
                output.EntityLastUpdated = relatedEntity.LastUpdated;
            }

            //need output get parent pathway?
            //output.IsDestinationComponentOf = Entity_PathwayComponentManager.GetPathwayForComponent( output.Id, PathwayComponent.PathwayComponentRelationship_HasDestinationComponent );

            //ispartof. Should be single, but using list for flexibility?
            //actually force one, as we are using pathway identifier an external id for a unique lookup
            //may not want output do this every time?
            //output.IsPartOf = Entity_PathwayComponentManager.GetPathwayForComponent( output.Id, PathwayComponent.PathwayComponentRelationship_HasPart );

            //may want output get all and split out
            if (childComponentsAction == 2)
            {
                output.AllComponents = Entity_PathwayComponentManager.GetAll(output.RowId, componentActionOfSummary);
                foreach (var item in output.AllComponents)
                {
                    if (item.ComponentRelationshipTypeId == PC.PathwayComponentRelationship_HasChild)
                    {
                        output.HasChild.Add(item);
                    }
                    else if (item.ComponentRelationshipTypeId == PC.PathwayComponentRelationship_IsChildOf)
                    {
                        output.IsChildOf.Add(item);
                    }
                    else if (item.ComponentRelationshipTypeId == PC.PathwayComponentRelationship_Preceeds)
                    {
                        output.Preceeds.Add(item);
                    }
                    else if (item.ComponentRelationshipTypeId == PC.PathwayComponentRelationship_Prerequiste)
                    {
                        output.Prerequisite.Add(item);
                    }
                }
                //child components - details of condition, but summary of components
                output.HasCondition = PathwayComponentConditionManager.GetAll(output.Id, true);
            }

            //output.CodedNotation = input.CodedNotation;
            output.ComponentCategory = input.ComponentCategory;
            output.ComponentTypeId   = input.ComponentTypeId;
            if (input.Codes_PathwayComponentType != null && input.Codes_PathwayComponentType.Id > 0)
            {
                output.PathwayComponentType = input.Codes_PathwayComponentType.Title;
            }
            else
            {
                output.PathwayComponentType = GetComponentType(output.ComponentTypeId);
            }
            //will be validated before getting here!
            output.CredentialType = input.CredentialType;
            if (!string.IsNullOrWhiteSpace(output.CredentialType) && output.CredentialType.IndexOf("ctdl/terms") > 0)
            {
                int pos = output.CredentialType.IndexOf("ctdl/terms");
                output.CredentialType = output.CredentialType.Substring(pos + 11);
            }

            //not sure if this will just be a URI, or point output a concept
            //if a concept, would probably need entity.hasConcept
            //output.HasProgressionLevel = input.HasProgressionLevel;
            //if ( !string.IsNullOrWhiteSpace( input.HasProgressionLevel ) )
            //{
            //	output.ProgressionLevel = ConceptSchemeManager.GetByConceptCtid( output.HasProgressionLevel );
            //	output.HasProgressionLevelDisplay = output.ProgressionLevel.PrefLabel;
            //}
            //20-10-28 now storing separated list
            if (!string.IsNullOrWhiteSpace(input.HasProgressionLevel))
            {
                string[] array = input.HasProgressionLevel.Split('|');
                if (array.Count() > 0)
                {
                    foreach (var i in array)
                    {
                        if (!string.IsNullOrWhiteSpace(i))
                        {
                            var pl = ConceptSchemeManager.GetByConceptCtid(i);
                            output.ProgressionLevels.Add(pl);

                            output.HasProgressionLevelDisplay += pl.PrefLabel + ", ";
                        }
                    }
                    output.HasProgressionLevelDisplay.Trim().TrimEnd(',');
                }
            }

            output.ProgramTerm    = input.ProgramTerm;
            output.SubjectWebpage = input.SubjectWebpage;
            output.SourceData     = input.SourceData;

            //where output store ComponentDesignation - textvalue
            //Json
            if (!string.IsNullOrEmpty(input.Properties))
            {
                PathwayComponentProperties pcp = JsonConvert.DeserializeObject <PathwayComponentProperties>(input.Properties);
                if (pcp != null)
                {
                    //unpack ComponentDesignation
                    output.ComponentDesignationList = pcp.ComponentDesignationList;
                    //credit value
                    output.CreditValue = pcp.CreditValue;
                    //this is now QuantitativeValue
                    output.PointValue = pcp.PointValue;

                    output.Identifier = new List <IdentifierValue>();
                    if (pcp.Identifier != null)
                    {
                        output.Identifier = pcp.Identifier;
                    }
                    if (pcp.SourceCredential != null && pcp.SourceCredential.Id > 0)
                    {
                        output.SourceCredential = pcp.SourceCredential;
                        output.SourceData       = "";
                    }
                    if (pcp.SourceAssessment != null && pcp.SourceAssessment.Id > 0)
                    {
                        output.SourceAssessment = pcp.SourceAssessment;
                        output.SourceData       = "";
                    }
                    if (pcp.SourceLearningOpportunity != null && pcp.SourceLearningOpportunity.Id > 0)
                    {
                        output.SourceLearningOpportunity = pcp.SourceLearningOpportunity;
                        output.SourceData = "";
                    }
                }
            }

            //
            if (IsValidDate(input.Created))
            {
                output.Created = ( DateTime )input.Created;
            }
            if (IsValidDate(input.LastUpdated))
            {
                output.LastUpdated = ( DateTime )input.LastUpdated;
            }
        }
Esempio n. 3
0
        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);
                    }
                }
            }
        }         //