public static List <object> Autocomplete(string keyword = "", int maxTerms = 25, int widgetId = 0) { int userId = 0; string where = ""; int totalRows = 0; AppUser user = AccountServices.GetCurrentUser(); if (user != null && user.Id > 0) { userId = user.Id; } //SetAuthorizationFilter( user, ref where ); if (UtilityManager.GetAppKeyValue("usingElasticOrganizationSearch", false)) { return(ElasticHelper.OrganizationAutoComplete(keyword, maxTerms, ref totalRows)); } else { SetKeywordFilter(keyword, true, ref where); //string keywords = ServiceHelper.HandleApostrophes( keyword ); //if ( keywords.IndexOf( "%" ) == -1 ) // keywords = "%" + keywords.Trim() + "%"; //where = string.Format( " (base.name like '{0}') ", keywords ); return(EntityMgr.Autocomplete(where, 1, maxTerms, userId, ref totalRows)); } }
/// <summary> /// Main search /// </summary> /// <param name="data"></param> /// <param name="pTotalRows"></param> /// <returns></returns> public static List <OrganizationSummary> DoSearch(MainSearchInput data, ref int pTotalRows) { string where = ""; int userId = 0; AppUser user = AccountServices.GetCurrentUser(); if (user != null && user.Id > 0) { userId = user.Id; } //only target full entities where = " ( base.EntityStateId = 3 ) "; SetKeywordFilter(data.Keywords, true, ref where); //SetAuthorizationFilter( user, ref where ); SearchServices.HandleCustomFilters(data, 59, ref where); SetPropertiesFilter(data, ref where); SearchServices.SetRolesFilter(data, ref where); SetBoundariesFilter(data, ref where); SetFrameworksFilter(data, ref where); SetOrgServicesFilter(data, ref where); //check for org category (credentially, or QA). Only valid if one item //SetOrgCategoryFilter( data, ref where ); //Not updated - I'm not sure we're still using this. - NA 5/12/2017 LoggingHelper.DoTrace(5, thisClassName + ".Search(). Filter: " + where); return(EntityMgr.MainSearch(where, data.SortOrder, data.StartPage, data.PageSize, ref pTotalRows)); }
public bool Save(Widget item, ref List <string> messages) { AppUser user = AccountServices.GetCurrentUser(); if (user == null || user.Id == 0) { messages.Add(string.Format("You must be logged in to: '{0}'.", "Save a widget")); return(false); } if (!AccountServices.IsUserSiteStaff(user)) { //check if user is part of organization related to widget var exists = user.Organizations.FirstOrDefault(a => a.CTID.ToLower() == item.OrgCTID.ToLower()); if (exists == null || string.IsNullOrWhiteSpace(exists.CTID)) { messages.Add(string.Format("You are not associated with the organization for this widget: {0}.", item.OrganizationName)); return(false); } } if (!mgr.Save(item, user.Id, ref messages)) { //message handling, or leave to caller return(false); } return(true); }
public static List <CM.Organization> MicroSearch(MicroSearchInputV2 query, int pageNumber, int pageSize, ref int pTotalRows) { string pOrderBy = ""; string filter = ""; int userId = 0; string keywords = query.GetFilterValueString("Keywords"); string orgMbrs = query.GetFilterValueString("OrgFilters"); //user is used to determine if can edit results AppUser user = new AppUser(); user = AccountServices.GetCurrentUser(); if (user != null && user.Id > 0) { userId = user.Id; } //this is an option on micro searches to only target orgs associated to the user //if ( orgMbrs == "myOrgs" ) // SetAuthorizationFilter( user, ref filter, true, true ); //else // SetAuthorizationFilter( user, ref filter, true, false ); SetKeywordFilter(keywords, true, ref filter); return(Mgr.Search(filter, pOrderBy, pageNumber, pageSize, ref pTotalRows)); }
public static List <ThisEntity> DoSearch(MainSearchInput data, ref int totalRows) { string where = ""; List <string> competencies = new List <string>(); int userId = 0; AppUser user = AccountServices.GetCurrentUser(); if (user != null && user.Id > 0) { userId = user.Id; } //only target full entities where = " ( base.EntityStateId = 3 ) "; SetKeywordFilter(data.Keywords, false, ref where); SearchServices.SetSubjectsFilter(data, CodesManager.ENTITY_TYPE_ASSESSMENT_PROFILE, ref where); SearchServices.HandleCustomFilters(data, 60, ref where); SetPropertiesFilter(data, ref where); SearchServices.SetRolesFilter(data, ref where); SearchServices.SetBoundariesFilter(data, ref where); //CIP SetFrameworksFilter(data, ref where); //Competencies SetCompetenciesFilter(data, ref where, ref competencies); LoggingHelper.DoTrace(5, "AssessmentServices.Search(). Filter: " + where); return(EntityMgr.Search(where, data.SortOrder, data.StartPage, data.PageSize, ref totalRows)); }
/// <summary> /// Credential autocomplete /// Needs to check authorization level for credential /// </summary> /// <param name="keyword"></param> /// <param name="maxTerms"></param> /// <returns></returns> public static List <object> Autocomplete(string keyword, int maxTerms = 25) { int userId = 0; string where = ""; int pTotalRows = 0; AppUser user = AccountServices.GetCurrentUser(); if (user != null && user.Id > 0) { userId = user.Id; } SetAuthorizationFilter(user, ref where); SetKeywordFilter(keyword, true, ref where); if (UtilityManager.GetAppKeyValue("usingElasticCredentialSearch", false)) { return(ElasticServices.CredentialAutoComplete(keyword, maxTerms, ref pTotalRows)); } else { return(CredentialManager.Autocomplete(where, 1, maxTerms, ref pTotalRows)); } // return new List<string>(); }
public bool Delete(int id, ref string message) { bool isValid = true; AppUser user = AccountServices.GetCurrentUser(); if (user == null || user.Id == 0) { message = string.Format("You must be logged in to: '{0}'.", "Delete a widget"); } isValid = mgr.Delete(id, ref message); return(isValid); }
/// <summary> /// Credential autocomplete /// Needs to check authorization level for credential /// </summary> /// <param name="keyword"></param> /// <param name="maxTerms"></param> /// <returns></returns> public static List <object> Autocomplete(string keywords, int maxTerms = 25) { int userId = 0; string where = " base.EntityStateId = 3 "; string AND = ""; int pTotalRows = 0; AppUser user = AccountServices.GetCurrentUser(); if (user != null && user.Id > 0) { userId = user.Id; } if (UtilityManager.GetAppKeyValue("usingElasticCredentialAutocomplete", false)) { return(ElasticHelper.CredentialAutoComplete(keywords, maxTerms, ref pTotalRows)); } else { bool usingLinqAutocomplete = true; if (usingLinqAutocomplete) { return(CredentialManager.AutocompleteInternal(keywords, 1, maxTerms, ref pTotalRows)); } else { string text = " (base.name like '{0}' OR base.AlternateName like '{0}' OR OwningOrganization like '{0}' ) "; //SetKeywordFilter( keywords, true, ref where ); keywords = ServiceHelper.HandleApostrophes(keywords); if (keywords.IndexOf("%") == -1) { keywords = SearchServices.SearchifyWord(keywords); } if (where.Length > 0) { AND = " AND "; } where = where + AND + string.Format(" ( " + text + " ) ", keywords); return(CredentialManager.AutocompleteDB(where, 1, maxTerms, ref pTotalRows)); } // return new List<string>(); } }
public static List <string> AutocompleteCompetencies(string keyword, int maxTerms = 25) { int userId = 0; string where = ""; AppUser user = AccountServices.GetCurrentUser(); if (user != null && user.Id > 0) { userId = user.Id; } SetCompetenciesAutocompleteFilter(keyword, ref where); //return CredentialManager.Autocomplete( where, 1, maxTerms, userId, ref pTotalRows ); return(new List <string>()); }
/// <summary> /// Retrieve Credential for compare purposes /// - name, description, cred type, education level, /// - industries, occupations /// - owner role /// - duration /// - estimated costs /// </summary> /// <param name="id"></param> /// <returns></returns> public static ThisEntity GetCredentialForCompare(int id) { //not clear if checks necessary, as interface only allows selection of those to which the user has access. AppUser user = AccountServices.GetCurrentUser(); LoggingHelper.DoTrace(2, string.Format("GetCredentialForCompare - using new compare get for cred: {0}", id)); //================================================ string statusMessage = ""; string key = "credentialCompare_" + id.ToString(); ThisEntity entity = new ThisEntity(); if (CacheManager.IsCredentialAvailableFromCache(id, key, ref entity)) { //check if user can update the object string status = ""; //if ( !CanUserUpdateCredential( id, user, ref status ) ) // entity.CanEditRecord = false; return(entity); } CredentialRequest cr = new CredentialRequest(); cr.IsCompareRequest(); DateTime start = DateTime.Now; entity = CredentialManager.GetForCompare(id, cr); //if ( CanUserUpdateCredential( entity, user, ref statusMessage ) ) // entity.CanUserEditEntity = true; DateTime end = DateTime.Now; int elasped = (end - start).Seconds; if (elasped > 1) { CacheManager.AddCredentialToCache(entity, key); } return(entity); } //
/// <summary> /// Full credentials search /// </summary> /// <param name="data"></param> /// <param name="pTotalRows"></param> /// <returns></returns> public static List <ThisSearchEntity> DoSearch(MainSearchInput data, ref int pTotalRows) { string where = ""; DateTime start = DateTime.Now; //Stopwatch stopwatch = new Stopwatch(); //stopwatch.Start(); LoggingHelper.DoTrace(6, string.Format("===CredentialServices.Search === Started: {0}", start)); int userId = 0; List <string> competencies = new List <string>(); AppUser user = AccountServices.GetCurrentUser(); if (user != null && user.Id > 0) { userId = user.Id; } //only target full entities where = " ( base.EntityStateId = 3 ) "; SetKeywordFilter(data.Keywords, false, ref where); where = where.Replace("[USERID]", user.Id.ToString()); SearchServices.SetSubjectsFilter(data, CodesManager.ENTITY_TYPE_CREDENTIAL, ref where); SearchServices.HandleCustomFilters(data, 58, ref where); //Should probably move this to its own method? string agentRoleTemplate = " ( id in (SELECT [CredentialId] FROM [dbo].[CredentialAgentRelationships_Summary] where RelationshipTypeId = {0} and OrgId = {1})) "; int roleId = 0; int orgId = 0; string AND = ""; if (where.Length > 0) { AND = " AND "; } //Updated to use FilterV2 foreach (var filter in data.FiltersV2.Where(m => m.Name == "qualityAssuranceBy").ToList()) { roleId = filter.GetValueOrDefault("RoleId", 0); orgId = filter.GetValueOrDefault("AgentId", 0); where = where + AND + string.Format(agentRoleTemplate, roleId, orgId); AND = " AND "; } /* //Retained for reference * foreach ( MainSearchFilter filter in data.Filters.Where( s => s.Name == "qualityAssuranceBy" ) ) * { * if ( filter.Data.ContainsKey( "RoleId" ) ) * roleId = (int)filter.Data[ "RoleId" ]; * if ( filter.Data.ContainsKey( "AgentId" ) ) * orgId = ( int ) filter.Data[ "AgentId" ]; * where = where + AND + string.Format( agentRoleTemplate, roleId, orgId ); * } */ SetPropertiesFilter(data, ref where); SearchServices.SetRolesFilter(data, ref where); SearchServices.SetBoundariesFilter(data, ref where); //need to fix rowId //naics, ONET SetFrameworksFilter(data, ref where); //Competencies SetCompetenciesFilter(data, ref where, ref competencies); SetCredCategoryFilter(data, ref where); //Not updated for FiltersV2 - I don't think we're using this anymore - NA 5/11/2017 SetConnectionsFilter(data, ref where); TimeSpan timeDifference = start.Subtract(DateTime.Now); LoggingHelper.DoTrace(5, thisClassName + string.Format(".Search(). Filter: {0}, elapsed: {1} ", where, timeDifference.TotalSeconds)); List <ThisSearchEntity> list = EntityMgr.Search(where, data.SortOrder, data.StartPage, data.PageSize, ref pTotalRows); //stopwatch.Stop(); timeDifference = start.Subtract(DateTime.Now); LoggingHelper.DoTrace(6, string.Format("===CredentialServices.Search === Ended: {0}, Elapsed: {1}, Filter: {2}", DateTime.Now, timeDifference.TotalSeconds, where)); return(list); }