public async Task <IEnumerable <EnrolleeListViewModel> > GetEnrolleesAsync(EnrolleeSearchOptions searchOptions = null)
        {
            searchOptions = searchOptions ?? new EnrolleeSearchOptions();

            IQueryable <int> newestAgreementIds = _context.AgreementVersions
                                                  .Select(a => a.AgreementType)
                                                  .Distinct()
                                                  .Select(type => _context.AgreementVersions
                                                          .OrderByDescending(a => a.EffectiveDate)
                                                          .First(a => a.AgreementType == type)
                                                          .Id
                                                          );

            return(await _context.Enrollees
                   .AsNoTracking()
                   .If(!string.IsNullOrWhiteSpace(searchOptions.TextSearch), q => q
                       .Search(e => e.FirstName,
                               e => e.LastName,
                               e => e.FullName,
                               e => e.Email,
                               e => e.Phone,
                               e => e.DisplayId.ToString())
                       .SearchCollections(e => e.Certifications.Select(c => c.LicenseNumber))
                       .Containing(searchOptions.TextSearch)
                       )
                   .If(searchOptions.StatusCode.HasValue, q => q
                       .Where(e => e.CurrentStatus.StatusCode == searchOptions.StatusCode.Value)
                       )
                   .ProjectTo <EnrolleeListViewModel>(_mapper.ConfigurationProvider, new { newestAgreementIds = newestAgreementIds })
                   .DecompileAsync() // Needed to allow selecting into computed properties like DisplayId and CurrentStatus
                   .OrderBy(e => e.Id)
                   .ToListAsync());
        }
        public async Task <ActionResult> GetEnrollees([FromQuery] EnrolleeSearchOptions searchOptions)
        {
            if (User.HasAdminView())
            {
                return(Ok(ApiResponse.Result(await _enrolleeService.GetEnrolleesAsync(searchOptions))));
            }
            else
            {
                var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

                return(Ok(ApiResponse.Result(enrollee == null ? Enumerable.Empty <Enrollee>() : new[] { enrollee })));
            }
        }
示例#3
0
        public async Task <ActionResult <IEnumerable <Enrollee> > > GetEnrollees([FromQuery] EnrolleeSearchOptions searchOptions)
        {
            IEnumerable <Enrollee> enrollees = null;

            // User must have the RO_ADMIN or ADMIN role to see all enrollees
            if (User.IsAdmin() || User.HasAdminView())
            {
                enrollees = await _enrolleeService.GetEnrolleesAsync(searchOptions);
            }
            else
            {
                var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

                enrollees = (enrollee != null) ? new[] { enrollee } : new Enrollee[0];
            }

            return(Ok(ApiResponse.Result(enrollees)));
        }
示例#4
0
        public async Task <ActionResult> GetEnrollees([FromQuery] EnrolleeSearchOptions searchOptions)
        {
            if (User.HasAdminView())
            {
                var notifiedIds = await _enrolleeService.GetNotifiedEnrolleeIdsForAdminAsync(User);

                var enrollees = await _enrolleeService.GetEnrolleesAsync(searchOptions);

                var result = enrollees.Select(e => e.SetNotification(notifiedIds.Contains(e.Id)));
                return(Ok(ApiResponse.Result(result)));
            }
            else
            {
                var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

                return(Ok(ApiResponse.Result(enrollee == null ? Enumerable.Empty <Enrollee>() : new[] { enrollee })));
            }
        }
示例#5
0
        public async Task <IEnumerable <Enrollee> > GetEnrolleesAsync(EnrolleeSearchOptions searchOptions = null)
        {
            IQueryable <Enrollee> query = this.GetBaseEnrolleeQuery();

            if (searchOptions?.StatusCode != null)
            {
                query.Load();
                query = _context.Enrollees.Where(e => e.CurrentStatus.StatusCode == (short)searchOptions.StatusCode);
            }

            var items = await query.ToListAsync();

            foreach (var item in items)
            {
                // Add the available statuses to the enrolment
                item.AvailableStatuses = this.GetAvailableStatuses(item.CurrentStatus?.Status);
            }

            return(items);
        }
示例#6
0
        public async Task <IEnumerable <Enrollee> > GetEnrolleesAsync(EnrolleeSearchOptions searchOptions = null)
        {
            IQueryable <Enrollee> query = this.GetBaseEnrolleeQuery()
                                          .Include(e => e.Adjudicator);

            if (searchOptions != null && searchOptions.TextSearch != null)
            {
                query = query.Where(e =>
                                    e.FirstName.ToLower().StartsWith(searchOptions.TextSearch.ToLower()) ||
                                    e.LastName.ToLower().StartsWith(searchOptions.TextSearch.ToLower()) ||
                                    e.ContactEmail.ToLower().StartsWith(searchOptions.TextSearch.ToLower()) ||
                                    e.VoicePhone.ToLower().StartsWith(searchOptions.TextSearch.ToLower())
                                    // Since DisplayId is a derived field we can not query on it. And we
                                    // don't want to have to grab all Enrollees and filter on the front end.
                                    || (e.Id + Enrollee.DISPLAY_OFFSET).ToString().Equals(searchOptions.TextSearch) ||
                                    e.FirstName.ToLower().StartsWith(searchOptions.TextSearch.ToLower()) ||
                                    e.Certifications.Any(c => c.LicenseNumber.ToLower().StartsWith(searchOptions.TextSearch.ToLower()))
                                    );
            }

            IEnumerable <Enrollee> items = await query.ToListAsync();

            if (searchOptions?.StatusCode != null)
            {
                // TODO refactor see Jira PRIME-251
                items = items.Where(e => e.CurrentStatus.StatusCode == searchOptions.StatusCode);
            }

            foreach (var item in items)
            {
                item.Privileges = await _privilegeService.GetPrivilegesForEnrolleeAsync(item);

                // Attach to the enrollee if they have signed the most recent ToA
                item.CurrentTOAStatus = await _accessTermService.GetCurrentTOAStatusAsync(item);
            }

            return(items);
        }
        public async Task <ActionResult <IEnumerable <Enrollee> > > GetEnrollees(
            [FromQuery] EnrolleeSearchOptions searchOptions)
        {
            IEnumerable <Enrollee> enrollees = null;

            // User must have the ADMIN role to see all enrollees
            if (User.IsInRole(PrimeConstants.PRIME_ADMIN_ROLE))
            {
                enrollees = await _enrolleeService.GetEnrolleesAsync(searchOptions);
            }
            else
            {
                var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

                enrollees = new List <Enrollee>();

                if (enrollee != null)
                {
                    enrollees = enrollees.Append(enrollee);
                }
            }

            return(Ok(new ApiOkResponse <IEnumerable <Enrollee> >(enrollees)));
        }
示例#8
0
        public Task <IEnumerable <Enrollee> > GetEnrolleesAsync(EnrolleeSearchOptions searchOptions)
        {
            IEnumerable <Enrollee> enrollees = this.GetHolder <int, Enrollee>().Values;

            return(Task.FromResult(enrollees));
        }
 public Task <IEnumerable <Enrollee> > GetEnrolleesAsync(EnrolleeSearchOptions searchOptions)
 {
     return(Task.FromResult((IEnumerable <Enrollee>) this.GetHolder <int, Enrollee>().Values?.ToList()));
 }