using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common; using System.Security.Principal; using System.Web; namespace EMIS.Utility.FormValidate { public class CustomPrincipal : ICustomPrincipal { IIdentity iIdentity; public Guid UserID { get; set; } public string LoginID { get; set; } public string Name { get; set; } public Guid? StaffID { get; set; } public Guid? StudentID { get; set; } public Guid? CollegeID { get; set; } public Guid? CampusID { get; set; } public Guid? UniversityID { get; set; } //For teacher public Guid? DepartmentID { get; set; } public string DepartmentHierarchyID { get; set; } public string DepartmentName { get; set; } public bool IsStudent { get { return StudentID.HasValue; } } public Guid? RoleID { get; set; } public void ProcessData(System.Security.Principal.IIdentity id, string data) { this.iIdentity = id; //Pengzw Add 2012-11-26 var set = data.Split('|'); this.LoginID = set[0]; this.UserID = string.IsNullOrEmpty(set[1]) ? new Guid() : new Guid(set[1]); this.Name = set[2]; this.StaffID = string.IsNullOrEmpty(set[3]) ? new Nullable() : new Nullable(Guid.Parse(set[3])); this.StudentID = string.IsNullOrEmpty(set[4]) ? new Nullable() : new Nullable(Guid.Parse(set[4])); this.DepartmentID = string.IsNullOrEmpty(set[5]) ? new Nullable() : new Nullable(Guid.Parse(set[5])); this.DepartmentHierarchyID = set[6]; this.DepartmentName = set[7]; this.CollegeID = string.IsNullOrEmpty(set[8]) ? new Nullable() : new Nullable(Guid.Parse(set[8])); this.CampusID = string.IsNullOrEmpty(set[9]) ? new Nullable() : new Nullable(Guid.Parse(set[9])); this.UniversityID = string.IsNullOrEmpty(set[10]) ? new Nullable() : new Nullable(Guid.Parse(set[10])); if (set.Length == 12) { this.RoleID = string.IsNullOrEmpty(set[11]) ? new Nullable() : new Nullable(Guid.Parse(set[11])); } } public void ProcessData(string data) { var set = data.Split('|'); this.LoginID = set[0]; this.UserID = string.IsNullOrEmpty(set[1]) ? new Guid() : new Guid(set[1]); this.Name = set[2]; this.StaffID = string.IsNullOrEmpty(set[3]) ? new Nullable() : new Nullable(Guid.Parse(set[3])); this.StudentID = string.IsNullOrEmpty(set[4]) ? new Nullable() : new Nullable(Guid.Parse(set[4])); this.DepartmentID = string.IsNullOrEmpty(set[5]) ? new Nullable() : new Nullable(Guid.Parse(set[5])); this.DepartmentHierarchyID = set[6]; this.DepartmentName = set[7]; this.CollegeID = string.IsNullOrEmpty(set[8]) ? new Nullable() : new Nullable(Guid.Parse(set[8])); this.CampusID = string.IsNullOrEmpty(set[9]) ? new Nullable() : new Nullable(Guid.Parse(set[9])); this.UniversityID = string.IsNullOrEmpty(set[10]) ? new Nullable() : new Nullable(Guid.Parse(set[10])); if (set.Length == 12) { this.RoleID = string.IsNullOrEmpty(set[11]) ? new Nullable() : new Nullable(Guid.Parse(set[11])); } _current = this; } public List GetUserData() { var userData = new List(); userData.Add(this.LoginID); userData.Add(this.UserID.ToString()); userData.Add(this.Name); userData.Add(this.StaffID == null ? "" : this.StaffID.ToString()); userData.Add(this.StudentID == null ? "" : this.StudentID.ToString()); userData.Add(this.DepartmentID == null ? "" : this.DepartmentID.ToString()); userData.Add(this.DepartmentHierarchyID); userData.Add(this.DepartmentName); userData.Add(this.CollegeID == null ? "" : this.CollegeID.ToString()); userData.Add(this.CampusID == null ? "" : this.CampusID.ToString()); userData.Add(this.UniversityID == null ? "" : this.UniversityID.ToString()); userData.Add(this.RoleID == null ? "" : this.RoleID.ToString()); return userData; } public System.Security.Principal.IIdentity Identity { get { return iIdentity; } } public bool IsInRole(string role) { if (!string.IsNullOrEmpty(Name)) { return true; } else { return false; } } private static CustomPrincipal _current; public static CustomPrincipal Current { get { try { if (HttpContext.Current == null) { return _current; } return ((CustomPrincipal)HttpContext.Current.User); } catch { return null; } } } } }