Пример #1
0
 public static ActivityViewModel WithUserInfo(this ActivityViewModel viewModel, Activity activity, ClaimsPrincipal user, IAllReadyDataAccess dataAccess)
 {
     if (user.IsSignedIn())
     {
         var userId = user.GetUserId();
         var appUser = dataAccess.GetUser(userId);
         viewModel.UserId = userId;
         viewModel.UserSkills = appUser?.AssociatedSkills?.Select(us => us.Skill).ToList();
         viewModel.IsUserVolunteeredForActivity = dataAccess.GetActivitySignups(viewModel.Id, userId).Any();
         var assignedTasks = activity.Tasks.Where(t => t.AssignedVolunteers.Any(au => au.User.Id == userId)).ToList();
         viewModel.Tasks = new List<TaskViewModel>(assignedTasks.Select(data => new TaskViewModel(data, userId)).OrderBy(task => task.StartDateTime));
         viewModel.SignupModel = new ActivitySignupViewModel()
         {
             ActivityId = viewModel.Id,
             UserId = userId,
             Name = appUser.Name,
             PreferredEmail = appUser.Email,
             PreferredPhoneNumber = appUser.PhoneNumber
         };
     }
     else
     {
         viewModel.Tasks = new List<TaskViewModel>();
     }
     return viewModel;
 }