Пример #1
0
        /// <summary>
        /// Get all components for the provided entity
        /// The returned entities are just the base
        /// </summary>
        /// <param name="parentUid"></param>
        /// <returns></returns>
        public static List <PathwayComponent> GetAll(Guid parentUid, int childComponentsAction = 1)
        {
            List <PathwayComponent> list   = new List <PathwayComponent>();
            PathwayComponent        entity = new PathwayComponent();

            Entity parent = EntityManager.GetEntity(parentUid);

            LoggingHelper.DoTrace(7, string.Format("Entity_PathwayComponent_GetAll: parentUid:{0} entityId:{1}, e.EntityTypeId:{2}", parentUid, parent.Id, parent.EntityTypeId));

            /*
             * ideal order
             * - get destination component
             *	 - get all children
             *	 - children of children?
             * - get hasChild
             *	 - if different from destination component, get children
             */
            //20-08-19 - try displaying in same order as read and see what we have
            try
            {
                using (var context = new EntityContext())
                {
                    List <DBEntity> results = context.Entity_HasPathwayComponent
                                              .Where(s => s.EntityId == parent.Id)
                                              .OrderBy(s => s.Created)
                                              //.OrderBy( s => s.ComponentRelationshipTypeId )
                                              .ThenBy(s => s.PathwayComponent.Name)
                                              .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (DBEntity item in results)
                        {
                            //actually the relationship type is not applicable in the component
                            entity = new PathwayComponent()
                            {
                                ComponentRelationshipTypeId = item.ComponentRelationshipTypeId
                            };
                            //not sure if we will have variances in what is returned
                            PathwayComponentManager.MapFromDB(item.PathwayComponent, entity, childComponentsAction);
                            int index = list.FindIndex(a => a.CTID == entity.CTID);
                            //20-07-27 shouldn't we be doing an exists here
                            //if ( index == -1 )
                            //{
                            list.Add(entity);
                            //}
                        }
                    }
                    return(list);
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Entity_PathwayComponent_GetAll");
            }
            return(list);
        }
Пример #2
0
        }        //

        /// <summary>
        /// Or just get all and let caller sort the data
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public static List <ThisEntity> GetAll(int parentId, int childComponentsAction = 1)
        {
            var entity = new ThisEntity();
            var list   = new List <ThisEntity>();

            if (parentId < 1)
            {
                return(list);
            }
            try
            {
                using (var context = new EntityContext())
                {
                    //there could be multiple relationships for a parent and component
                    List <DBEntity> results = context.Entity_HasPathwayComponent
                                              .Where(s => s.EntityId == parentId)
                                              .OrderBy(s => s.ComponentRelationshipTypeId)
                                              .ThenBy(s => s.PathwayComponent.Name)     //
                                              .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (var from in results)
                        {
                            if (from != null && from.Id > 0)
                            {
                                entity.Id                          = from.Id;
                                entity.EntityId                    = from.EntityId;
                                entity.PathwayComponentId          = from.PathwayComponentId;
                                entity.ComponentRelationshipTypeId = from.ComponentRelationshipTypeId;
                                if (IsValidDate(from.Created))
                                {
                                    entity.Created = ( DateTime )from.Created;
                                }

                                entity.PathwayComponentName = from.PathwayComponent.Name;
                                //to.Credential = from.Credential;
                                entity.PathwayComponent = new PathwayComponent();
                                PathwayComponentManager.MapFromDB(from.PathwayComponent, entity.PathwayComponent, childComponentsAction);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".GetAll");
            }
            return(list);
        }        //
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parentUid"></param>
        /// <param name="componentRelationshipTypeId"></param>
        /// <param name="childComponentsAction">0-none; 1-summary; 2-deep </param>
        /// <returns></returns>
        public static List <PathwayComponent> GetAll(Guid parentUid, int componentRelationshipTypeId, int childComponentsAction = 1)
        {
            List <PathwayComponent> list   = new List <PathwayComponent>();
            PathwayComponent        entity = new PathwayComponent();

            Entity parent = EntityManager.GetEntity(parentUid);

            LoggingHelper.DoTrace(7, string.Format("Entity_PathwayComponent_GetAll: parentUid:{0} entityId:{1}, e.EntityTypeId:{2}, componentRelationshipTypeId: {3}", parentUid, parent.Id, parent.EntityTypeId, componentRelationshipTypeId));

            try
            {
                using (var context = new EntityContext())
                {
                    List <DBEntity> results = context.Entity_HasPathwayComponent
                                              .Where(s => s.EntityId == parent.Id && s.ComponentRelationshipTypeId == componentRelationshipTypeId)
                                              .OrderBy(s => s.Created)
                                              .ThenBy(s => s.PathwayComponent.Name)             //not sure
                                              .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (DBEntity item in results)
                        {
                            //actually the relationship type is not applicable in the component
                            entity = new PathwayComponent()
                            {
                                ComponentRelationshipTypeId = item.ComponentRelationshipTypeId
                            };
                            //not sure if we will have variances in what is returned
                            PathwayComponentManager.MapFromDB(item.PathwayComponent, entity, childComponentsAction);
                            list.Add(entity);
                        }
                    }
                    return(list);
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Entity_PathwayComponent_GetAll");
            }
            return(list);
        }
Пример #4
0
        }        //

        /// <summary>
        /// May not have a direct get. If we do, will likely need to include ComponentRelationshipTypeId
        /// </summary>
        /// <param name="parentId"></param>
        /// <param name="pathwayComponentId"></param>
        /// <returns></returns>
        public static ThisEntity Get(int parentId, int pathwayComponentId, int childComponentsAction = 1)
        {
            ThisEntity entity = new ThisEntity();

            if (parentId < 1 || pathwayComponentId < 1)
            {
                return(entity);
            }
            try
            {
                using (var context = new EntityContext())
                {
                    //there could be multiple relationships for a parent and component
                    var from = context.Entity_HasPathwayComponent
                               .FirstOrDefault(s => s.PathwayComponentId == pathwayComponentId && s.EntityId == parentId);

                    if (from != null && from.Id > 0)
                    {
                        entity.Id                          = from.Id;
                        entity.EntityId                    = from.EntityId;
                        entity.PathwayComponentId          = from.PathwayComponentId;
                        entity.ComponentRelationshipTypeId = from.ComponentRelationshipTypeId;
                        if (IsValidDate(from.Created))
                        {
                            entity.Created = ( DateTime )from.Created;
                        }

                        entity.PathwayComponentName = from.PathwayComponent.Name;
                        //to.Credential = from.Credential;
                        entity.PathwayComponent = new PathwayComponent();
                        PathwayComponentManager.MapFromDB(from.PathwayComponent, entity.PathwayComponent, childComponentsAction);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Get");
            }
            return(entity);
        }        //