Example #1
0
        /// <summary>
        /// Fetches admin by specified username from DB or fetches all admins if the argument is null.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <returns>An array with admins.</returns>
        /// <example>The following code example fetches all admins from DB.
        /// <code>
        /// Admin[] allAdmins = Admin.FetchAdmins(null);
        /// </code>
        /// </example>
        private static Admin[] FetchAdmins(string username)
        {
            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader;
                if (username == null || username == "")
                    reader = (SqlDataReader)SqlHelper.GetDB().ExecuteReader("FetchAdmins");
                else
                    reader = (SqlDataReader)SqlHelper.GetDB().ExecuteReader("FetchAdmins", username);

                List<Admin> lAdmins = new List<Admin>();

                while (reader.Read())
                {
                    Admin admin = new Admin();

                    admin.username = (string)reader["Username"];
                    admin.password = (string)reader["Password"];
                    admin.lastlogin = (DateTime)reader["LastLogin"];
                    try
                    {
                        if (admin.Username == Config.Users.SystemUsername)
                        {
                            admin.Privileges = GetFullAccess();
                        }
                        else
                            admin.Privileges = Misc.FromXml<AdminPrivileges>((string)reader["Privileges"]);
                    }
                    catch
                    {
                        //no privileges found ... default will be used instead
                    }

                    lAdmins.Add(admin);
                }

                return lAdmins.ToArray();
            }
        }
Example #2
0
 /// <summary>
 /// Loads admin account data from DB by specified username.
 /// </summary>
 /// <param name="Username">Username identifying the admin</param>
 /// <returns>User object</returns>
 /// <exception cref="NotFoundException">Username was not found.</exception>
 public static Admin Load(string Username)
 {
     Admin admin = new Admin(Username);
     admin.Load();
     return admin;
 }
Example #3
0
 /// <summary>
 /// Updates admin account data
 /// </summary>
 /// <param name="admin">User object</param>
 public static void Update(Admin admin)
 {
     using (SqlConnection conn = Config.DB.Open())
     {
         SqlHelper.GetDB().ExecuteNonQuery( "UpdateAdmin",
                                   admin.username, admin.password, Misc.ToXml(admin.Privileges));
     }
 }
Example #4
0
 /// <summary>
 /// Stores the specified admin in the DB.
 /// </summary>
 /// <param name="admin">The admin.</param>
 public static void Create(Admin admin)
 {
     //using (var conn = Config.DB.Open())
     {
         SqlHelper.GetDB().ExecuteNonQuery( "CreateAdmin",
                                   admin.username, admin.password, Misc.ToXml(admin.Privileges));
     }
 }