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
{
public class UserProfile
{
public string DisplayName { get; set; }
public string GivenName { get; set; }
public string Surname { get; set; }
{
public string ObjectType { get; set; }
public List<object> AssignedLicenses { 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
@{
ViewBag.Title = "User Profile";
}
<h2>@ViewBag.Title.</h2>
<table class="table table-bordered table-striped">
<tr>
<td>Display Name</td>
<td>@Model.DisplayName</td>
</tr>
<tr>
<td>First Name</td>
<td>@Model.GivenName</td>
</tr>
<tr>
<td>Last Name</td>
<td>@Model.Surname</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>
}
@using System.Collections
@model WebAppGraphAPI.Models.UserProfile
@{
ViewBag.Title = "User Profile";
}
<h2>@ViewBag.Title.</h2>
<table class="table table-bordered table-striped">
@{
var type = Model.GetType();
var properties = type.GetProperties();
var collections = new List<Type>() { typeof(IEnumerable<>), typeof(IEnumerable) };
foreach (var property in properties)
{
<tr>
<td>@property.Name</td>
<td>
@{
if (property.PropertyType != typeof(string) && property.PropertyType.GetInterfaces().Any(i => collections.Any(c => i == c)))
{
var list = (IList)property.GetValue(Model, null);
if (list != null)
{
foreach (var value in list)
{
@value<br />
}
}
}
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>
}