Пример #1
0
        public void SaveAccount(Account account)
        {
            using (var conn = Connection)
            using (var cmd = new UpdateCommand("UPDATE `accounts` SET {0} WHERE `username` = @username", conn))
            {
                cmd.AddParameter("@username", account.Username);
                cmd.Set("authority", account.Authority);
                cmd.Set("lastLogin", account.LastLogin);

                cmd.Execute();
            }
        }
Пример #2
0
        /// <summary>
        /// Retrieves an account start the database if it exists.
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public Account GetAccount(string username)
        {
            var account = new Account();

            using (var conn = Connection)
            {
                using (var mc = new MySqlCommand("SELECT * FROM `accounts` WHERE `username` = @username", conn))
                {
                    mc.Parameters.AddWithValue("@username", username);

                    using (var reader = mc.ExecuteReader())
                    {
                        if (!reader.Read())
                            return null;

                        account.Username = reader.GetStringSafe("username");
                        account.Password = reader.GetStringSafe("password");
                        account.Email = reader.GetStringSafe("email");
                        account.Fullname = reader.GetStringSafe("fullname");
                        account.Authority = reader.GetByte("authority");
                        account.Creation = reader.GetDateTime("creation");
                        account.LastLogin = reader.GetDateTime("lastLogin");
                        account.Appointments = GetAppointments(username);
                    }
                }
            }

            return account;
        }