From 3ba04217dfba44c6554c78da39e23a39477e4eab Mon Sep 17 00:00:00 2001 From: "Zach Keeping [SSW]" <11418832+zacharykeeping@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:04:39 +1100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Mobile=20|=20Restore=20opening?= =?UTF-8?q?=20user=20profile=20on=20QR=20code=20scan=20(#1109)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Return correct staff ID * Return correct UserID and add error handling * Update message * Update message --- .../PostAchievement/PostAchievementCommand.cs | 39 +++++++++------- .../Features/Profile/ProfileViewModelBase.cs | 44 +++++++++++-------- 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/src/Application/Achievements/Command/PostAchievement/PostAchievementCommand.cs b/src/Application/Achievements/Command/PostAchievement/PostAchievementCommand.cs index 6dd002f5..dadf57ae 100644 --- a/src/Application/Achievements/Command/PostAchievement/PostAchievementCommand.cs +++ b/src/Application/Achievements/Command/PostAchievement/PostAchievementCommand.cs @@ -52,23 +52,28 @@ public async Task Handle(PostAchievementCommand request, // check for milestone achievements if (requestedAchievement.Type == AchievementType.Scanned) { - // TODO: Re-enable when fixed - // var scannedUser = await _context.Users - // .FirstOrDefaultAsync(u => u.AchievementId == requestedAchievement.Id, cancellationToken); - // - // if (scannedUser == null) - // { - // var staffMember = await _context.StaffMembers - // .Include(s => s.StaffAchievement) - // .Where(s => s.StaffAchievement != null) - // .FirstOrDefaultAsync(s => s.StaffAchievement!.Id == requestedAchievement.Id, cancellationToken); - // - // achievementModel.UserId = staffMember?.Id; - // } - // else - // { - // achievementModel.UserId = scannedUser.Id; - // } + var scannedUser = await _context.Users + .FirstOrDefaultAsync(u => u.AchievementId == requestedAchievement.Id, cancellationToken); + + if (scannedUser == null) + { + var staffMember = await _context.StaffMembers + .Include(s => s.StaffAchievement) + .Where(s => s.StaffAchievement != null) + .FirstOrDefaultAsync(s => s.StaffAchievement!.Id == requestedAchievement.Id, cancellationToken); + + if (staffMember != null) + { + var staffUser = await _context.Users + .FirstOrDefaultAsync(u => u.Email == staffMember.Email, cancellationToken); + + achievementModel.UserId = staffUser?.Id; + } + } + else + { + achievementModel.UserId = scannedUser.Id; + } if (!userAchievements.Any(ua => ua.Achievement.Name == MilestoneAchievements.MeetSSW)) { diff --git a/src/MobileUI/Features/Profile/ProfileViewModelBase.cs b/src/MobileUI/Features/Profile/ProfileViewModelBase.cs index b30ab2eb..7f953414 100644 --- a/src/MobileUI/Features/Profile/ProfileViewModelBase.cs +++ b/src/MobileUI/Features/Profile/ProfileViewModelBase.cs @@ -103,26 +103,34 @@ protected async Task LoadProfileSections() if (!_loadingProfileSectionsSemaphore.Wait(0)) return; - IsLoading = true; - var profileTask = _userService.GetUserAsync(UserId); - var socialMediaTask = LoadSocialMedia(); + try + { + IsLoading = true; + var profileTask = _userService.GetUserAsync(UserId); + var socialMediaTask = LoadSocialMedia(); - await Task.WhenAll(profileTask, socialMediaTask); - - var profile = profileTask.Result; - - ProfilePic = profile.ProfilePic ?? "v2sophie"; - Name = profile.FullName; - Rank = profile.Rank; - Points = profile.Points; - Balance = profile.Balance; - IsStaff = profile.IsStaff; - UserEmail = profile.Email; - Title = GetTitle(); + await Task.WhenAll(profileTask, socialMediaTask); + + var profile = profileTask.Result; + + ProfilePic = profile.ProfilePic ?? "v2sophie"; + Name = profile.FullName; + Rank = profile.Rank; + Points = profile.Points; + Balance = profile.Balance; + IsStaff = profile.IsStaff; + UserEmail = profile.Email; + Title = GetTitle(); - await UpdateSkillsSectionIfRequired(); - UpdateLastSeenSection(profile.Achievements); - UpdateRecentActivitySection(profile.Achievements, profile.Rewards); + await UpdateSkillsSectionIfRequired(); + UpdateLastSeenSection(profile.Achievements); + UpdateRecentActivitySection(profile.Achievements, profile.Rewards); + } + catch (Exception) + { + await ClosePage(); + await App.Current.MainPage.DisplayAlert("Oops...", "There was an error loading this profile", "OK"); + } _loadingProfileSectionsSemaphore.Release(); IsLoading = false;