Esempio n. 1
0
 public static MP.TransferValueProfile HandlingExistingEntity(string ctid, ref SaveStatus status)
 {
     MP.TransferValueProfile entity = new MP.TransferValueProfile();
     //warning-
     entity = TransferValueProfileManager.GetByCtid(ctid);
     if (entity != null && entity.Id > 0)
     {
         Entity relatedEntity = EntityManager.GetEntity(entity.RowId);
         if (relatedEntity == null || relatedEntity.Id == 0)
         {
             status.AddError(string.Format("Error - the related Entity for transfer value: '{0}' ({1}), was not found.", entity.Name, entity.Id));
             return(entity);
         }
         //we know for this type, there will entity.learningopp, entity.assessment and entity.credential relationships, and quick likely blank nodes.
         //delete related entity if a reference
         //there are for and from relationships!! - OK in this case it will be all
         new Entity_AssessmentManager().DeleteAll(relatedEntity, ref status);
         new Entity_CredentialManager().DeleteAll(relatedEntity, ref status);
         new Entity_LearningOpportunityManager().DeleteAll(relatedEntity, ref status);
         //also
         entity.TransferValueFor  = new List <TopLevelObject>();
         entity.TransferValueFrom = new List <TopLevelObject>();
     }
     return(entity);
 }
        }        //

        public static ThisEntity GetByCtid(string ctid)
        {
            ThisEntity entity = new ThisEntity();

            if (string.IsNullOrWhiteSpace(ctid))
            {
                return(entity);
            }
            try
            {
                using (var context = new EntityContext())
                {
                    //lookup by SubjectWebpage, or SourceUrl
                    DBEntity item = context.TransferValueProfile
                                    .FirstOrDefault(s => s.CTID.ToLower() == ctid.ToLower());

                    if (item != null && item.Id > 0)
                    {
                        MapFromDB(item, entity);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".GetByCtid: " + ctid);
            }
            return(entity);
        }        //
        /// <summary>
        /// Get a competency record
        /// </summary>
        /// <param name="profileId"></param>
        /// <returns></returns>
        public static ThisEntity Get(int profileId)
        {
            ThisEntity entity = new ThisEntity();

            if (profileId == 0)
            {
                return(entity);
            }
            try
            {
                using (var context = new EntityContext())
                {
                    DBEntity item = context.TransferValueProfile
                                    .SingleOrDefault(s => s.Id == profileId);

                    if (item != null && item.Id > 0)
                    {
                        MapFromDB(item, entity);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Get");
            }
            return(entity);
        }        //
        public int AddPendingRecord(Guid entityUid, string ctid, string registryAtId, ref string status)
        {
            DBEntity efEntity = new DBEntity();

            try
            {
                using (var context = new EntityContext())
                {
                    if (!IsValidGuid(entityUid))
                    {
                        status = thisClassName + " - A valid GUID must be provided to create a pending entity";
                        return(0);
                    }
                    //quick check to ensure not existing
                    ThisEntity entity = GetByCtid(ctid);
                    if (entity != null && entity.Id > 0)
                    {
                        return(entity.Id);
                    }

                    //only add DB required properties
                    //NOTE - an entity will be created via trigger
                    efEntity.Name          = "Placeholder until full document is downloaded";
                    efEntity.Description   = "Placeholder until full document is downloaded";
                    efEntity.EntityStateId = 1;
                    efEntity.RowId         = entityUid;
                    //watch that Ctid can be  updated if not provided now!!
                    efEntity.CTID           = ctid;
                    efEntity.CTID           = ctid;
                    efEntity.SubjectWebpage = registryAtId;

                    efEntity.Created     = System.DateTime.Now;
                    efEntity.LastUpdated = System.DateTime.Now;

                    context.TransferValueProfile.Add(efEntity);
                    int count = context.SaveChanges();
                    if (count > 0)
                    {
                        return(efEntity.Id);
                    }

                    status = thisClassName + " Error - the save was not successful, but no message provided. ";
                }
            }

            catch (Exception ex)
            {
                string message = FormatExceptions(ex);
                LoggingHelper.LogError(ex, thisClassName + string.Format(".AddPendingRecord. entityUid:  {0}, ctid: {1}", entityUid, ctid));
                status = thisClassName + " Error - the save was not successful. " + message;
            }
            return(0);
        }
        //currently
        public bool DoesEntityExist(string ctid, ref ThisEntity entity, ref SaveStatus status)
        {
            bool exists = false;

            entity = EntityServices.HandlingExistingEntity(ctid, ref status);
            if (entity != null && entity.Id > 0)
            {
                //we know for this type, there will entity.learningopp, entity.assessment and entity.credential relationships, and quick likely blank nodes.
                return(true);
            }

            return(exists);
        }
        public bool ValidateProfile(ThisEntity profile, ref SaveStatus status)
        {
            status.HasSectionErrors = false;

            if (string.IsNullOrWhiteSpace(profile.Name))
            {
                status.AddWarning("An Transfer Value Profile name must be entered");
            }

            //if we don't require url, we can't resolve potentially duplicate framework names


            return(status.WasSectionValid);
        }
Esempio n. 7
0
        public bool Import(ThisEntity entity, ref SaveStatus status)
        {
            bool          isValid  = new EntityMgr().Save(entity, ref status);
            List <string> messages = new List <string>();

            if (entity.Id > 0)
            {
                if (UtilityManager.GetAppKeyValue("delayingAllCacheUpdates", false) == false)
                {
                    //update cache - not applicable yet

                    //update Elastic
                    if (Utilities.UtilityManager.GetAppKeyValue("updatingElasticIndexImmediately", false))
                    {
                        //ElasticHelper.TransferValueProfile_UpdateIndex( entity.Id );
                    }
                    else
                    {
                        new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_TRANSFER_VALUE_PROFILE, entity.Id, 1, ref messages);
                        if (messages.Count > 0)
                        {
                            status.AddWarningRange(messages);
                        }
                    }
                    //also update related org
                    new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_ORGANIZATION, entity.OwningOrganizationId, 1, ref messages);
                }
                else
                {
                    new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_TRANSFER_VALUE_PROFILE, entity.Id, 1, ref messages);
                    if (entity.OwningOrganizationId > 0)
                    {
                        new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_ORGANIZATION, entity.OwningOrganizationId, 1, ref messages);
                    }
                    if (messages.Count > 0)
                    {
                        status.AddWarningRange(messages);
                    }
                }
                //no caching needed yet
                //CacheManager.RemoveItemFromCache( "cframework", entity.Id );
            }

            return(isValid);
        }
Esempio n. 8
0
 public static MP.TransferValueProfile GetByCtid(string ctid)
 {
     MP.TransferValueProfile entity = new MP.TransferValueProfile();
     entity = TransferValueProfileManager.GetByCtid(ctid);
     return(entity);
 }
Esempio n. 9
0
 public static MP.TransferValueProfile Get(int id)
 {
     MP.TransferValueProfile entity = new MP.TransferValueProfile();
     entity = TransferValueProfileManager.Get(id);
     return(entity);
 }
        //public static int Count_ForOwningOrg( string orgCtid )
        //{
        //	int totalRecords = 0;
        //	if ( string.IsNullOrWhiteSpace( orgCtid ) || orgCtid.Trim().Length != 39 )
        //		return totalRecords;

        //	using ( var context = new EntityContext() )
        //	{
        //		var query = ( from entity in context.TransferValueProfile
        //					  join org in context.Organization on entity.OrganizationCTID equals org.CTID
        //					  where entity.OrganizationCTID.ToLower() == orgCtid.ToLower()
        //						   && org.EntityStateId > 1 && entity.EntityStateId == 3
        //					  select new
        //					  {
        //						  entity.CTID
        //					  } );
        //		//until ed frameworks is cleaned up, need to prevent dups != 39
        //		var results = query.Select( s => s.CTID ).Distinct()
        //			.ToList();

        //		if ( results != null && results.Count > 0 )
        //		{
        //			totalRecords = results.Count();

        //		}
        //	}

        //	return totalRecords;
        //}

        public static List <ThisEntity> Search(string pFilter, string pOrderBy, int pageNumber, int pageSize, ref int pTotalRows)
        {
            string connectionString = DBConnectionRO();
            var    item             = new ThisEntity();
            var    list             = new List <ThisEntity>();
            var    result           = new DataTable();

            using (SqlConnection c = new SqlConnection(connectionString))
            {
                c.Open();

                if (string.IsNullOrEmpty(pFilter))
                {
                    pFilter = "";
                }

                using (SqlCommand command = new SqlCommand("[TransferValue.ElasticSearch]", c))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add(new SqlParameter("@Filter", pFilter));
                    command.Parameters.Add(new SqlParameter("@SortOrder", pOrderBy));
                    command.Parameters.Add(new SqlParameter("@StartPageIndex", pageNumber));
                    command.Parameters.Add(new SqlParameter("@PageSize", pageSize));

                    SqlParameter totalRows = new SqlParameter("@TotalRows", pTotalRows);
                    totalRows.Direction = ParameterDirection.Output;
                    command.Parameters.Add(totalRows);

                    using (SqlDataAdapter adapter = new SqlDataAdapter())
                    {
                        adapter.SelectCommand = command;
                        adapter.Fill(result);
                    }
                    string rows = command.Parameters[4].Value.ToString();
                    try
                    {
                        pTotalRows = Int32.Parse(rows);
                    }
                    catch
                    {
                        pTotalRows = 0;
                    }
                }

                foreach (DataRow dr in result.Rows)
                {
                    item      = new ThisEntity();
                    item.Id   = GetRowColumn(dr, "Id", 0);
                    item.CTID = GetRowColumn(dr, "CTID", "");
                    item.Name = GetRowColumn(dr, "Name", "???");
                    item.PrimaryOrganizationName = GetRowColumn(dr, "OrganizationName", "");
                    item.Description             = GetRowColumn(dr, "Description", "");
                    item.SubjectWebpage          = GetRowColumn(dr, "SubjectWebpage", "");
                    //item.CodedNotation = GetRowColumn( dr, "CodedNotation", "" );
                    item.StartDate = GetRowColumn(dr, "StartDate", "");
                    item.EndDate   = GetRowColumn(dr, "EndDate", "");

                    item.IdentifierJson        = GetRowColumn(dr, "IdentifierJson", "");
                    item.TransferValueJson     = GetRowColumn(dr, "TransferValueJson", "");
                    item.TransferValueFromJson = GetRowColumn(dr, "TransferValueFromJson", "");
                    item.TransferValueForJson  = GetRowColumn(dr, "TransferValueForJson", "");
                    //
                    item.EntityLastUpdated = GetRowColumn(dr, "EntityLastUpdated", System.DateTime.MinValue);
                    item.Created           = GetRowColumn(dr, "Created", System.DateTime.MinValue);
                    //item.LastUpdated = GetRowColumn( dr, "LastUpdated", System.DateTime.MinValue );

                    list.Add(item);
                }

                return(list);
            }
        }         //
        }         //

        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 MapToDB(ThisEntity input, DBEntity output)
        {
            //want to ensure fields from create are not wiped
            //to.Id = from.Id;

            output.Name = input.Name;
            //TODO - can't have pending or references
            output.EntityStateId        = 3;
            output.Description          = input.Description;
            output.CTID                 = input.CTID;
            output.SubjectWebpage       = input.SubjectWebpage ?? "";
            output.CredentialRegistryId = input.CredentialRegistryId ?? "";
            output.OwningAgentUid       = input.OwningAgentUid;

            //need to handle a partial date
            if (!string.IsNullOrWhiteSpace(input.StartDate))
            {
                output.StartDate = input.StartDate;
                if ((output.StartDate ?? "").Length > 20)
                {
                    output.StartDate = output.StartDate.Substring(0, 10);
                }
            }
            else
            {
                output.StartDate = null;
            }
            //
            if (!string.IsNullOrWhiteSpace(input.EndDate))
            {
                output.EndDate = input.EndDate;
                if ((output.EndDate ?? "").Length > 20)
                {
                    output.EndDate = output.EndDate.Substring(0, 10);
                }
            }
            else
            {
                output.EndDate = null;
            }



            output.LifecycleStatusType = string.IsNullOrWhiteSpace(input.LifecycleStatusType) ? "lifecycle:Active" : input.LifecycleStatusType;
            //output.CodedNotation = input.CodedNotation;

            //just store the json
            output.IdentifierJson        = input.IdentifierJson;
            output.TransferValueJson     = input.TransferValueJson;
            output.TransferValueFromJson = input.TransferValueFromJson;
            output.TransferValueForJson  = input.TransferValueForJson;

            //output.ProfileGraph = input.ProfileGraph;
            //ensure we don't reset the graph
            //if ( !string.IsNullOrWhiteSpace( input.ProfileGraph ) )
            //	output.ProfileGraph = input.ProfileGraph;
            //else
            //{

            //}
        }         //
        /// <summary>
        /// Add/Update a TransferValueProfile
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="messages"></param>
        /// <returns></returns>
        public bool Save(ThisEntity entity, ref SaveStatus status)
        {
            bool isValid = true;
            int  count   = 0;

            DBEntity efEntity = new DBEntity();

            try
            {
                using (var context = new EntityContext())
                {
                    if (ValidateProfile(entity, ref status) == false)
                    {
                        return(false);
                    }

                    if (entity.Id == 0)
                    {
                        //add
                        efEntity = new DBEntity();
                        MapToDB(entity, efEntity);

                        if (IsValidDate(status.EnvelopeCreatedDate))
                        {
                            efEntity.Created     = status.LocalCreatedDate;
                            efEntity.LastUpdated = status.LocalCreatedDate;
                        }
                        else
                        {
                            efEntity.Created     = System.DateTime.Now;
                            efEntity.LastUpdated = System.DateTime.Now;
                        }

                        if (IsValidGuid(entity.RowId))
                        {
                            efEntity.RowId = entity.RowId;
                        }
                        else
                        {
                            efEntity.RowId = Guid.NewGuid();
                        }

                        context.TransferValueProfile.Add(efEntity);

                        count = context.SaveChanges();

                        entity.Id    = efEntity.Id;
                        entity.RowId = efEntity.RowId;
                        if (count == 0)
                        {
                            status.AddWarning(string.Format(" Unable to add Profile: {0} <br\\> ", string.IsNullOrWhiteSpace(entity.Name) ? "no description" : entity.Name));
                        }
                        else
                        {
                            //add log entry
                            SiteActivity sa = new SiteActivity()
                            {
                                ActivityType     = "TransferValueProfile",
                                Activity         = "Import",
                                Event            = "Add",
                                Comment          = string.Format("New Transfer Value Profile was found by the import. Name: {0}, URI: {1}", entity.Name, entity.SubjectWebpage),
                                ActivityObjectId = entity.Id
                            };
                            new ActivityManager().SiteActivityAdd(sa);

                            if (!UpdateParts(entity, ref status))
                            {
                                isValid = false;
                            }
                        }
                    }
                    else
                    {
                        efEntity = context.TransferValueProfile.FirstOrDefault(s => s.Id == entity.Id);
                        if (efEntity != null && efEntity.Id > 0)
                        {
                            entity.RowId = efEntity.RowId;
                            //update
                            MapToDB(entity, efEntity);
                            if (IsValidDate(status.EnvelopeCreatedDate) && status.LocalCreatedDate < efEntity.Created)
                            {
                                efEntity.Created = status.LocalCreatedDate;
                            }
                            if (IsValidDate(status.EnvelopeUpdatedDate) && status.LocalUpdatedDate != efEntity.LastUpdated)
                            {
                                efEntity.LastUpdated = status.LocalUpdatedDate;
                            }
                            //has changed?
                            if (HasStateChanged(context))
                            {
                                if (IsValidDate(status.EnvelopeUpdatedDate))
                                {
                                    efEntity.LastUpdated = status.LocalUpdatedDate;
                                }
                                else
                                {
                                    efEntity.LastUpdated = DateTime.Now;
                                }

                                count = context.SaveChanges();

                                //add log entry
                                SiteActivity sa = new SiteActivity()
                                {
                                    ActivityType     = "TransferValueProfile",
                                    Activity         = "Import",
                                    Event            = "Update",
                                    Comment          = string.Format("Updated Transfer Value Profile found by the import. Name: {0}, URI: {1}", entity.Name, entity.SubjectWebpage),
                                    ActivityObjectId = entity.Id
                                };
                                new ActivityManager().SiteActivityAdd(sa);
                            }
                            if (!UpdateParts(entity, ref status))
                            {
                                isValid = false;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, "TransferValueProfileManager.Save()");
            }

            return(isValid);
        }
        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("Error - the related Entity was not found.");
                return(false);
            }
            mgr.DeleteAll(relatedEntity, ref status);
            mgr.SaveList(relatedEntity.Id, Entity_AgentRelationshipManager.ROLE_TYPE_OWNER, entity.OwnedBy, ref status);
            //consider storing the class properties as Json!

            //derived from
            //where to store this? It commonly require Entity.TransferValueProfile
            var etvlMgr = new Entity_TransferValueProfileManager();

            etvlMgr.SaveList(entity.DerivedFromForImport, entity.RowId, ref status);


            //delete all Entity.Lopp, .Cred, and .Assessment relationships, and then add?
            //would be convenient if a delete wasn't necessary
            //NOTE: this will leave orphan reference objects. Will need to clean up.
            //could check if target is a reference. If so delete, or check if there are other references
            //NOTE: this should have been done in TransferValueServices.HandlingExistingEntity - is done corrently, remove this
            Entity_CredentialManager ecm = new Entity_CredentialManager();

            ecm.DeleteAll(relatedEntity, ref status);
            //
            var eam = new Entity_AssessmentManager();

            eam.DeleteAll(relatedEntity, ref status);
            //
            var elom = new Entity_LearningOpportunityManager();

            elom.DeleteAll(relatedEntity, ref status);
            //
            var etvp = new Entity_TransferValueProfileManager();

            etvp.DeleteAll(relatedEntity, ref status);
            //
            foreach (var item in entity.TransferValueFromImport)
            {
                int newId = 0;
                var from  = EntityManager.GetEntity(item, false);
                if (from == null || from.Id == 0)
                {
                    status.AddError(string.Format("{0}.UpdateParts - TransferValueFromImport. TVP: {1}. An entity was not found for GUID: {2}", thisClassName, entity.Id, item));
                    continue;
                }
                if (from.EntityTypeId == 1)
                {
                    ecm.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_IS_PART_OF, ref newId, ref status);
                }
                else if (from.EntityTypeId == 3)
                {
                    eam.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_IS_PART_OF, false, ref status);
                }
                else if (from.EntityTypeId == 7)
                {
                    elom.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_IS_PART_OF, false, ref status);
                }
            }

            foreach (var item in entity.TransferValueForImport)
            {
                int newId = 0;
                var from  = EntityManager.GetEntity(item, false);
                if (from == null || from.Id == 0)
                {
                    //??
                    status.AddError(string.Format("{0}.UpdateParts - TransferValueForImport. TVP: {1}. An entity was not found for GUID: {2}", thisClassName, entity.Id, item));
                    continue;
                }
                if (from.EntityTypeId == 1)
                {
                    ecm.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_HAS_PART, ref newId, ref status);
                }
                else if (from.EntityTypeId == 3)
                {
                    eam.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_HAS_PART, false, ref status);
                }
                else if (from.EntityTypeId == 7)
                {
                    elom.Add(entity.RowId, from.EntityBaseId, BaseFactory.RELATIONSHIP_TYPE_HAS_PART, false, ref status);
                }
            }

            foreach (var item in entity.DerivedFromForImport)
            {
                var from = Get(item);
                if (from == null || from.Id == 0)
                {
                    //??
                    status.AddError(string.Format("{0}.UpdateParts - DerivedFromForImport. TVP: {1}. A TVP was not found for ID: {2}", thisClassName, entity.Id, item));
                    continue;
                }
                //check that not the same as current TVP
                if (from.Id == entity.Id)
                {
                    status.AddError(string.Format("{0}.UpdateParts - DerivedFromForImport. TVP: {1}. The DerivedFrom TVP Id ({2}) is the same as the current TVP ID", thisClassName, entity.Id, item));
                    continue;
                }
                etvp.Add(entity.RowId, item, ref status);
            }

            //ProcessProfile
            Entity_ProcessProfileManager ppm = new Factories.Entity_ProcessProfileManager();

            ppm.DeleteAll(relatedEntity, ref status);
            try
            {
                ppm.SaveList(entity.DevelopmentProcess, Entity_ProcessProfileManager.DEV_PROCESS_TYPE, entity.RowId, ref status);
            }
            catch (Exception ex)
            {
                string message = FormatExceptions(ex);
                LoggingHelper.LogError(ex, thisClassName + string.Format(".AddProfiles() - ProcessProfiles. id: {0}", entity.Id));
                status.AddWarning(thisClassName + ".AddProfiles(). Exceptions encountered handling ProcessProfiles. " + message);
            }
            return(isAllValid);
        }
        private static WMA.TransferValueProfile MapToAPI(ThisEntity input)
        {
            var output = new WMA.TransferValueProfile()
            {
                Meta_Id               = input.Id,
                CTID                  = input.CTID,
                Name                  = input.Name,
                FriendlyName          = HttpUtility.UrlPathEncode(input.Name),
                Description           = input.Description,
                SubjectWebpage        = input.SubjectWebpage,
                EntityTypeId          = 26,
                StartDate             = input.StartDate,
                EndDate               = input.EndDate,
                CredentialRegistryURL = RegistryServices.GetResourceUrl(input.CTID),
                RegistryData          = ServiceHelper.FillRegistryData(input.CTID)
            };

            if (input.OwningOrganizationId > 0)
            {
                output.OwnedByLabel = ServiceHelper.MapDetailLink("Organization", input.OrganizationName, input.OwningOrganizationId);
            }

            var orgOutline = ServiceHelper.MapToOutline(input.OwningOrganization, "organization");

            //var work = ServiceHelper.MapOrganizationRoleProfileToOutline( input.OrganizationRole, Entity_AgentRelationshipManager.ROLE_TYPE_OWNER );
            output.OwnedBy = ServiceHelper.MapOutlineToAJAX(orgOutline, "Owning Organization");
            //
            //
            output.Identifier = ServiceHelper.MapIdentifierValue(input.Identifier);
            //transferValue
            output.TransferValue = ServiceHelper.MapValueProfile(input.TransferValue, "");
            //for
            var work = new List <WMA.Outline>();

            foreach (var target in input.TransferValueFor)
            {
                if (target != null && !string.IsNullOrWhiteSpace(target.Name))
                {
                    work.Add(ServiceHelper.MapToOutline(target, ""));
                }
            }
            output.TransferValueFor = ServiceHelper.MapOutlineToAJAX(work, "Includes {0} Transfer Value For");

            //from
            work = new List <WMA.Outline>();
            foreach (var target in input.TransferValueFrom)
            {
                if (target != null && !string.IsNullOrWhiteSpace(target.Name))
                {
                    work.Add(ServiceHelper.MapToOutline(target, ""));
                }
            }
            output.TransferValueFrom = ServiceHelper.MapOutlineToAJAX(work, "Includes {0} Transfer Value From");
            //
            if (input.DevelopmentProcess.Any())
            {
                output.DevelopmentProcess = ServiceHelper.MapAJAXProcessProfile("Development Process", "", input.DevelopmentProcess);
            }

            //
            output.InLanguage = null;
            return(output);
        }