Using reflection to enumerate all of the properties on the user profile

This commit is contained in:
Wade Wegner 2014-09-04 13:46:02 -06:00
Родитель b894989c94
Коммит 8ea2c18a88
2 изменённых файлов: 85 добавлений и 36 удалений

Просмотреть файл

@ -6,9 +6,38 @@ using System.Web;
namespace WebAppGraphAPI.Models namespace WebAppGraphAPI.Models
{ {
public class UserProfile public class UserProfile
{ {
public string DisplayName { get; set; } public string ObjectType { get; set; }
public string GivenName { get; set; } public List<object> AssignedLicenses { get; set; }
public string Surname { get; set; } public List<object> AssignedPlans { get; set; }
public object City { get; set; }
public object Country { get; set; }
public object Department { get; set; }
public object DirSyncEnabled { get; set; }
public string DisplayName { get; set; }
public object FacsimileTelephoneNumber { get; set; }
public string GivenName { get; set; }
public object ImmutableId { get; set; }
public object JobTitle { get; set; }
public object LastDirSyncTime { get; set; }
public object Mail { get; set; }
public string MailNickname { get; set; }
public object Mobile { get; set; }
public List<string> OtherMails { get; set; }
public string PasswordPolicies { get; set; }
public object PasswordProfile { get; set; }
public object PhysicalDeliveryOfficeName { get; set; }
public object PostalCode { get; set; }
public object PreferredLanguage { get; set; }
public List<object> ProvisionedPlans { get; set; }
public List<object> ProvisioningErrors { get; set; }
public List<object> ProxyAddresses { get; set; }
public object State { get; set; }
public object StreetAddress { get; set; }
public string Surname { get; set; }
public object TelephoneNumber { get; set; }
public object UsageLocation { get; set; }
public string UserPrincipalName { get; set; }
public string UserType { get; set; }
} }
} }

Просмотреть файл

@ -1,32 +1,52 @@
@model WebAppGraphAPI.Models.UserProfile @using System.Collections
@{ @model WebAppGraphAPI.Models.UserProfile
ViewBag.Title = "User Profile"; @{
} ViewBag.Title = "User Profile";
}
<h2>@ViewBag.Title.</h2> <h2>@ViewBag.Title.</h2>
<table class="table table-bordered table-striped"> <table class="table table-bordered table-striped">
<tr> @{
<td>Display Name</td> var type = Model.GetType();
<td>@Model.DisplayName</td> var properties = type.GetProperties();
</tr> var collections = new List<Type>() { typeof(IEnumerable<>), typeof(IEnumerable) };
<tr>
<td>First Name</td> foreach (var property in properties)
<td>@Model.GivenName</td> {
</tr> <tr>
<tr> <td>@property.Name</td>
<td>Last Name</td> <td>
<td>@Model.Surname</td> @{
</tr> if (property.PropertyType != typeof(string) && property.PropertyType.GetInterfaces().Any(i => collections.Any(c => i == c)))
</table> {
var list = (IList)property.GetValue(Model, null);
@if (ViewBag.ErrorMessage == "AuthorizationRequired") if (list != null)
{ {
<p>You have to sign-in to see your profile. Click @Html.ActionLink("here", "Index", "UserProfile", new { reauth = true }, null) to sign-in.</p> foreach (var value in list)
} {
@value<br />
@if (ViewBag.ErrorMessage == "UnexpectedError") }
{ }
<p>An unexpected error occurred while retrieving your profile. Please try again. You may need to sign-in.</p>
} }
else
{
@property.GetValue(Model, null)
}
}
</td>
</tr>
}
}
</table>
@if (ViewBag.ErrorMessage == "AuthorizationRequired")
{
<p>You have to sign-in to see your profile. Click @Html.ActionLink("here", "Index", "UserProfile", new { reauth = true }, null) to sign-in.</p>
}
@if (ViewBag.ErrorMessage == "UnexpectedError")
{
<p>An unexpected error occurred while retrieving your profile. Please try again. You may need to sign-in.</p>
}