/// <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); }
private bool ValidateProfile(PathwayComponent profile, ref SaveStatus status) { status.HasSectionErrors = false; if (string.IsNullOrWhiteSpace(profile.Name)) { status.AddError(string.Format("Error: A PathwayComponent Name is required. CTID: {0}, Component: {1}", profile.CTID ?? "none?", profile.ComponentTypeId)); } //if ( string.IsNullOrWhiteSpace( profile.Description ) ) //{ // status.AddError( "Error: A PathwayComponent Description is required." ); //} return(status.WasSectionValid); }
/// <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); }
/// <summary> /// Get a basic PathwayComponent by CTID /// </summary> /// <param name="ctid"></param> /// <returns></returns> public static ThisEntity GetByCtid(string ctid, int childComponentsAction = 1) { PathwayComponent entity = new PathwayComponent(); if (string.IsNullOrWhiteSpace(ctid)) { return(entity); } using (var context = new EntityContext()) { context.Configuration.LazyLoadingEnabled = false; EM.PathwayComponent item = context.PathwayComponent .FirstOrDefault(s => s.CTID.ToLower() == ctid.ToLower() ); if (item != null && item.Id > 0) { MapFromDB(item, entity, childComponentsAction); } } return(entity); }