Example #1
0
        public IHttpActionResult GetTradingVolume([FromODataUri] string productName, CountryOrRegion portingCountryOrRegion)
        {
            var  trades        = Trades.Where(t => t.ProductName == productName && t.PortingCountryOrRegion == portingCountryOrRegion).ToArray();
            long?tradingVolume = 0;

            foreach (var trade in trades)
            {
                tradingVolume += trade.TradingVolume;
            }
            return(Ok(tradingVolume));
        }
Example #2
0
            /// <summary>
            /// Gets the list of countries or regions by locale.
            /// </summary>
            /// <param name="locale">The locale.</param>
            /// <returns>The result list.</returns>
            public IEnumerable <CountryOrRegion> GetCountryRegionListByLocale(string locale)
            {
                if (locale == null)
                {
                    throw new ArgumentNullException("locale");
                }

                var countries = new List <CountryOrRegion>();

                using (SqlConnection connection = new SqlConnection(this.connectionString))
                {
                    connection.Open();

                    using (SqlCommand command = new SqlCommand(GetCountryListByLocaleSprocName, connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@nvc_Locale", locale);

                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var country = new CountryOrRegion();
                                country.TwoLetterCode = GetString(reader, reader.GetOrdinal("TWOLETTERISOCODE"));
                                country.Locale        = GetString(reader, reader.GetOrdinal("LOCALE"));
                                country.ShortName     = GetString(reader, reader.GetOrdinal("SHORTNAME"));
                                country.LongName      = GetString(reader, reader.GetOrdinal("LONGNAME"));

                                countries.Add(country);
                            }
                        }
                    }
                }

                // If no country or region is found for the requested locale, fall back to en-US.
                string fallbackLocale = "en-US";

                if (countries.Count == 0 && !locale.Equals(fallbackLocale, StringComparison.OrdinalIgnoreCase))
                {
                    countries.AddRange(this.GetCountryRegionListByLocale(fallbackLocale));
                }

                return(countries);
            }
Example #3
0
        public IHttpActionResult GetTradeByCountry([FromODataUri] CountryOrRegion countryOrRegion)
        {
            var trades = Trades.Where(t => t.PortingCountryOrRegion == countryOrRegion).ToList();

            return(Ok(trades));
        }