using System;
using System.Xml;
namespace CPE.App.Web.Connect {
///
/// Represents a principal-info object returned from Connect.
///
public class PrincipalInfo {
///
/// The ID of the account the principal belongs to.
///
public int AccountId { get; private set; }
///
/// The date the account was disabled. If the account is active, then the value will be null.
///
public DateTime? Disabled { get; private set; }
///
/// The ID of the principal.
///
public int PrincipalId { get; private set; }
///
/// The principal’s login ID on Connect Enterprise. Can be the same as an e-mail address.
///
public string Login { get; private set; }
///
/// For a user, the e-mail address.
///
public string Email { get; private set; }
///
/// For a user, the full name, concatenated from their first and last name fields.
///
public string Name { get; private set; }
///
/// For a user, the first name.
///
public string FirstName { get; private set; }
///
/// For a user, the last name.
///
public string LastName { get; private set; }
public string DisplayName
{
get
{
return string.Format("{0} {1}", FirstName, LastName).Trim();
}
}
///
/// Initializes the object by parsing the values from the XmlDocument.
///
/// The XmlDocument returned from Connect for this object.
public PrincipalInfo(XmlNode document) {
// Find main node
XmlNode principal = document.SelectSingleNode("/results/principal");
// Parse values
AccountId = int.Parse(principal.Attributes["account-id"].Value);
PrincipalId = int.Parse(principal.Attributes["principal-id"].Value);
Login = principal.SelectSingleNode("login").InnerText;
Name = principal.SelectSingleNode("name").InnerText;
try
{
FirstName = principal.SelectSingleNode("first-name").InnerText;
}
catch
{
FirstName = "";
}
try
{
LastName = principal.SelectSingleNode("last-name").InnerText;
}
catch
{
LastName = "";
}
Email = principal.SelectSingleNode("email").InnerText;
if(principal.Attributes["disabled"].Value != string.Empty)
Disabled = DateTime.Parse(principal.Attributes["disabled"].Value);
}
}
}