/// <summary> /// Get music genre based on the weather, derived from user's location /// </summary> /// <param name="client"></param> /// <returns></returns> public ActionResult <Models.Weather> GetGenre(Models.User client) { //authenticate IEnumerable <Preference> allPreference; Domain.DomainEntities.User user = udb.Find(client.username); ExternalApis.WeatherApi weatherApi = new ExternalApis.WeatherApi(); Domain.DomainEntities.Weather weather = weatherApi.GetWeatherByLocation(user.location); weather = wdb.GetWeather(weather); Domain.DomainEntities.Preference preference = new Domain.DomainEntities.Preference(); allPreference = pdb.GetPreferences(udb.Find(user.username).id); preference = allPreference.Where(x => weather.weather_id == x.weather_id).FirstOrDefault(); if (preference != null) { Domain.DomainEntities.Weather weatherPreference = new Domain.DomainEntities.Weather() { type = weather.type, description = weather.description, default_genre = preference.genre }; return(Ok(ModelMapper.Map(weatherPreference))); } else { return(Ok(ModelMapper.Map(weather))); } }
/// <summary> /// Get the weather based on users zipcode /// </summary> /// <param name="zip"></param> /// <returns></returns> public ActionResult <Domain.DomainEntities.Weather> GetWeather(string zip) { Dictionary <string, string> weatherDictionary = new Dictionary <string, string> { { "Thunderstorm", "African Percussion" }, { "Drizzle", "Classical" }, { "Rain", "R&B" }, { "Snow", "Christmas" }, { "Mist", "Jazz" }, { "Smoke", "Cyberpunk" }, { "Haze", "EDM" }, { "Dust", "Western" }, { "Fog", "Punk" }, { "Sand", "Arab Pop" }, { "Ash", "Rap" }, { "Squall", "Rock" }, { "Tornado", "Metal" }, { "Clear", "Pop" }, { "Clouds", "Indie" } }; ExternalApis.WeatherApi weatherApi = new ExternalApis.WeatherApi(); Domain.DomainEntities.Weather weather = weatherApi.GetWeatherByLocation(zip); ///* uses hard coded dictionary to get default genre Domain.DomainEntities.Weather rweather = weather; rweather.default_genre = weatherDictionary[rweather.type]; //*/ /* uses the database to get genre * Domain.DomainEntities.Weather rweather = wdb.GetWeather(weather); * rweather.description = weather.description; * //*/ return(Ok(rweather)); }