}        //

        public static void MapFromDB(DBEntity from, ThisEntity to)
        {
            to.Id       = from.Id;
            to.EntityId = from.EntityId;

            to.EducationFrameworkId  = from.EducationFrameworkId ?? 0;
            to.TargetNodeName        = from.TargetNodeName;
            to.TargetNodeDescription = from.TargetNodeDescription;
            if (to.TargetNodeDescription == to.TargetNodeName)
            {
                to.TargetNodeDescription = "";
            }

            to.TargetNode    = from.TargetNode;
            to.CodedNotation = from.CodedNotation;
            to.Weight        = from.Weight ?? 0;

            //to.AlignmentTypeId = from.AlignmentTypeId ?? 0;
            //to.AlignmentType = from.AlignmentType;

            if (IsValidDate(from.Created))
            {
                to.Created = ( DateTime )from.Created;
            }

            if (from.EducationFramework != null && from.EducationFramework.FrameworkName != null)
            {
                to.FrameworkName = from.EducationFramework.FrameworkName;
            }
        }               //
        }        //

        //public static List<CredentialAlignmentObjectItem> GetAllAsAlignmentObjects( Guid parentUid, string alignmentType )
        //{
        //	//ThisEntity entity = new ThisEntity();
        //	List<CredentialAlignmentObjectItem> list = new List<CredentialAlignmentObjectItem>();
        //	CredentialAlignmentObjectItem entity = new CredentialAlignmentObjectItem();

        //	Entity parent = EntityManager.GetEntity( parentUid );
        //	if ( parent == null || parent.Id == 0 )
        //	{
        //		return list;
        //	}
        //	try
        //	{
        //		using ( var context = new EntityContext() )
        //		{
        //			List<DBEntity> results = context.Entity_Competency
        //					.Where( s => s.EntityId == parent.Id
        //					)
        //					.OrderBy( s => s.EducationFramework_Competency.EducationFramework.Name )
        //					.ThenBy( s => s.EducationFramework_Competency.Name )
        //					.ToList();
        //			//&& ( alignmentType == "" || s.AlignmentType == alignmentType )
        //			if ( results != null && results.Count > 0 )
        //			{
        //				foreach ( DBEntity item in results )
        //				{
        //					entity = new CredentialAlignmentObjectItem();
        //					ToMapAsAlignmentObjects( item, entity );
        //					list.Add( entity );
        //				}
        //			}
        //		}
        //	}
        //	catch ( Exception ex )
        //	{
        //		LoggingHelper.LogError( ex, thisClassName + ".GetAllAsAlignmentObjects" );
        //	}
        //	return list;
        //}//

        /// <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.Entity_Competency
        //					.SingleOrDefault( s => s.Id == profileId );

        //			if ( item != null && item.Id > 0 )
        //			{
        //				MapFromDB( item, entity );
        //			}
        //		}
        //	}
        //	catch ( Exception ex )
        //	{
        //		LoggingHelper.LogError( ex, thisClassName + ".Get" );
        //	}
        //	return entity;
        //}//

        /// <summary>
        /// Get entity to determine if one exists for the entity and alignment type
        /// </summary>
        /// <param name="entityId"></param>
        /// <param name="targetNodeName"></param>
        /// <returns></returns>
        public static ThisEntity Get(int entityId, string targetNodeName)
        {
            ThisEntity entity = new ThisEntity();

            if (string.IsNullOrWhiteSpace(targetNodeName))
            {
                return(entity);
            }
            try
            {
                using (var context = new EntityContext())
                {
                    DBEntity item = context.Entity_Competency
                                    .FirstOrDefault(s => s.EntityId == entityId &&
                                                    s.TargetNodeName == targetNodeName);

                    if (item != null && item.Id > 0)
                    {
                        MapFromDB(item, entity);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Get");
            }
            return(entity);
        }        //
        //public bool SaveList( List<ThisEntity> list, Guid parentUid, ref SaveStatus status )
        //{
        //	if ( list == null || list.Count == 0 )
        //		return true;

        //	bool isAllValid = true;
        //	foreach ( ThisEntity item in list )
        //	{
        //		Save( item, parentUid, ref status );
        //	}

        //	return isAllValid;
        //}

        public bool SaveList(List <CredentialAlignmentObjectProfile> list, Guid parentUid, ref SaveStatus status)
        {
            if (!IsValidGuid(parentUid))
            {
                status.AddError(string.Format("A valid parent identifier was not provided to the {0}.Add method.", thisClassName));
                return(false);
            }

            Entity parent = EntityManager.GetEntity(parentUid);

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

            if (list == null || list.Count == 0)
            {
                return(true);
            }
            ThisEntity entity     = new ThisEntity();
            bool       isAllValid = true;

            foreach (CredentialAlignmentObjectProfile item in list)
            {
                entity = new ThisEntity();
                MapToAlignmentObject(item, entity);
                Save(entity, parent, ref status);
            }

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

            if (profile.EducationFrameworkId < 1)
            {
                //status.AddError( thisClassName + ".ValidateProfile(). A competency identifier must be included." );
            }

            if (string.IsNullOrWhiteSpace(profile.TargetNodeName))
            {
                status.AddError(thisClassName + ".ValidateProfile(). A competency TargetNodeName must be included.");
            }
            return(!status.HasSectionErrors);
        }
        /// <summary>
        /// Add a competency
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="parentUid"></param>
        /// <param name="messages"></param>
        /// <returns></returns>
        public bool Save(ThisEntity entity,
                         Entity parent,
                         ref SaveStatus status)
        {
            bool isValid = true;
            int  count   = 0;

            DBEntity efEntity = new DBEntity();

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

                if (entity.Id == 0)
                {
                    //check if already exists
                    //TODO - will need to add alignment type
                    ThisEntity item = Get(parent.Id, entity.TargetNodeName);
                    if (entity != null && entity.Id > 0)
                    {
                        status.AddWarning(thisClassName + string.Format("Save(). Error: the selected competency {0} already exists!", entity.TargetNodeName));
                        return(false);
                    }
                    //add
                    efEntity          = new DBEntity();
                    efEntity.EntityId = parent.Id;

                    if (entity.EducationFrameworkId > 0)
                    {
                        efEntity.EducationFrameworkId = entity.EducationFrameworkId;
                    }
                    else
                    {
                        efEntity.EducationFrameworkId = null;
                    }

                    efEntity.FrameworkName = entity.FrameworkName;
                    efEntity.FrameworkUrl  = entity.FrameworkUrl;

                    efEntity.TargetNodeName        = entity.TargetNodeName;
                    efEntity.TargetNodeDescription = entity.TargetNodeDescription;
                    efEntity.TargetNode            = entity.TargetNode;
                    efEntity.CodedNotation         = entity.CodedNotation;
                    efEntity.Weight = entity.Weight;

                    efEntity.Created = DateTime.Now;

                    context.Entity_Competency.Add(efEntity);
                    count = context.SaveChanges();

                    //update profile record so doesn't get deleted
                    entity.Id = efEntity.Id;

                    if (count == 0)
                    {
                        status.AddWarning(string.Format(" Unable to add Competency: {0} <br\\> ", string.IsNullOrWhiteSpace(entity.TargetNodeName) ? "no description" : entity.TargetNodeName));
                    }
                }
                else
                {
                    //no update possible at this time
                    entity.EntityId = parent.Id;

                    efEntity = context.Entity_Competency.SingleOrDefault(s => s.Id == entity.Id);
                    if (efEntity != null && efEntity.Id > 0)
                    {
                        //update
                        if (entity.EducationFrameworkId > 0)
                        {
                            efEntity.EducationFrameworkId = entity.EducationFrameworkId;
                        }
                        else
                        {
                            efEntity.EducationFrameworkId = null;
                        }

                        efEntity.FrameworkName = entity.FrameworkName;
                        efEntity.FrameworkUrl  = entity.FrameworkUrl;


                        efEntity.TargetNodeName        = entity.TargetNodeName;
                        efEntity.TargetNodeDescription = entity.TargetNodeDescription;
                        efEntity.TargetNode            = entity.TargetNode;
                        efEntity.CodedNotation         = entity.CodedNotation;
                        efEntity.Weight = entity.Weight;

                        //has changed?
                        if (HasStateChanged(context))
                        {
                            count = context.SaveChanges();
                        }
                    }
                }
            }

            return(isValid);
        }
        public static void MapToAlignmentObject(CredentialAlignmentObjectProfile from, ThisEntity to)
        {
            if (IsValidDate(from.Created))
            {
                to.Created = ( DateTime )from.Created;
            }
            //
            to.FrameworkName = from.FrameworkName;
            //add url?? to Entity for now?
            //this should not be used from Entity.Competency, rather get from EducationFramework
            //****unless it is possible to not have these?
            if (!string.IsNullOrWhiteSpace(from.FrameworkUri))
            {
                to.FrameworkUrl = from.FrameworkUri;
            }
            else
            {
                to.FrameworkUrl = from.SourceUrl;
            }
            //todo - latter has value, lookup frameworkId
            to.EducationFrameworkId = new EducationFrameworkManager().Lookup_OR_Add(to.FrameworkUrl, to.FrameworkName);

            to.TargetNode            = from.TargetNode;
            to.TargetNodeDescription = from.TargetNodeDescription;
            to.TargetNodeName        = from.TargetNodeName;
            if (to.TargetNodeDescription == to.TargetNodeName)
            {
                to.TargetNodeDescription = "";
            }

            //to.Weight = GetDecimalField(from.Weight);
            to.Weight        = from.Weight;
            to.CodedNotation = from.CodedNotation;
        }