public bool NaicsSaveList(int parentEntityId, int categoryId, List <string> list, ref SaveStatus status) { if (list == null || list.Count == 0) { return(true); } bool isAllValid = true; CredentialAlignmentObjectProfile item = new CredentialAlignmentObjectProfile(); foreach (string naics in list) { item = new CredentialAlignmentObjectProfile(); //look up NAICS CodeItem record = CodesManager.Naics_Get(naics); if (record != null && record.Id > 0) { item.Id = record.Id; item.TargetNodeName = record.Title; item.CodedNotation = record.Code; item.TargetNode = record.URL; Add(parentEntityId, categoryId, item, ref status, false); } } return(isAllValid); }
public static void MapToAlignmentObject(CredentialAlignmentObjectProfile from, ThisEntity to) { if (IsValidDate(from.Created)) { to.Created = ( DateTime )from.Created; } // to.FrameworkName = from.FrameworkName; //add url?? to Entity for now? //this should not be used from Entity.Competency, rather get from EducationFramework //****unless it is possible to not have these? if (!string.IsNullOrWhiteSpace(from.FrameworkUri)) { to.FrameworkUrl = from.FrameworkUri; } else { to.FrameworkUrl = from.SourceUrl; } //todo - latter has value, lookup frameworkId to.EducationFrameworkId = new EducationFrameworkManager().Lookup_OR_Add(to.FrameworkUrl, to.FrameworkName); to.TargetNode = from.TargetNode; to.TargetNodeDescription = from.TargetNodeDescription; to.TargetNodeName = from.TargetNodeName; if (to.TargetNodeDescription == to.TargetNodeName) { to.TargetNodeDescription = ""; } //to.Weight = GetDecimalField(from.Weight); to.Weight = from.Weight; to.CodedNotation = from.CodedNotation; }
public bool OnetSaveList(int parentEntityId, int categoryId, List <string> list, ref SaveStatus status) { if (list == null || list.Count == 0) { return(true); } bool isAllValid = true; CredentialAlignmentObjectProfile item = new CredentialAlignmentObjectProfile(); foreach (string code in list) { item = new CredentialAlignmentObjectProfile(); //look up SOC var records = CodesManager.SOC_Get(code); foreach (var record in records) { if (record != null && record.Id > 0) { item.Id = record.Id; item.TargetNodeName = record.Title; item.Description = record.Description; item.CodedNotation = record.Code; item.TargetNode = record.URL; Add(parentEntityId, categoryId, item, ref status, false); } } } return(isAllValid); }
//public bool OnetSaveList( int parentEntityId, int categoryId, List<string> list, ref SaveStatus status ) //{ // if ( list == null || list.Count == 0 ) // return true; // bool isAllValid = true; // CredentialAlignmentObjectProfile item = new CredentialAlignmentObjectProfile(); // foreach ( string code in list ) // { // item = new CredentialAlignmentObjectProfile(); // //look up SOC // var records = CodesManager.SOC_Get( code ); // foreach ( var record in records ) // { // if ( record != null && record.Id > 0 ) // { // item.Id = record.Id; // item.TargetNodeName = record.Title; // item.Description = record.Description; // item.CodedNotation = record.Code; // item.TargetNode = record.URL; // Add( parentEntityId, categoryId, item, ref status, false ); // } // } // } // return isAllValid; //} //public bool CIPSaveList( int parentEntityId, int categoryId, List<string> list, ref SaveStatus status ) //{ // if ( list == null || list.Count == 0 ) // return true; // bool isAllValid = true; // CredentialAlignmentObjectProfile item = new CredentialAlignmentObjectProfile(); // foreach ( string code in list ) // { // item = new CredentialAlignmentObjectProfile(); // //look up SOC // var records = CodesManager.SOC_Get( code ); // foreach ( var record in records ) // { // if ( record != null && record.Id > 0 ) // { // item.Id = record.Id; // item.TargetNodeName = record.Title; // item.Description = record.Description; // item.CodedNotation = record.Code; // item.TargetNode = record.URL; // Add( parentEntityId, categoryId, item, ref status, false ); // } // } // } // return isAllValid; //} /// <summary> /// Add a Entity framework Item /// </summary> /// <param name="parentEntityId"></param> /// <param name="categoryId"></param> /// <param name="entity"></param> /// <param name="status"></param> /// <returns></returns> public int Add(int parentEntityId, int categoryId, CredentialAlignmentObjectProfile entity, ref SaveStatus status, bool warningOnDuplicates) { DBEntity efEntity = new DBEntity(); using (var context = new EntityContext()) { try { //first ensure not a duplicate (until interface/search prevents dups) //EnumeratedItem entity = Get( parentEntityId, categoryId, codeID ); //if ( entity != null && entity.Id > 0 ) //{ // status.AddWarning( "Warning: the selected code already exists!" ); // return 0; //} ReferenceFramework rf = new ReferenceFramework() { CategoryId = categoryId, CodedNotation = entity.CodedNotation, Name = entity.TargetNodeName, Description = entity.Description, TargetNode = entity.TargetNode }; //add or update, returns rfm.Id if OK if (!rfm.Save(rf, ref status)) { return(0); } //check if a duplicate if (Exists(parentEntityId, rf.Id)) { if (warningOnDuplicates) { status.AddWarning(string.Format("Warning - Duplicate encountered for categoryId: {0}, entityId: {1}, Name: {2}, ReferenceId: {3}, CodedNotation: {4}", categoryId, parentEntityId, entity.TargetNodeName, rf.Id, rf.CodedNotation)); } return(0); } //save efEntity.EntityId = parentEntityId; efEntity.CategoryId = categoryId; efEntity.ReferenceFrameworkId = rf.Id; efEntity.Created = System.DateTime.Now; context.Entity_ReferenceFramework.Add(efEntity); // submit the change to database int count = context.SaveChanges(); if (count > 0) { return(efEntity.Id); } else { string message = string.Format(thisClassName + ".Add Failed", "Attempted to add a Entity_ReferenceFramework item. The process appeared to not work, but was not an exception, so we have no message, or no clue. parentId: {0}, CategoryId: {1}, Name: {2}, ReferenceId: {3}, CodedNotation: {4}", parentEntityId, categoryId, entity.TargetNodeName, rf.Id, rf.CodedNotation); //?no info on error status.AddWarning(thisClassName + "Error - the add was not successful. \r\n" + message); //EmailManager.NotifyAdmin( thisClassName + ".ItemAdd Failed", message ); } } catch (Exception ex) { string message = FormatExceptions(ex); LoggingHelper.LogError(ex, thisClassName + string.Format(".Add(), parentId: {0}, CategoryId: {1}, Name: {2}, CodedNotation: {3}", parentEntityId, categoryId, entity.TargetNodeName, entity.CodedNotation)); status.AddError(thisClassName + ".Add() - Error - the save was not successful. \r\n" + message); } } return(efEntity.Id); }
} // public static void MapFromDB(Views.EntityCompetencyFramework_Items_Summary from, CredentialAlignmentObjectProfile to) { to.Id = from.EntityCompetencyId; to.ParentId = from.EntityId; //to.CompetencyFrameworkId = from.CompetencyFrameworkId ?? 0; to.FrameworkName = from.FrameworkName; //add url?? to Entity for now? //don't populate if for registry //18-06-28 mparsons - aim to make FrameworkUrl obsolete! // - SourceUrl should be populated //if ( from.FrameworkUrl.ToLower().IndexOf("credentialengineregistry.org/resources/ce-") == -1 ) //{ // to.FrameworkUrl = from.FrameworkUrl; //} //else if ( !string.IsNullOrWhiteSpace(from.SourceUrl) ) // to.FrameworkUrl = from.SourceUrl; // to.SourceUrl = from.SourceUrl; to.FrameworkUri = from.FrameworkUri; to.FrameworkCtid = from.FrameworkCtid; // to.TargetNode = from.TargetNode; to.TargetNodeDescription = from.TargetNodeDescription; to.TargetNodeName = from.Competency; to.Weight = (from.Weight ?? 0M); to.CodedNotation = from.CodedNotation; if (IsValidDate(from.Created)) { to.Created = ( DateTime )from.Created; } }
} // /// <summary> /// May be workaround, may be permanent, getting combined /// </summary> /// <param name="parentUid"></param> /// <param name="alignmentType"></param> /// <returns></returns> public static List <CredentialAlignmentObjectProfile> GetAllAs_CredentialAlignmentObjectProfile(Guid parentUid, ref Dictionary <string, RegistryImport> frameworksList) { CredentialAlignmentObjectProfile entity = new CredentialAlignmentObjectProfile(); List <CredentialAlignmentObjectProfile> list = new List <CredentialAlignmentObjectProfile>(); //var frameworksList = new Dictionary<string, RegistryImport>(); string prevFramework = ""; Entity parent = EntityManager.GetEntity(parentUid); if (parent == null || parent.Id == 0) { return(list); } try { using (var context = new ViewContext()) { /* * List<DBEntity> results = context.Entity_Competency * .Where( s => s.EntityId == parent.Id * ) * .OrderBy( s => s.CompetencyFramework ) * .ThenBy( s => s.TargetNodeName ) * .ToList(); * if ( results != null && results.Count > 0 ) * { * foreach ( DBEntity item in results ) * { * entity = new CredentialAlignmentObjectProfile(); * MapFromDB( item, entity ); * list.Add( entity ); * } * } */ List <Views.EntityCompetencyFramework_Items_Summary> results = context.EntityCompetencyFramework_Items_Summary .Where(s => s.EntityId == parent.Id ) .OrderBy(s => s.FrameworkName) .ThenBy(s => s.Competency) .ToList(); if (results != null && results.Count > 0) { foreach (var item in results) { entity = new CredentialAlignmentObjectProfile(); MapFromDB(item, entity); if (prevFramework != entity.FrameworkName) { if (!string.IsNullOrWhiteSpace(entity.FrameworkCtid)) { //var fw = new Dictionary<string, RegistryImport>(); RegistryImport ri = ImportManager.GetByCtid(entity.FrameworkCtid); if (frameworksList.ContainsKey(entity.FrameworkName) == false) { frameworksList.Add(entity.FrameworkName, ri); } } prevFramework = entity.FrameworkName; } list.Add(entity); } } } } catch (Exception ex) { LoggingHelper.LogError(ex, thisClassName + ".GetAllAs_CredentialAlignmentObjectProfile"); } return(list); } //