Exemplo n.º 1
0
        public List <AllCoins> GetAllUserCoins()
        {
            string userId = UserService.GetCurrentUserId();

            if (userId != null)
            {
                List <AllCoins> CoinList = new List <AllCoins>();
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand("dbo.Users_GetAllCoins", conn))
                    {
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@UserId", userId);
                        SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                        while (reader.Read())
                        {
                            AllCoins model = Mapper2(reader);
                            CoinList.Add(model);
                        }
                    }
                    conn.Close();
                }
                return(CoinList);
            }
            return(null);
        }
Exemplo n.º 2
0
        private AllCoins Mapper2(SqlDataReader reader)
        {
            AllCoins model = new AllCoins();
            int      index = 0;

            model.CoinName      = reader.GetString(index++);
            model.Symbol        = reader.GetString(index++);
            model.NumberOfCoins = reader.GetDouble(index++);
            model.Id            = reader.GetInt32(index++);
            model.AverageValue  = reader.GetDouble(index++);
            index++;
            return(model);
        }