public async Task <IActionResult> Index() { try { var id = new Guid(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value); var profile = await _demoClient.GetUserProfile(id); var userEmail = _authClient.GetUserById(id).Result.Email; var model = new ProfileViewModel { Id = id, FirstName = profile.FirstName, LastName = profile.LastName, Birthdate = profile.BirthDate, Gender = profile.Gender, PhoneNumber = profile.PhoneNumbers.FirstOrDefault(), DisplayName = profile.DisplayName, Title = profile.Title, Email = userEmail, EmailRecord = userEmail }; if (model.Birthdate != null) { model.BirthDateString = model.Birthdate.Value.ToString("dd/MM/yyyy"); } return(View(model)); } catch (Exception e) { return(RedirectToAction("Index", "Error")); } }
public async Task <IActionResult> Edit(string id) { try { var userId = new Guid(id); var profile = await _demoClient.GetUserProfile(userId); var user = await _authClient.GetUserById(userId); var roles = await _authClient.GetRoles(); var assignedRoles = await _authClient.GetUserRolesByUserId(userId); var model = new EditUserViewModel { Id = userId, FirstName = profile.FirstName, LastName = profile.LastName, BirthDate = profile.BirthDate, Gender = profile.Gender, PhoneNumber = profile.PhoneNumbers.FirstOrDefault(), DisplayName = profile.DisplayName, Title = profile.Title, AllRoles = roles, // There is an email property that we get from Auth, but there is also a email property on a // demographics profile. So this allows flexibility if someone wasn't using BOS Auth to still // maintain email address in our system. However it can also lead to inconsistent data. The // eventual consistency is just something to be aware of. For this app, the email on the // Auth user is the single source of truth, so we get that here. Email = user.Email, EmailRecord = user.Email }; if (model.BirthDate != null) { model.BirthDateString = model.BirthDate.Value.ToString("dd/MM/yyyy"); } foreach (Role r in roles) { if (assignedRoles.Any(ro => ro.Id == r.Id)) { model.AssignedRoles.Add(r); } } return(View(model)); } catch (Exception e) { return(RedirectToAction("Index", "Error")); } }