Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
        public bool UpdateParts(ThisEntity entity, ref SaveStatus status)
        {
            bool isAllValid = true;
            Entity_AgentRelationshipManager mgr = new Entity_AgentRelationshipManager();
            Entity relatedEntity = EntityManager.GetEntity(entity.RowId);

            if (relatedEntity == null || relatedEntity.Id == 0)
            {
                status.AddError(thisClassName + " - Error - the parent entity was not found.");
                return(false);
            }
            mgr.DeleteAll(relatedEntity, ref status);

            mgr.SaveList(relatedEntity.Id, Entity_AgentRelationshipManager.ROLE_TYPE_OFFERED_BY, entity.OfferedBy, ref status);
            mgr.SaveList(relatedEntity.Id, Entity_AgentRelationshipManager.ROLE_TYPE_OWNER, entity.OwnedBy, ref status);

            var epmgr = new Entity_PathwayManager();
            //handle pathways - using replace
            //actually just use typical pattern of delete all and then add
            //could be extreme
            //epmgr.DeleteAll( parent.EntityUid, ref status );
            var list = new List <int>();

            //check if we should get the list of ids easier
            foreach (var item in entity.HasPathwayList)
            {
                var p = PathwayManager.GetBasic(item);
                if (p != null && p.Id > 0)
                {
                    list.Add(p.Id);
                }
                else
                {
                    //??
                    status.AddError(thisClassName + string.Format(" - Error - the pathway using Guid: {0} entity was not found.", item.ToString()));
                }
            }
            if (!new Entity_PathwayManager().Replace(entity.RowId, 1, list, ref status))
            {
                isAllValid = false;
            }

            return(isAllValid);
        }