using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common; using System.Security.Principal; using System.Web; namespace EMISOnline.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 List GetUserData() { List userData = new List(); userData.Add(this.LoginID); userData.Add((this.UserID == Guid.Empty) ? "" : this.UserID.ToString()); userData.Add(this.Name); userData.Add((this.StaffID.HasValue) ? this.StaffID.ToString() : ""); userData.Add((this.StudentID.HasValue) ? this.StudentID.ToString() : ""); userData.Add((this.DepartmentID.HasValue) ? this.DepartmentID.ToString() : ""); userData.Add(DepartmentHierarchyID); userData.Add(DepartmentName); userData.Add((this.CollegeID.HasValue) ? this.CollegeID.ToString() : ""); userData.Add((this.CampusID.HasValue) ? this.CampusID.ToString() : ""); userData.Add((this.UniversityID.HasValue) ? this.UniversityID.ToString() : ""); userData.Add((this.RoleID.HasValue) ? 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; } } public static CustomPrincipal Current { get { try { return ((CustomPrincipal)HttpContext.Current.User); } catch { return null; } } } } }