Remove photo from showprofile (#26253)

This commit is contained in:
Hao Kung 2020-10-02 09:21:29 -07:00 committed by GitHub
parent 242701ca40
commit 854b4aad4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 0 additions and 40 deletions

View File

@ -24,61 +24,21 @@ else
<td>Name</td> <td>Name</td>
<td>@user.DisplayName</td> <td>@user.DisplayName</td>
</tr> </tr>
<tr>
<td>Photo</td>
<td>
@{
if (photo != null)
{
<img style="margin: 5px 0; width: 150px" src="data:image/jpeg;base64, @photo" />
}
else
{
<h3>NO PHOTO</h3>
<p>Check user profile in Azure Active Directory to add a photo.</p>
}
}
</td>
</tr>
</table> </table>
} }
@code { @code {
User user; User user;
string photo;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
try try
{ {
user = await GraphServiceClient.Me.Request().GetAsync(); user = await GraphServiceClient.Me.Request().GetAsync();
photo = await GetPhoto();
} }
catch (Exception ex) catch (Exception ex)
{ {
ConsentHandler.HandleException(ex); ConsentHandler.HandleException(ex);
} }
} }
protected async Task<string> GetPhoto()
{
string photo;
try
{
using (var photoStream = await GraphServiceClient.Me.Photo.Content.Request().GetAsync())
{
byte[] photoByte = ((System.IO.MemoryStream)photoStream).ToArray();
photo = Convert.ToBase64String(photoByte);
this.StateHasChanged();
}
}
catch (Exception)
{
photo = null;
}
return photo;
}
} }