/// <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)); }
public void DeletePreference_validPreference_Null() { Domain.DomainEntities.Preference testPreference = new Domain.DomainEntities.Preference(); Domain.DomainEntities.User testUser = udb.Find("backendTest"); var preferences = pdb.GetPreferences(testUser.id); foreach (var p in preferences) { if (p.genre == "testGenre") { testPreference = p; } } pdb.DeletePreference(testPreference); udb.Delete(testUser); Domain.DomainEntities.Weather testWeather = new Domain.DomainEntities.Weather(); testWeather.type = "testType"; testWeather.description = "testDescription"; testWeather.default_genre = "testGenre"; wdb.DeleteWeather(wdb.GetWeather(testWeather)); Assert.IsTrue(true); }
public static Entities.Weather Map(DomainEntities.Weather w) { if (w == null) { return(null); } return(new Entities.Weather { Id = w.weather_id, Type = w.type, Description = w.description, DefaultGenre = w.default_genre }); }
public void SetPreference_validPreference_True() { Domain.DomainEntities.User testUser = new Domain.DomainEntities.User(); testUser.username = "******"; testUser.password = "******"; testUser.location = "98908"; udb.Create(testUser); Domain.DomainEntities.Weather testWeather = new Domain.DomainEntities.Weather(); testWeather.type = "testType"; testWeather.description = "testDescription"; testWeather.default_genre = "testGenre"; wdb.CreateWeather(testWeather); Domain.DomainEntities.Preference testPreference = new Domain.DomainEntities.Preference(); testPreference.genre = "testGenre"; testPreference.weather_id = wdb.GetWeather(testWeather).weather_id; testPreference.user_id = udb.Find(testUser.username).id; pdb.SetPreference(testPreference); Assert.IsTrue(true); }
public virtual void DeleteWeather(Domain.DomainEntities.Weather weather) { DatabaseInstance.GetContext().Remove(DatabaseInstance.GetContext().Weather.Find(weather.weather_id)); DatabaseInstance.GetContext().SaveChanges(); }
public virtual Domain.DomainEntities.Weather GetWeather(Domain.DomainEntities.Weather type) { return(Mapper.Map(DatabaseInstance.GetContext().Weather.Where(x => x.Type == type.type).FirstOrDefault())); }
public virtual void CreateWeather(Domain.DomainEntities.Weather weather) { DatabaseInstance.GetContext().Add(Mapper.Map(weather)); DatabaseInstance.GetContext().SaveChanges(); }