/General/Service.cs

https://bitbucket.org/tvaladze/ipushserver
C# | 125 lines | 81 code | 17 blank | 27 comment | 1 complexity | 5a9c8eeea75e53b9f128314da8165e89 MD5 | raw file
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using SystemBase;
  6. namespace General
  7. {
  8. public class Service : ObjectBase
  9. {
  10. /// <summary>
  11. /// Gets Error message by name from Resources
  12. /// </summary>
  13. /// <param name="MessageName"></param>
  14. /// <returns></returns>
  15. public static string GetMessage(string MessageName)
  16. {
  17. return Properties.Resources.ResourceManager.GetString(MessageName);
  18. }
  19. public static DBGeneralDataContext GetDBGeneralDataContext()
  20. {
  21. return new DBGeneralDataContext(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString);
  22. }
  23. }
  24. public class Device : ObjectBase
  25. {
  26. #region Properties
  27. public string DToken { get; set; }
  28. public string DName { get; set; }
  29. #endregion
  30. #region Methods
  31. public List<Device> List_Devices(bool? isActive=null)
  32. {
  33. return TryToGetList<Device>("", delegate()
  34. {
  35. DBGeneralDataContext db = Service.GetDBGeneralDataContext();
  36. return db.List_Devices(isActive).Select(s => new Device
  37. {
  38. DToken = s.DToken,
  39. DName = s.DName
  40. }).ToList();
  41. });
  42. }
  43. #endregion
  44. }
  45. public class User : ObjectBase
  46. {
  47. #region Properties
  48. //public long ID { get; set; }
  49. //public string UserName { get; set; }
  50. //public string Email { get; set; }
  51. //public string Password { get; set; }
  52. //public string FName { get; set; }
  53. //public string LName { get; set; }
  54. //public string FLName { get; set; }
  55. //public int? RoleID { get; set; }
  56. //public string RoleName { get; set; }
  57. public bool? IsAuthorized { get; set; }
  58. public bool? IsAdmin { get; set; }
  59. #endregion
  60. #region Methods
  61. public bool Authenticate(string Username, string Password)
  62. {
  63. return TryToReturn<bool>("Authenticate(Username = " + Username + ", Password = " + Password + ")",
  64. delegate()
  65. {
  66. //DBClassesDataContext db = ConnectionFactory.GetDBGeneralDataContext();
  67. //string pwd = Password.MD5();
  68. //var U = db.Authorise(Username, pwd).DefaultIfEmpty().Single();
  69. // if (U != null)
  70. if (Password=="asdf")
  71. {
  72. Hashtable ClientTable = new Hashtable();
  73. ClientTable["IsAuthorized"] = true;
  74. //ClientTable["ID"] = U.ID;
  75. //ClientTable["IsAdmin"] = U.UserName == "admin";
  76. //ClientTable["UserName"] = U.UserName;
  77. //ClientTable["Email"] = U.Email;
  78. //ClientTable["Password"] = Password;
  79. //ClientTable["Fname"] = U.FName;
  80. //ClientTable["Lname"] = U.Lname;
  81. //ClientTable["RoleID"] = U.RoleID;
  82. //ClientTable["RoleName"] = U.RoleName;
  83. System.Web.HttpContext.Current.Session["UserInfo"] = ClientTable;
  84. return true;
  85. }
  86. return false;
  87. });
  88. }
  89. public bool GetAuthorizedCredentials()
  90. {
  91. try
  92. {
  93. Hashtable ClientTable = (Hashtable)System.Web.HttpContext.Current.Session["UserInfo"];
  94. IsAuthorized = (bool)ClientTable["IsAuthorized"];
  95. return true;
  96. }
  97. catch
  98. { return false; }
  99. }
  100. public void SetAuthorizedCredentials(string Key, object Value)
  101. {
  102. Hashtable ClientTable = (Hashtable)System.Web.HttpContext.Current.Session["UserInfo"];
  103. ClientTable[Key] = Value;
  104. System.Web.HttpContext.Current.Session["UserInfo"] = ClientTable;
  105. }
  106. #endregion
  107. }
  108. }