コード例 #1
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);
        }        //
コード例 #2
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);
        }        //