public JsonResult GetCurrentSecurityScreeningSummaryNew() { // get the current user. UserSettings userSettings = UserSettings.CreateFromHttpContext(_httpContextAccessor); // check that the session is setup correctly. userSettings.Validate(); // get data for the current account. string currentAccountId = userSettings.AccountId; var contacts = _dynamicsClient.GetLEConnectionsForAccount(currentAccountId, _logger, _configuration); List <SecurityScreeningStatusItem> securityItems = GetConnectionsScreeningData(contacts); // get the current user's applications and licences var licences = _dynamicsClient.GetLicensesByLicencee(_cache, currentAccountId); var applications = _dynamicsClient.GetApplicationsForLicenceByApplicant(currentAccountId); SecurityScreeningSummary result = new SecurityScreeningSummary(); // determine how many of each licence there are. int cannabisLicenceCount = 0; int liquorLicenceCount = 0; if (licences != null && licences.Count() > 0) { cannabisLicenceCount = licences.Count(x => x.AdoxioLicenceType.AdoxioName.ToUpper().Contains("CANNABIS")); liquorLicenceCount = licences.Count() - cannabisLicenceCount; } // determine how many applications of each type there are. int cannabisApplicationCount = 0; int liquorApplicationCount = 0; if (applications != null && applications.Count() > 0) { cannabisApplicationCount = applications.Count(x => x.AdoxioApplicationTypeId != null && x.AdoxioApplicationTypeId.AdoxioName != null && x.AdoxioApplicationTypeId.AdoxioName.ToUpper().Contains("CANNABIS")); liquorApplicationCount = applications.Count() - cannabisApplicationCount; } if (cannabisLicenceCount > 0 || cannabisApplicationCount > 0) { var data = securityItems.Select(item => { item.IsComplete = (item.Contact?.AdoxioCascomplete == (int)YesNoOptions.Yes); return(item); }); result.Cannabis = new SecurityScreeningCategorySummary() { CompletedItems = data.Where(item => item.IsComplete).ToList(), OutstandingItems = data.Where(item => !item.IsComplete).ToList() }; } if (liquorLicenceCount > 0 || liquorApplicationCount > 0) { var data = securityItems.Select(item => { item.IsComplete = (item.Contact?.AdoxioPhscomplete == (int)YesNoOptions.Yes); return(item); }); result.Liquor = new SecurityScreeningCategorySummary() { CompletedItems = data.Where(item => item.IsComplete).ToList(), OutstandingItems = data.Where(item => !item.IsComplete).ToList() }; } return(new JsonResult(result)); }