/// <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); //SetAuthorizationFilter( user, 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); }