Ejemplo n.º 1
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.ExecuteNonQuery(conn, "UpdateAdmin",
                                   admin.username, admin.password, Misc.ToXml(admin.Privileges));
     }
 }
Ejemplo n.º 2
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 = SqlHelper.ExecuteReader(conn, "FetchAdmins");
                else
                    reader = SqlHelper.ExecuteReader(conn, "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();
            }
        }
Ejemplo n.º 3
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;
 }