//
        #endregion

        #region ComponentRetrievals
        public static PathwayComponent GetComponentByCtid(string ctid)
        {
            PathwayComponent entity = new PathwayComponent();

            if (string.IsNullOrWhiteSpace(ctid))
            {
                return(entity);
            }

            return(PathwayComponentManager.GetByCtid(ctid));
        }
        private bool DoesComponentExist(PathwayComponent input, string pathwayCTID, ref PathwayComponent record)
        {
            bool isFound = false;

            var exists = PathwayComponentManager.GetByCtid(input.CTID);

            if (exists != null && exists.Id > 0)
            {
                record  = exists;
                isFound = true;
            }

            return(isFound);
        }
        public void HandleComponents(ThisEntity pathway, ref SaveStatus status)
        {
            try
            {
                //components
                //delete all not in current list
                new Entity_PathwayComponentManager().DeleteNotInList(pathway.CTID, pathway.HasPart, ref status);
                //

                //TBD - should we do a fresh get of the pathway with components - or clear all?
                //handle components
                foreach (var item in pathway.HasPart)
                {
                    var component = new PathwayComponent();
                    //handle each component
                    //add to pathway HasParts on conclusion (with existance checking
                    var recordExists = false;
                    if (HandlePathwayComponent(item, pathway, ref component, ref recordExists, ref status) < 1)
                    {
                        status.RecordsFailed++;
                        continue;
                    }
                    else
                    {
                        if (recordExists)
                        {
                            status.RecordsUpdated++;
                        }
                        else
                        {
                            status.RecordsAdded++;
                        }
                    }

                    //add pathway HasPart for component
                    //?do we need has part in the finder?
                    //will be useful to retrieve data for the detail page
                    epcmgr.Add(pathway.RowId, component.Id, PathwayComponent.PathwayComponentRelationship_HasPart, ref status);
                }

                //handle conditions
                var candidates = pathway.HasPart.Where(s => s.HasCondition != null && s.HasCondition.Count() > 0).ToList();
                foreach (var pc in candidates)
                {
                    foreach (var item in pc.HasCondition)
                    {
                        //get parent component
                        var component = PathwayComponentManager.GetByCtid(pc.CTID);
                        if (component == null || component.Id == 0)
                        {
                            //shouldn't happen here - although the add attempt could have failed?
                            status.AddError(string.Format("The parent pathway component: {0} for ConditionComponent: {1} was not found. This could have been due the an issue adding the component - which should have resulted in an earlier error message.", pc.Name, item.Name));
                            continue;
                        }
                        var condition = new PathwayComponentCondition();
                        //add to pathway component Entity.HasPathwayComponent on conclusion

                        if (HandleComponentCondition(item, pathway, component, ref status) < 1)
                        {
                            status.RecordsFailed++;
                            //could continue if have an id (i.e. failed after saved)?
                            continue;
                        }
                    }
                }

                //now handle relationships
                int cntr = 0;
                foreach (var item in pathway.HasPart)
                {
                    cntr++;
                    var component = PathwayComponentManager.GetByCtid(item.CTID, PathwayComponentManager.componentActionOfNone);
                    //handle each component
                    //add to pathway HasParts on conclusion (with existance checking
                    ReplacePathwayComponentRelationships(cntr, component.RowId, item.HasChildList, pathway, PathwayComponent.PathwayComponentRelationship_HasChild, "PathwayComponent.HasChild", ref status);

                    ReplacePathwayComponentRelationships(cntr, component.RowId, item.HasPrerequisiteList, pathway, PathwayComponent.PathwayComponentRelationship_Prerequiste, "PathwayComponent.Prerequisite", ref status);
                    //
                    ReplacePathwayComponentRelationships(cntr, component.RowId, item.HasPreceedsList, pathway, PathwayComponent.PathwayComponentRelationship_Preceeds, "PathwayComponent.Preceeds", ref status);
                }

                //these may have to been done after processing components
                //================ destination component
                ReplacePathwayToPathwayComponentRelationships(pathway.HasDestinationList, pathway, PathwayComponent.PathwayComponentRelationship_HasDestinationComponent, "Pathway.HasDestinationComponent", ref status);
                //
                ReplacePathwayToPathwayComponentRelationships(pathway.HasChildList, pathway, PathwayComponent.PathwayComponentRelationship_HasChild, "Pathway.HasChild", ref status);
            }
            catch (Exception ex)
            {
                LoggingHelper.DoTrace(1, string.Format(thisClassName + ".HandleComponents. Pathway: {0} ({1}) Exception encountered: {2}", pathway.Name, pathway.Id, ex.Message));
                //only fail current, and allow to continue
                status.AddError(string.Format("Exception encountered. Pathway: {0}, Message: {1}", pathway.Name, ex.Message));

                LoggingHelper.LogError(ex, string.Format(thisClassName + ".HandleComponents. Pathway: {0} ({1}) Exception encountered", pathway.Name, pathway.Id));
            }
        }