Beispiel #1
0
        private List <Currency> GetCurrencies(long economyId)
        {
            List <Currency> currencies = new List <Currency>();

            SqlConnection sql     = DatabaseService.GetSqlConnection();
            string        fetch   = "SELECT * FROM dbo.Currency WHERE EconomyId=@economyId";
            SqlCommand    command = new SqlCommand(fetch, sql);

            command.Parameters.AddWithValue("@economyId", economyId);

            using (SqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    currencies.Add(CurrencyService.GetCurrency((long)reader["Id"]));
                }
            }

            sql.Close();

            List <Currency> sortedCurrencies = currencies.OrderByDescending(c => c.ConversionRateToStandard).ToList();

            return(sortedCurrencies);
        }
        /// <summary>
        /// gets a currencyCOunt of the provided ID from the database
        /// </summary>
        /// <param name="currencyCountId">ID of the count to fetch</param>
        /// <returns>instance of the CurrencyCount class matching the database</returns>
        public static CurrencyCount GetCurrencyCount(long currencyCountId)
        {
            Debug.WriteLine("I'm fetching the currency count with the ID of " + currencyCountId + " from CurrencyCount table");

            CurrencyCount currencyCount = null;

            SqlConnection sql = DatabaseService.GetSqlConnection();

            //fetch the row
            string     fetch   = "SELECT * FROM dbo.CurrencyCountTable WHERE Id =@Id;";
            SqlCommand command = new SqlCommand(fetch, sql);

            command.Parameters.AddWithValue("@Id", currencyCountId);

            using (SqlDataReader reader = command.ExecuteReader())
            {
                if (reader.Read())
                {
                    currencyCount = new CurrencyCount((long)reader["Id"], (long)reader["WalletId"], CurrencyService.GetCurrency((long)reader["CurrencyId"]), (int)reader["Quantity"]);
                }
            }

            sql.Close();
            return(currencyCount);
        }