private async Task <AccountViewModel> GetAccountViewModel(User user, CancellationToken cancellationToken, bool verifyNow = false) { var viewModel = new AccountViewModel(); if (user != null) { List <NotificationModel> notifications = new List <NotificationModel>() { new NotificationModel { Id = Guid.NewGuid(), Title = "Good news " + user.UserPersonalDetails.FirstName + "!", Message = "<p>Your account is all set up.</p>" + " <div> Coming Soon: " + "<ul style='margin-top:2px;'> " + "<li>You will soon be able to update the personal and volunteering details on your profile page. </li>" + "</ul> " + "</div>" + "<p>Keep an eye on your email inbox for the latest updates. Thanks for joining HelpMyStreet!</p>", Type = NotificationType.Success } }; var userDetails = await _userService.GetUserDetails(user, cancellationToken); viewModel.Notifications = notifications; viewModel.VerificationViewModel = new VerificationViewModel { YotiOptions = _yotiOptions.Value, EncodedUserID = Base64Utils.Base64Encode(user.ID), DisplayName = userDetails.DisplayName, StartAtStep = verifyNow ? 1 : 0, }; viewModel.UserDetails = userDetails; viewModel.UserGroups = await _groupMemberService.GetUserGroupRoles(user.ID, cancellationToken); viewModel.VerificationViewModel.IsVerified = await _groupMemberService.GetUserIsVerified(user.ID, cancellationToken); } return(viewModel); }
public async Task <CurrentAwardModel> GetAwardsByUserID(int userID, CancellationToken cancellationToken) { try { var jobs = await _requestService.GetJobsForUserAsync(userID, true, cancellationToken); var shifts = await _requestService.GetShiftsForUserAsync(userID, null, null, true, cancellationToken); var awards = await GetAwards(); bool userIsVerified = await _groupMemberService.GetUserIsVerified(userID, cancellationToken); var predicates = new List <Object>() { userIsVerified }; IEnumerable <JobBasic> shiftsAndJobs = jobs.Select(j => (JobBasic)j).Concat(shifts.Select(s => (JobBasic)s)); var completedJobs = shiftsAndJobs.Where(x => x.JobStatus == JobStatuses.Done); var relevantAward = awards.Where(x => completedJobs.Count() >= x.AwardValue && x.SpecificPredicate(predicates)).OrderBy(x => x.AwardValue).LastOrDefault(); var completedJobDictionary = completedJobs.GroupBy(x => x.SupportActivity).ToDictionary(g => g.Key, g => g.Count()); return(new CurrentAwardModel { Award = relevantAward, CompletedJobCount = completedJobs.Count(), CompletedJobs = completedJobDictionary }); } catch { // Skip awards component if request service has been too slow to respond return(null); } }