public IEnumerable <Country> GetAll(int continentId) { GeoContext ctx = new GeoContext(); if (ctx.Continents.Any(c => c.ContinentId == continentId)) { List <Country> cts = new List <Country>(); var countries = ctx.Countries .Join(ctx.CountryMappings, c => new { c.CountryId }, cm => new { cm.CountryId }, (c, cm) => new { Name = c.Name, CountryId = c.CountryId, Surface = c.Surface, ContinentId = cm.ContinentId }).Where(c => c.ContinentId == continentId); foreach (var ct in countries) { Country country = new Country(ct.Name, ct.Surface); country.CountryId = ct.CountryId; cts.Add(country); } return(cts); } else { throw new GeoException("Continent does not exist in db."); } }
/// <summary> /// Add New City to Existing Country /// </summary> /// <param name="context"></param> /// <param name="country"></param> /// <param name="city"></param> /// <param name="eventSender">reference to GraphQL EventSender</param> /// <returns></returns> public async Task <City> AddCity([Service] GeoContext context, string country, string city, [Service] ITopicEventSender eventSender) { Country countryItem = context.Countries.Include(c => c.Cities).FirstOrDefault(c => c.Name == country); if (countryItem == null) { throw new System.Exception("Country not found."); } City cityitem = countryItem.Cities.FirstOrDefault(c => c.Name == city); if (cityitem != null) { throw new System.Exception("City already exists."); } City newCity = new() { Name = city }; countryItem.Cities.Add(newCity); context.SaveChanges(); await eventSender.SendAsync( nameof(Subscription.OnCityAddedAsync), newCity.Id).ConfigureAwait(false); return(newCity); } }
/// <summary> /// Add site to existing city /// </summary> /// <param name="context"></param> /// <param name="cityId"></param> /// <param name="site"></param> /// <param name="eventSender"></param> /// <returns></returns> public async Task <Site> AddSite([Service] GeoContext context, int cityId, string site, [Service] ITopicEventSender eventSender) { City cityItem = context.Cities.Include(c => c.Sites).FirstOrDefault(c => c.Id == cityId); if (cityItem == null) { throw new System.Exception("City not found."); } Site siteitem = cityItem.Sites.FirstOrDefault(s => s.Name == site); if (siteitem != null) { throw new System.Exception("Site already exists."); } Site newSite = new() { Name = site }; cityItem.Sites.Add(newSite); context.SaveChanges(); await eventSender.SendAsync( nameof(Subscription.OnSiteAddedAsync), newSite.Id).ConfigureAwait(false); return(newSite); } }
public Country GetCountry(int continentId, int countryId) { GeoContext ctx = new GeoContext(); if (ctx.Countries.Any(i => i.CountryId == countryId)) { var c = ctx.Countries .Join(ctx.CountryMappings, c => new { c.CountryId }, cm => new { cm.CountryId }, (c, cm) => new { Name = c.Name, CountryId = c.CountryId, Surface = c.Surface, ContinentId = cm.ContinentId }). Where(c => c.CountryId == countryId); if (c.First().ContinentId != continentId) { throw new GeoException("Continent id does not match that which the queried country is located in."); } Country country = new Country(c.First().Name, c.First().Surface); country.CountryId = countryId; return(country); } else { throw new GeoException("Country does not exist in db."); } }
public void AddCity(int continentId, int countryId, City city, int? capital) { GeoContext ctx = new GeoContext(); if (!ctx.Cities.Any(n => n.Name == city.Name)) { Country country = ctx.Countries.Where(c => c.CountryId == countryId).First(); Continent continent = ctx.Continents.Where(c => c.ContinentId == continentId).First(); if (capital == 1) { city.CityMappings = new List<CityMapping> { new CityMapping { City = city, IsCapital = true, Country = ctx.Countries.Single(c => c.CountryId == countryId) } }; } else { city.CityMappings = new List<CityMapping> { new CityMapping { City = city, Country = ctx.Countries.Single(c => c.CountryId == countryId) } }; } country.Population += city.Population; continent.Population += city.Population; ctx.Countries.Update(country); ctx.Continents.Update(continent); ctx.Cities.Add(city); ctx.SaveChanges(); } else throw new GeoException("City already added to db."); }
public void UpdateCity(int continentId, int countryId, City city) { GeoContext ctx = new GeoContext(); if (ctx.Cities.Any(n => n.Name == city.Name)) { GeoContext popContext = new GeoContext(); int oldCityPopulation = popContext.Cities.Where(c => c.CityId == city.CityId).First().Population; Continent continent = ctx.Continents.Where(c => c.ContinentId == continentId).First(); Country country = ctx.Countries.Where(c => c.CountryId == countryId).First(); if (oldCityPopulation > city.Population) { continent.Population -= city.Population; country.Population -= city.Population; } else { continent.Population += city.Population; country.Population += city.Population; } ctx.Continents.Update(continent); ctx.Countries.Update(country); ctx.Cities.Update(city); ctx.SaveChanges(); } else throw new GeoException("City does not exist in db."); }
/// <summary> /// Indicate the state of a photo's geotagginess beyond latitude and longitude. /// </summary> /// <remarks> /// Note : photos passed to this method must already be geotagged (using the flickr.photos.geo.setLocation method). /// </remarks> /// <param name="photoId">The id of the photo to set context data for.</param> /// <param name="context">ontext is a numeric value representing the photo's geotagginess beyond latitude and longitude. /// For example, you may wish to indicate that a photo was taken "indoors" or "outdoors". </param> public void PhotosGeoSetContext(string photoId, GeoContext context) { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("method", "flickr.photos.geo.setContext"); parameters.Add("photo_id", photoId); parameters.Add("context", context.ToString("D")); GetResponseNoCache <NoResponse>(parameters); }
/// <summary> /// Indicate the state of a photo's geotagginess beyond latitude and longitude. /// </summary> /// <remarks> /// Note : photos passed to this method must already be geotagged (using the flickr.photos.geo.setLocation method). /// </remarks> /// <param name="photoId">The id of the photo to set context data for.</param> /// <param name="context">Context is a numeric value representing the photo's geotagginess beyond latitude and longitude. /// For example, you may wish to indicate that a photo was taken "indoors" or "outdoors". </param> /// <param name="callback">Callback method to call upon return of the response from Flickr.</param> public void PhotosGeoSetContextAsync(string photoId, GeoContext context, Action <FlickrResult <NoResponse> > callback) { var parameters = new Dictionary <string, string>(); parameters.Add("method", "flickr.photos.geo.setContext"); parameters.Add("photo_id", photoId); parameters.Add("context", context.ToString("D")); GetResponseAsync <NoResponse>(parameters, callback); }
public bool ExistsCity(int id) { GeoContext ctx = new GeoContext(); if (ctx.Cities.Any(c => c.CityId == id)) { return true; } else return false; }
public bool ExistsRiver(int id) { GeoContext ctx = new GeoContext(); if (ctx.Rivers.Any(r => r.RiverId == id)) { return(true); } else { return(false); } }
public bool ExistsContinent(int id) { GeoContext ctx = new GeoContext(); if (ctx.Continents.Any(c => c.ContinentId == id)) { return(true); } else { return(false); } }
public void RemoveRiver(int id) { GeoContext ctx = new GeoContext(); if (ExistsRiver(id)) { ctx.Rivers.Remove(ctx.Rivers.Single(r => r.RiverId == id)); ctx.SaveChanges(); } else { throw new GeoException("River does not exist in db."); } }
public void AddContinent(Continent continent) { GeoContext ctx = new GeoContext(); if (!ctx.Continents.Any(c => c.Name == continent.Name)) { ctx.Continents.Add(continent); ctx.SaveChanges(); } else { throw new GeoException("Continent already added to db."); } }
public void RemoveContinent(int id) { GeoContext ctx = new GeoContext(); if (ExistsContinent(id)) { ctx.Continents.Remove(ctx.Continents.Single(c => c.ContinentId == id)); ctx.SaveChanges(); } else { throw new GeoException("Continent does not exist in db."); } }
public void UpdateCountry(Country country) { GeoContext ctx = new GeoContext(); if (ExistsCountry(country.CountryId)) { ctx.Countries.Update(country); ctx.SaveChanges(); } else { throw new GeoException("Country does not exist in db."); } }
public void UpdateRiver(River river) { GeoContext ctx = new GeoContext(); if (ExistsRiver(river.RiverId)) { ctx.Rivers.Update(river); ctx.SaveChanges(); } else { throw new GeoException("River does not exist in db."); } }
public void RemoveCountry(int continentId, int countryId) { GeoContext ctx = new GeoContext(); if (ExistsCountry(countryId)) { ctx.Countries.Remove(ctx.Countries.Single(c => c.CountryId == countryId)); ctx.SaveChanges(); } else { throw new GeoException("Country does not exist in db."); } }
public void UpdateContinent(Continent continent) { GeoContext ctx = new GeoContext(); if (ExistsContinent(continent.ContinentId)) { ctx.Continents.Update(continent); ctx.SaveChanges(); } else { throw new GeoException("Continent does not exist in db."); } }
/// <summary> /// Create new Country, with capital /// </summary> /// <param name="context"></param> /// <param name="country"></param> /// <param name="captial"></param> /// <param name="eventSender">reference to GraphQL EventSender</param> /// <returns></returns> public async Task <Country> AddCountry([Service] GeoContext context, string country, string captial, [Service] ITopicEventSender eventSender) { Country item = context.Countries.FirstOrDefault(c => c.Name == country); if (item != null) { return(item); } //throw new System.Exception("Country already exists."); Country newCountry = context.CreateCountry(country, captial, System.Array.Empty <string>()); await eventSender.SendAsync( nameof(Subscription.OnCountryAddedAsync), newCountry.Id).ConfigureAwait(false); return(newCountry); }
public River GetRiver(int id) { GeoContext ctx = new GeoContext(); if (ExistsRiver(id)) { List <RiverMapping> rms = new List <RiverMapping>(); var r = ctx.Rivers .Where(r => r.RiverId == id) .Join(ctx.RiverMappings, r => new { RiverId = r.RiverId }, rm => new { rm.RiverId }, (r, rm) => new { Name = r.Name, RiverId = r.RiverId, Length = r.Length, CountryId = rm.CountryId }); foreach (var rm in r) { RiverMapping rmData = new RiverMapping { RiverId = id, CountryId = rm.CountryId }; rms.Add(rmData); } if (rms.Count == 0) { return(ctx.Rivers.Where(r => r.RiverId == id).First()); } River river = new River { RiverId = id, Name = r.First().Name, Length = r.First().Length, RiverMappings = rms }; return(river); } else { throw new GeoException("River does not exist in db."); } }
public Continent GetContinent(int id) { GeoContext ctx = new GeoContext(); if (ExistsContinent(id)) { List <CountryMapping> cms = new List <CountryMapping>(); var c = ctx.Continents .Where(c => c.ContinentId == id) .Join(ctx.CountryMappings, c => new { c.ContinentId }, cm => new { cm.ContinentId }, (c, cm) => new { Name = c.Name, ContinentId = c.ContinentId, Population = c.Population, CountryId = cm.CountryId }); foreach (var cm in c) { CountryMapping cmData = new CountryMapping { ContinentId = id, CountryId = cm.CountryId }; cms.Add(cmData); } if (cms.Count == 0) { return(ctx.Continents.Where(c => c.ContinentId == id).First()); } Continent continent = new Continent { ContinentId = id, Name = c.First().Name, Population = c.First().Population, CountryMappings = cms }; return(continent); } else { throw new GeoException("Continent does not exist in db."); } }
public City GetCity(int cityId, int countryId, int continentId) { GeoContext ctx = new GeoContext(); if (ExistsCity(cityId)) { var city = ctx.Cities .Join(ctx.CityMappings, c => new { c.CityId }, cm => new { cm.CityId }, (c, cm) => new { CityId = c.CityId, CountryId = cm.CountryId, Name = c.Name, Population = c.Population }) .Join(ctx.CountryMappings, c => new { c.CountryId }, cm => new { cm.CountryId }, (c, cm) => new { CityId = c.CityId, CountryId = c.CountryId, ContinentId = cm.ContinentId, Name = c.Name, Population = c.Population }).Where(c => c.CityId == cityId); if (cityId != city.First().CityId || countryId != city.First().CountryId || continentId != city.First().ContinentId) { throw new GeoException("Country or continent id do not match that which the city is located at."); } City c = new City { CityId = city.First().CityId, Name = city.First().Name, Population = city.First().Population }; return c; } else throw new GeoException("City does not exist in db."); }
public void RemoveCity(int continentId, int countryId, int cityId) { GeoContext ctx = new GeoContext(); if (ctx.Cities.Any(c => c.CityId == cityId)) { City city = ctx.Cities.Where(c => c.CityId == cityId).First(); Country country = ctx.Countries.Where(c => c.CountryId == countryId).First(); Continent continent = ctx.Continents.Where(c => c.ContinentId == continentId).First(); country.Population -= city.Population; continent.Population -= city.Population; ctx.Continents.Update(continent); ctx.Countries.Update(country); ctx.Cities.Remove(city); ctx.SaveChanges(); } else throw new GeoException("City does not exist in db."); }
public void AddCountry(Country country, int id) { GeoContext ctx = new GeoContext(); if (!ctx.Countries.Any(c => c.Name == country.Name)) { country.CountryMappings = new List <CountryMapping> { new CountryMapping { Country = country, Continent = ctx.Continents.Single(c => c.ContinentId == id) } }; ctx.Countries.Add(country); ctx.SaveChanges(); } else { throw new GeoException("Country already added to db."); } }
public void AddRiver(River river, int id) { GeoContext ctx = new GeoContext(); if (!ctx.Rivers.Any(r => r.Name == river.Name)) { river.RiverMappings = new List <RiverMapping> { new RiverMapping { River = river, Country = ctx.Countries.Single(c => c.CountryId == id) } }; ctx.Rivers.Add(river); ctx.SaveChanges(); } else { throw new GeoException("River already added to db."); } }
public IEnumerable<City> GetAll(int continentId, int countryId) { GeoContext ctx = new GeoContext(); var citiesData = ctx.Cities.Join(ctx.CityMappings, c => new { c.CityId }, cm => new { cm.CityId }, (c, cm) => new { CityId = c.CityId, Name = c.Name, Population = c.Population, IsCapital = cm.IsCapital, CountryId = cm.CountryId }).Join(ctx.CountryMappings, c => new { c.CountryId }, cm => new { cm.CountryId }, (c, cm) => new { CityId = c.CityId, Name = c.Name, Population = c.Population, IsCapital = c.IsCapital, CountryId = c.CountryId, ContinentId = cm.ContinentId }).Where(c => c.ContinentId == continentId); List<City> cities = new List<City>(); foreach (var city in citiesData) { City c = new City { Name = city.Name, CityId = city.CityId, Population = city.Population }; cities.Add(c); } return cities; }
public void SaveTo(GeoContext context) { if (!_dimensions.Any() || !_ores.Any()) { throw new InvalidOperationException(); } var oreNames = _ores .Select(o => o.ToString()) .OrderBy(o => o); var info = new VeinInfo { Name = string.Join("/", oreNames), YMax = _yMax, YMin = _yMin }; context.Veins.Add(info); foreach (var dimension in _dimensions) { var dimensionInfo = new VeinDimensionInfo { Dimension = dimension, VeinInfo = info }; context.VeinDimensions.Add(dimensionInfo); } foreach (var ore in _ores) { var oreInfo = new VeinOreInfo { Ore = ore, VeinInfo = info }; context.VeinOres.Add(oreInfo); } }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var c = controllerContext.HttpContext.Request.Cookies["jaar"]; if (c == null) { return(new Jaar(0)); } if (c.Value == null) { return(new Jaar(0)); } if (c.Value == "") { return(new Jaar(0)); } var context = new GeoContext(); var repo = new JaarRepository(context); return(repo.FindAll() .First(e => e.Leerjaar.ToString() == c.Value)); }
public void PhotosGeoSetContext(string photoId, GeoContext context);
/// <summary> /// Sets the geo location for a photo. /// </summary> /// <param name="photoId">The ID of the photo to set to location for.</param> /// <param name="latitude">The latitude of the geo location. A double number ranging from -180.00 to 180.00. /// Digits beyond 6 decimal places will be truncated.</param> /// <param name="longitude">The longitude of the geo location. A double number ranging from -180.00 to 180.00. /// Digits beyond 6 decimal places will be truncated.</param> /// <param name="accuracy">The accuracy of the photos geo location.</param> /// <param name="context">The context of the geolocation data, i.e. Inside or Outside.</param> public void PhotosGeoSetLocation(string photoId, double latitude, double longitude, GeoAccuracy accuracy, GeoContext context) { var parameters = new Dictionary<string, string>(); parameters.Add("method", "flickr.photos.geo.setLocation"); parameters.Add("photo_id", photoId); parameters.Add("lat", latitude.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); parameters.Add("lon", longitude.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); if (accuracy != GeoAccuracy.None) parameters.Add("accuracy", accuracy.ToString("D")); if (context != GeoContext.NotDefined) parameters.Add("context", context.ToString("D")); GetResponseNoCache<NoResponse>(parameters); }
/// <summary> /// Indicate the state of a photo's geotagginess beyond latitude and longitude. /// </summary> /// <remarks> /// Note : photos passed to this method must already be geotagged (using the flickr.photos.geo.setLocation method). /// </remarks> /// <param name="photoId">The id of the photo to set context data for.</param> /// <param name="context">ontext is a numeric value representing the photo's geotagginess beyond latitude and longitude. /// For example, you may wish to indicate that a photo was taken "indoors" or "outdoors". </param> public void PhotosGeoSetContext(string photoId, GeoContext context) { var parameters = new Dictionary<string, string>(); parameters.Add("method", "flickr.photos.geo.setContext"); parameters.Add("photo_id", photoId); parameters.Add("context", context.ToString("D")); GetResponseNoCache<NoResponse>(parameters); }
public void PhotosGeoSetContext(string photoId, GeoContext context) { var dictionary = new Dictionary<string, string>(); dictionary.Add("method", "flickr.photos.geo.setContext"); dictionary.Add("photo_id", photoId); dictionary.Add("context", context.ToString("d")); GetResponse<NoResponse>(dictionary); }
public GeoContext geo() { GeoContext _localctx = new GeoContext(Context, State); EnterRule(_localctx, 80, RULE_geo); int _la; try { EnterOuterAlt(_localctx, 1); { State = 1305; k_geo(); State = 1310; ErrorHandler.Sync(this); _la = TokenStream.La(1); while (_la==SCOL) { { { State = 1306; Match(SCOL); State = 1307; other_param(); } } State = 1312; ErrorHandler.Sync(this); _la = TokenStream.La(1); } State = 1313; Match(COL); State = 1314; geovalue(); State = 1315; Match(CRLF); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return _localctx; }
public void PhotosGeoSetLocation(string photoId, double lat, double lon, GeoContext context) { PhotosGeoSetLocation(photoId, lat, lon, GeoAccuracy.None, context); }
public void PhotosGeoSetLocation(string photoId, double lat, double lon, GeoAccuracy accuracy, GeoContext context) { var dictionary = new Dictionary<string, string>(); dictionary.Add("method", "flickr.photos.geo.setLocation"); dictionary.Add("photo_id", photoId); dictionary.Add("lat", lat.ToString(NumberFormatInfo.InvariantInfo)); dictionary.Add("lon", lon.ToString(NumberFormatInfo.InvariantInfo)); if (accuracy != GeoAccuracy.None) dictionary.Add("accuracy", accuracy.ToString("d")); if (context != GeoContext.NotDefined) dictionary.Add("context", context.ToString("d")); GetResponse<NoResponse>(dictionary); }
/// <summary> /// Indicate the state of a photo's geotagginess beyond latitude and longitude. /// </summary> /// <remarks> /// Note : photos passed to this method must already be geotagged (using the flickr.photos.geo.setLocation method). /// </remarks> /// <param name="photoId">The id of the photo to set context data for.</param> /// <param name="context">Context is a numeric value representing the photo's geotagginess beyond latitude and longitude. /// For example, you may wish to indicate that a photo was taken "indoors" or "outdoors". </param> /// <param name="callback">Callback method to call upon return of the response from Flickr.</param> public void PhotosGeoSetContextAsync(string photoId, GeoContext context, Action<FlickrResult<NoResponse>> callback) { Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("method", "flickr.photos.geo.setContext"); parameters.Add("photo_id", photoId); parameters.Add("context", context.ToString("D")); GetResponseAsync<NoResponse>(parameters, callback); }
public ComponentRepository(GeoContext context) { _context = context; _componenten = _context.DeterminatieComponent; }
public LandRepository(GeoContext context) { _context = context; _landen = _context.Land; }
/// <summary> /// Indicate the state of a photo's geotagginess beyond latitude and longitude. /// </summary> /// <remarks> /// Note : photos passed to this method must already be geotagged (using the flickr.photos.geo.setLocation method). /// </remarks> /// <param name="photoId">The id of the photo to set context data for.</param> /// <param name="context">ontext is a numeric value representing the photo's geotagginess beyond latitude and longitude. For example, you may wish to indicate that a photo was taken "indoors" or "outdoors". </param> /// <param name="callback">Callback method to call upon return of the response from Flickr.</param> public async Task<FlickrResult<NoResponse>> PhotosGeoSetContextAsync(string photoId, GeoContext context) { Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("method", "flickr.photos.geo.setContext"); parameters.Add("photo_id", photoId); parameters.Add("context", context.ToString("D")); return await GetResponseAsync<NoResponse>(parameters); }