} // public static ThisEntity GetByCtid(string ctid) { ThisEntity entity = new ThisEntity(); if (string.IsNullOrWhiteSpace(ctid)) { return(entity); } try { using (var context = new EntityContext()) { //lookup by frameworkUri, or SourceUrl DBEntity item = context.CompetencyFramework .FirstOrDefault(s => s.CTID.ToLower() == ctid.ToLower()); if (item != null && item.Id > 0) { MapFromDB(item, entity); } } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".GetByUrl"); } return(entity); } //
public bool AddLanguage(string textValue, int entityId, ref SaveStatus status, int categoryId) { if (string.IsNullOrWhiteSpace(textValue)) { return(true); } using (var context = new EntityContext()) { EnumeratedItem code = new EnumeratedItem(); code = CodesManager.GetLanguage(textValue); if (code.Id > 0) { textValue = string.Format("{0} ({1})", code.Name, code.Value); AddTextValue(textValue, entityId, ref status, categoryId); } else { status.AddWarning(thisClassName + string.Format(". Warning - the langugage code was not found. parentUid: {0}, languagecode: {1}", entityId, textValue)); } } return(true); }
/// <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.CompetencyFramework .SingleOrDefault(s => s.Id == profileId); if (item != null && item.Id > 0) { MapFromDB(item, entity); } } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".Get"); } return(entity); } //
public static int FrameworkCount_ForOwningOrg(string orgCtid) { int totalRecords = 0; if (string.IsNullOrWhiteSpace(orgCtid) || orgCtid.Trim().Length != 39) { return(totalRecords); } using (var context = new EntityContext()) { var query = (from entity in context.CompetencyFramework join org in context.Organization on entity.OrganizationCTID equals org.CTID where entity.OrganizationCTID.ToLower() == orgCtid.ToLower() && org.EntityStateId > 1 && entity.EntityStateId == 3 select new { entity.CTID }); //until ed frameworks is cleaned up, need to prevent dups != 39 var results = query.Select(s => s.CTID).Distinct() .ToList(); if (results != null && results.Count > 0) { totalRecords = results.Count(); } } return(totalRecords); }
/// <summary> /// Delete record /// Need to also delete the related Entity /// </summary> /// <param name="Id"></param> /// <param name="statusMessage"></param> /// <returns></returns> public bool Delete(int id, ref string statusMessage) { bool isValid = false; if (id == 0) { statusMessage = "Error - missing an identifier for the Pathway_ComponentCondition"; return(false); } using (var context = new EntityContext()) { var efEntity = context.Pathway_ComponentCondition .SingleOrDefault(s => s.Id == id); if (efEntity != null && efEntity.Id > 0) { //delete the relate Entity //20-06-03 N/A added an after delete trigger //new EntityManager().Delete( efEntity.RowId, ref statusMessage ); //now remove context.Pathway_ComponentCondition.Remove(efEntity); int count = context.SaveChanges(); if (count > 0) { isValid = true; } } else { statusMessage = "Error - delete failed, as record was not found."; } } return(isValid); }
public static List <CostManifest> GetAllManifestInCommonCostsFor(int CostManifestId, int CostManifestBeingCheckedId) { List <CostManifest> list = new List <CostManifest>(); try { using (var context = new EntityContext()) { List <DBEntity> results = context.Entity_CommonCost .Where(s => s.CostManifestId == CostManifestId) .OrderBy(s => s.EntityId) .ToList(); if (results != null && results.Count > 0) { foreach (DBEntity item in results) { if (item.Entity.EntityBaseId == CostManifestBeingCheckedId) { } } } return(list); } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".GetAllManifestInCommonCostsFor"); } return(list); }
/// <summary> /// Delete all records that are not in the provided list. /// This method is typically called from bulk upload, and want to remove any records not in the current list to upload. /// </summary> /// <param name="parentUid"></param> /// <param name="list"></param> /// <param name="messages"></param> /// <returns></returns> public bool DeleteNotInList(Guid parentUid, List <PathwayComponent> list, ref SaveStatus status) { bool isValid = true; if (!list.Any()) { return(true); } Entity parent = EntityManager.GetEntity(parentUid); if (parent == null || parent.Id == 0) { status.AddError(thisClassName + string.Format(".DeleteNotInList() Error - the parent entity for [{0}] was not found.", parentUid)); return(false); } using (var context = new EntityContext()) { var existing = context.Entity_HasPathwayComponent.Where(s => s.EntityId == parent.Id).ToList(); var inputIds = list.Select(x => x.Id).ToList(); //delete records which are not selected var notExisting = existing.Where(x => !inputIds.Contains(x.PathwayComponentId)).ToList(); foreach (var item in notExisting) { context.Entity_HasPathwayComponent.Remove(item); context.SaveChanges(); } } return(isValid); }
public bool DeleteAll(Entity parent, ref SaveStatus status) { bool isValid = true; //Entity parent = EntityManager.GetEntity( parentUid ); if (parent == null || parent.Id == 0) { status.AddError(thisClassName + ". Error - the provided target parent entity was not provided."); return(false); } using (var context = new EntityContext()) { context.Entity_ContactPoint.RemoveRange(context.Entity_ContactPoint.Where(s => s.ParentEntityId == parent.Id)); int count = context.SaveChanges(); if (count > 0) { isValid = true; } else { //if doing a delete on spec, may not have been any properties } } return(isValid); }
public static Enumeration GetAgentToAgentRolesCodes(bool isInverseRole = true) { Enumeration entity = new Enumeration(); using (var context = new EntityContext()) { EM.Tables.Codes_PropertyCategory category = context.Codes_PropertyCategory .SingleOrDefault(s => s.Id == CodesManager.PROPERTY_CATEGORY_CREDENTIAL_AGENT_ROLE); if (category != null && category.Id > 0) { entity.Id = category.Id; entity.Name = category.Title; entity.SchemaName = category.SchemaName; entity.Url = category.SchemaUrl; entity.Items = new List <EnumeratedItem>(); EnumeratedItem val = new EnumeratedItem(); var Query = from P in context.Codes_CredentialAgentRelationship .Where(s => s.IsActive == true && s.IsAgentToAgentRole == true) select P; Query = Query.OrderBy(p => p.Title); var results = Query.ToList(); foreach (EM.Tables.Codes_CredentialAgentRelationship item in results) { val = new EnumeratedItem(); val.Id = item.Id; val.CodeId = item.Id; val.Value = item.Id.ToString();//???? val.Description = item.Description; if (isInverseRole) { val.Name = item.ReverseRelation; } else { val.Name = item.Title; } if ((bool)item.IsQARole) { val.IsQAValue = true; if (IsDevEnv()) { val.Name += " (QA)"; } } entity.Items.Add(val); } } } return(entity); }
/// <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); }
/// <summary> /// Format a summary of the EarningsProfile for use in search and gray boxes /// </summary> /// <param name="parentUid"></param> /// <returns></returns> public static string GetSummary(Guid parentUid) { var list = new List <EarningsProfile>(); var entity = new EarningsProfile(); Entity parent = EntityManager.GetEntity(parentUid); LoggingHelper.DoTrace(7, string.Format(thisClassName + ".GetAll: parentUid:{0} entityId:{1}, e.EntityTypeId:{2}", parentUid, parent.Id, parent.EntityTypeId)); var summary = ""; var lineBreak = ""; try { using (var context = new EntityContext()) { List <DBEntity> results = context.Entity_EarningsProfile .Where(s => s.EntityId == parent.Id) .OrderBy(s => s.Created) .ToList(); if (results != null && results.Count > 0) { foreach (DBEntity item in results) { entity = new EarningsProfile(); if (item.EarningsProfile != null && item.EarningsProfile.EntityStateId > 1) { if (!string.IsNullOrWhiteSpace(item.EarningsProfile.Name)) { summary = item.EarningsProfile.Name + lineBreak; } else if (!string.IsNullOrWhiteSpace(item.EarningsProfile.Description)) { summary = item.EarningsProfile.Description.Length < 200 ? item.EarningsProfile.Description : item.EarningsProfile.Description.Substring(0, 200) + " ... " + lineBreak; } else { } if (item.EarningsProfile.MedianEarnings > 0) { summary += string.Format(" Median Earnings: {0}", item.EarningsProfile.MedianEarnings); } } lineBreak = "<\br>"; } } return(summary); } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".GetSummary"); } return(summary); }
public int AddPendingRecord(Guid entityUid, string ctid, string registryAtId, ref string status) { DBEntity efEntity = new DBEntity(); try { //var pathwayCTIDTemp = "ce-abcb5fe0-8fde-4f06-9d70-860cd5bdc763"; using (var context = new EntityContext()) { if (!IsValidGuid(entityUid)) { status = thisClassName + " - A valid GUID must be provided to create a pending entity"; return(0); } //quick check to ensure not existing ThisEntity entity = GetByCtid(ctid); if (entity != null && entity.Id > 0) { return(entity.Id); } //only add DB required properties //NOTE - an entity will be created via trigger efEntity.Name = "Placeholder until full document is downloaded"; efEntity.Description = "Placeholder until full document is downloaded"; //realitically the component should be added in the same workflow efEntity.EntityStateId = 1; efEntity.RowId = entityUid; //watch that Ctid can be updated if not provided now!! efEntity.CTID = ctid; efEntity.FrameworkUri = registryAtId; efEntity.Created = System.DateTime.Now; efEntity.LastUpdated = System.DateTime.Now; context.CompetencyFramework.Add(efEntity); int count = context.SaveChanges(); if (count > 0) { return(efEntity.Id); } status = thisClassName + " Error - the save was not successful, but no message provided. "; } } catch (Exception ex) { string message = FormatExceptions(ex); LoggingHelper.LogError(ex, thisClassName + string.Format(".AddPendingRecord. entityUid: {0}, ctid: {1}", entityUid, ctid)); status = thisClassName + " Error - the save was not successful. " + message; } return(0); }
/// <summary> /// Delete all EarningsProfiles for parent /// </summary> /// <param name="parent"></param> /// <param name="status"></param> /// <returns></returns> public bool DeleteAll(Guid parentUid, ref SaveStatus status) { bool isValid = true; int count = 0; Entity parent = EntityManager.GetEntity(parentUid); if (parent == null || parent.Id == 0) { status.AddError(thisClassName + ".DeleteAll Error - the provided target parent entity was not provided."); return(false); } if (parent == null || parent.Id == 0) { status.AddError(thisClassName + ". Error - the provided target parent entity was not provided."); return(false); } using (var context = new EntityContext()) { //check if target is a reference object and is only in use here var results = context.Entity_EarningsProfile .Where(s => s.EntityId == parent.Id) .OrderBy(s => s.Created) .ToList(); if (results == null || results.Count == 0) { return(true); } foreach (var item in results) { if (item.EarningsProfile != null && item.EarningsProfile.EntityStateId > 0) { var messages = new List <string>(); new EarningsProfileManager().Delete(item.Id, ref messages); if (messages.Any()) { status.AddErrorRange(messages); } continue; } context.Entity_EarningsProfile.Remove(item); count = context.SaveChanges(); if (count > 0) { } } } return(isValid); }
} // /// <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); } //
public bool DeleteAll(Guid parentUid, SaveStatus status) { bool isValid = true; Entity parent = EntityManager.GetEntity(parentUid); if (parent == null || parent.Id == 0) { status.AddError("Error - the parent entity was not found."); return(false); } try { using (var context = new EntityContext()) { //var results = context.Entity_HasPathwayComponent.Where( s => s.EntityId == parent.Id ).ToList(); //if ( results == null || results.Count == 0 ) // return true; //foreach ( var item in results ) //{ // string statusMessage = ""; // //we have a trigger for this // new EntityManager().Delete( item.RowId, ref statusMessage ); // context.Entity_HasPathwayComponent.Remove( item ); // int count = context.SaveChanges(); // if ( count > 0 ) // { // isValid = true; // } // else // { // //if doing a delete on spec, may not have been any properties // } //} context.Entity_HasPathwayComponent.RemoveRange(context.Entity_HasPathwayComponent.Where(s => s.EntityId == parent.Id)); int count = context.SaveChanges(); if (count > 0) { isValid = true; //status.AddError( string.Format( "removed {0} related relationships.", count ) ); } } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".DeleteAll( Guid parentUid, ref SaveStatus status )"); } return(isValid); }
}// /// <summary> /// Get All Entity_Reference records for the parent /// </summary> /// <param name="parentUid"></param> /// <param name="categoryId"></param> /// <returns></returns> public static List <ThisEntity> GetAll(Guid parentUid, int categoryId) { ThisEntity entity = new ThisEntity(); List <ThisEntity> list = new List <ThisEntity>(); List <ThisEntity> results = new List <ThisEntity>(); Entity parent = EntityManager.GetEntity(parentUid); if (parent == null || parent.Id == 0) { return(list); } try { using (var context = new EntityContext()) { List <DBEntity> search = context.Entity_Reference .Where(s => s.EntityId == parent.Id && s.CategoryId == categoryId) .OrderBy(s => s.Title).ThenBy(x => x.TextValue) .ToList(); //this appears wrong, the ToList means query not deferred??? if (categoryId == CodesManager.PROPERTY_CATEGORY_SUBJECT || categoryId == CodesManager.PROPERTY_CATEGORY_KEYWORD) { search = search.OrderBy(s => s.TextValue).ToList(); } else { search = search.OrderBy(s => s.Created).ToList(); } if (search != null && search.Count > 0) { foreach (DBEntity item in search) { entity = new ThisEntity(); MapFromDB(item, entity); list.Add(entity); } } } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".GetAllDirect"); } return(list); }//
} // public static List <Pathway> GetPathwayForComponent(int pathwayComponentId, int componentRelationshipTypeId) { /* * */ var entity = new Pathway(); var list = new List <Pathway>(); if (pathwayComponentId < 1 || componentRelationshipTypeId < 1) { return(list); } try { using (var context = new EntityContext()) { //there should be only one pathway-component for the passed relationship - typically ispartof List <DBEntity> results = context.Entity_HasPathwayComponent .Where(s => s.PathwayComponentId == pathwayComponentId && s.ComponentRelationshipTypeId == componentRelationshipTypeId && s.Entity.EntityTypeId == CodesManager.ENTITY_TYPE_PATHWAY) .OrderBy(s => s.ComponentRelationshipTypeId) .ThenBy(s => s.Entity.EntityBaseName) // .ToList(); if (results != null && results.Count > 0) { foreach (var from in results) { if (from != null && from.Id > 0) { if (from.Entity != null && from.Entity.EntityBaseId != null) { //is basic enough? entity = PathwayManager.GetBasic(( int )from.Entity.EntityBaseId); } list.Add(entity); } } } } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".GetPathwayForComponent"); } return(list); } //
public bool Delete(int id, ref List <string> messages) { bool isValid = true; if (id < 1) { messages.Add(thisClassName + ".Delete() Error - a valid Entity_EarningsProfile id must be provided."); return(false); } using (var context = new EntityContext()) { try { context.Configuration.LazyLoadingEnabled = false; DBEntity efEntity = context.Entity_EarningsProfile .FirstOrDefault(s => s.Id == id); if (efEntity != null && efEntity.Id > 0) { // context.Entity_EarningsProfile.Remove(efEntity); int count = context.SaveChanges(); if (count > 0) { isValid = true; } } else { messages.Add(thisClassName + ".Delete() Warning No action taken, as the record was not found."); } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".Delete()"); isValid = false; var statusMessage = FormatExceptions(ex); if (statusMessage.ToLower().IndexOf("the delete statement conflicted with the reference constraint") > -1) { statusMessage = "Error: this EmploymentOutcomeProfile cannot be deleted as it is being referenced by other items, such as roles or credentials. These associations must be removed before this EmploymentOutcomeProfile can be deleted."; } messages.Add(statusMessage); } } return(isValid); }
public static ThisEntity Get(int id, bool includingComponents = true) { ThisEntity entity = new ThisEntity(); using (var context = new EntityContext()) { DBEntity item = context.Pathway_ComponentCondition .SingleOrDefault(s => s.Id == id); if (item != null && item.Id > 0) { MapFromDB(item, entity, includingComponents); } } return(entity); }
/// <summary> /// Get all CostManifests for the provided entity /// The returned entities are just the basic, unless for the detail view /// </summary> /// <param name="parentUid"></param> /// <returns></returns> public static List <CostManifest> GetAll(Guid parentUid) { List <CostManifest> list = new List <CostManifest>(); if (parentUid == null) { return(list); } CostManifest entity = new CostManifest(); Entity parent = EntityManager.GetEntity(parentUid); LoggingHelper.DoTrace(7, string.Format("Entity_CommonCostManager_GetAll: parentUid:{0} entityId:{1}, e.EntityTypeId:{2}", parentUid, parent.Id, parent.EntityTypeId)); try { using (var context = new EntityContext()) { List <DBEntity> results = context.Entity_CommonCost .Where(s => s.EntityId == parent.Id) .OrderBy(s => s.CostManifestId) .ToList(); if (results != null && results.Count > 0) { foreach (DBEntity item in results) { entity = new CostManifest(); // //Need all the data for detail page - NA 6/2/2017 if (item.CostManifest != null && item.CostManifest.Id > 0 && item.CostManifest.EntityStateId > 2) { entity = CostManifestManager.Get(item.CostManifestId); list.Add(entity); } } } return(list); } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".GetAll"); } return(list); }
public bool DeleteAll(Entity parent, ref SaveStatus status) { bool isValid = true; //Entity parent = EntityManager.GetEntity( parentUid ); if (parent == null || parent.Id == 0) { status.AddError(thisClassName + ". Error - the provided target parent entity was not provided."); return(false); } using (var context = new EntityContext()) { var results = context.Entity_ContactPoint.Where(s => s.ParentEntityId == parent.Id) .ToList(); if (results == null || results.Count == 0) { return(true); } foreach (var item in results) { //21-03-31 mp - just removing the profile will not remove its entity and the latter,s children! string statusMessage = ""; new EntityManager().Delete(item.RowId, string.Format("EntityContactPointProfile: {0} for EntityType: {1} ({2})", item.Id, parent.EntityTypeId, parent.EntityBaseId), ref statusMessage); context.Entity_ContactPoint.Remove(item); var count = context.SaveChanges(); if (count > 0) { } } //context.Entity_ContactPoint.RemoveRange( context.Entity_ContactPoint.Where( s => s.ParentEntityId == parent.Id ) ); // int count = context.SaveChanges(); // if ( count > 0 ) // { // isValid = true; // } // else // { // //if doing a delete on spec, may not have been any properties // } } return(isValid); }
}// public static List <string> GetAllToList(Guid parentUid, int categoryId) { List <string> list = new List <string>(); Entity parent = EntityManager.GetEntity(parentUid); if (parent == null || parent.Id == 0) { return(list); } try { using (var context = new EntityContext()) { List <DBEntity> search = context.Entity_Reference .Where(s => s.EntityId == parent.Id && s.CategoryId == categoryId) .OrderBy(s => s.Title).ThenBy(x => x.TextValue) .ToList(); if (categoryId == CodesManager.PROPERTY_CATEGORY_SUBJECT || categoryId == CodesManager.PROPERTY_CATEGORY_KEYWORD) { search = search.OrderBy(s => s.TextValue).ToList(); } else { search = search.OrderBy(s => s.Created).ToList(); } if (search != null && search.Count > 0) { foreach (DBEntity item in search) { list.Add(item.TextValue); } } } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".GetAllToList"); } return(list); }//
/// <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); }
//public bool Delete( Guid parentUid, int profileId, ref string statusMessage ) //{ // bool isValid = false; // if ( profileId == 0 ) // { // statusMessage = "Error - missing an identifier for the Assessment to remove"; // return false; // } // //need to get Entity.Id // Entity parent = EntityManager.GetEntity( parentUid ); // if ( parent == null || parent.Id == 0 ) // { // statusMessage = "Error - the parent entity was not found."; // return false; // } // using ( var context = new EntityContext() ) // { // DBEntity efEntity = context.Entity_CommonCost // .SingleOrDefault( s => s.EntityId == parent.Id && s.CostManifestId == profileId ); // if ( efEntity != null && efEntity.Id > 0 ) // { // context.Entity_CommonCost.Remove( efEntity ); // int count = context.SaveChanges(); // if ( count > 0 ) // { // isValid = true; // } // } // else // { // statusMessage = "Warning - the record was not found - probably because the target had been previously deleted"; // isValid = true; // } // } // return isValid; //} public bool DeleteAll(Entity parent, ref SaveStatus status) { bool isValid = true; //Entity parent = EntityManager.GetEntity( parentUid ); if (parent == null || parent.Id == 0) { status.AddError(thisClassName + ". Error - the provided target parent entity was not provided."); return(false); } try { using (var context = new EntityContext()) { var results = context.Entity_CommonCost.Where(s => s.EntityId == parent.Id) .ToList(); if (results == null || results.Count == 0) { return(true); } context.Entity_CommonCost.RemoveRange(context.Entity_CommonCost.Where(s => s.EntityId == parent.Id)); int count = context.SaveChanges(); if (count > 0) { isValid = true; } else { //if doing a delete on spec, may not have been any properties } } } catch (Exception ex) { var msg = BaseFactory.FormatExceptions(ex); LoggingHelper.DoTrace(1, string.Format(thisClassName + ".DeleteAll. ParentType: {0}, baseId: {1}, exception: {2}", parent.EntityType, parent.EntityBaseId, msg)); } return(isValid); }
/// <summary> /// Get all EarningsProfile for the provided entity /// The returned entities are just the base /// </summary> /// <param name="parentUid"></param> /// <returns></returnsThisEntity public static List <EarningsProfile> GetAll(Entity parent, bool includingParts = true) { var list = new List <EarningsProfile>(); var entity = new EarningsProfile(); //Entity parent = EntityManager.GetEntity( parentUid ); //LoggingHelper.DoTrace( 7, string.Format( thisClassName + ".GetAll: parentUid:{0} entityId:{1}, e.EntityTypeId:{2}", parentUid, parent.Id, parent.EntityTypeId ) ); try { using (var context = new EntityContext()) { List <DBEntity> results = context.Entity_EarningsProfile .Where(s => s.EntityId == parent.Id) .OrderBy(s => s.Created) .ToList(); if (results != null && results.Count > 0) { foreach (DBEntity item in results) { entity = new EarningsProfile(); //need to distinguish between on a detail page for conditions and EarningsProfile detail //would usually only want basics here?? //17-05-26 mp- change to MapFromDB_Basic if (item.EarningsProfile != null && item.EarningsProfile.EntityStateId > 1) { EarningsProfileManager.MapFromDB(item.EarningsProfile, entity, includingParts); list.Add(entity); } } } return(list); } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".GetAll"); } return(list); }
public bool Delete(int recordId, ref string statusMessage) { bool isOK = true; using (var context = new EntityContext()) { DBEntity p = context.Entity_ContactPoint.FirstOrDefault(s => s.Id == recordId); if (p != null && p.Id > 0) { context.Entity_ContactPoint.Remove(p); int count = context.SaveChanges(); } else { statusMessage = string.Format("Contact Point record was not found: {0}", recordId); isOK = false; } } return(isOK); }
} // public bool Delete(Guid parentUid, int recordId, ref string statusMessage) { bool isValid = false; if (recordId == 0) { statusMessage = "Error - missing an identifier for the Entity_HasPathwayComponent to remove"; return(false); } //need to get Entity.Id Entity parent = EntityManager.GetEntity(parentUid); if (parent == null || parent.Id == 0) { statusMessage = "Error - the parent entity was not found."; return(false); } using (var context = new EntityContext()) { DBEntity efEntity = context.Entity_HasPathwayComponent .FirstOrDefault(s => s.EntityId == parent.Id && s.PathwayComponentId == recordId); if (efEntity != null && efEntity.Id > 0) { context.Entity_HasPathwayComponent.Remove(efEntity); int count = context.SaveChanges(); if (count > 0) { isValid = true; } } else { statusMessage = "Warning - the record was not found - probably because the target had been previously deleted"; isValid = true; } } return(isValid); }
public bool DeleteAll(int pathwayComponentId, SaveStatus status) { bool isValid = true; if (pathwayComponentId < 1) { status.AddError(thisClassName + ".DeleteAll. Error - A valid pathwayComponentId must be provided."); return(false); } using (var context = new EntityContext()) { context.Pathway_ComponentCondition.RemoveRange(context.Pathway_ComponentCondition.Where(s => s.ParentComponentId == pathwayComponentId)); int count = context.SaveChanges(); if (count >= 0) { isValid = true; //status.AddError( string.Format( "removed {0} related relationships.", count ) ); } } return(isValid); }
} // /// <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); } //
/// <summary> /// Get all CompetencyFrameworks for the provided entity /// The returned entities are just the base /// </summary> /// <param name="parentUid"></param> /// <returns></returnsThisEntity public static List <WPM.CompetencyFramework> GetAll(Guid parentUid) { var list = new List <WPM.CompetencyFramework>(); var entity = new WPM.CompetencyFramework(); Entity parent = EntityManager.GetEntity(parentUid); LoggingHelper.DoTrace(7, string.Format("EntityCompetencyFrameworks_GetAll: parentUid:{0} entityId:{1}, e.EntityTypeId:{2}", parentUid, parent.Id, parent.EntityTypeId)); try { using (var context = new EntityContext()) { List <DBEntity> results = context.Entity_CompetencyFramework .Where(s => s.EntityId == parent.Id) .OrderBy(s => s.CompetencyFramework.Name) .ToList(); if (results != null && results.Count > 0) { foreach (DBEntity item in results) { entity = new WPM.CompetencyFramework(); if (item.CompetencyFramework != null && item.CompetencyFramework.EntityStateId > 1) { CompetencyFrameworkManager.MapFromDB(item.CompetencyFramework, entity); list.Add(entity); } } } return(list); } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + string.Format(".EntityCompetencyFrameworks_GetAll. Guid: {0}, parentType: {1} ({2}), ", parentUid, parent.EntityType, parent.EntityBaseId)); } return(list); }