public async Task <IActionResult> PostLocations(Locations locations) { Locations newLocations = new Locations(); newLocations.Latitude = locations.Latitude; newLocations.Longitude = locations.Longitude; string latitude, longitude; latitude = locations.Latitude; longitude = locations.Longitude; string url = "https://api.foursquare.com/v2/venues/search" + "?client_id=OPVXQPHD0AMGMQDGVDAKIWMB21K414HNAXE0KHSCPSHAA2N1" + "&client_secret=DZJ3U51QJ0QJ0YRAK3YSZUKK1AO1TPXA4AKD1LJILDZZ4WQI" + "&v=20180323&limit=10"; string noviUrl = url + "&ll=" + latitude + "," + longitude; HttpClient httpClient = new HttpClient(); string json = await httpClient.GetStringAsync(noviUrl); var jsonDes = JsonConvert.DeserializeObject(json); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _context.Locations.AddAsync(newLocations); _context.SaveChanges(); return(Ok(jsonDes)); }
public void Delete(int id) { var model = this.GetById(id); context.Remove(model); context.SaveChanges(); }
public void CanAddCitiesToLocationDb() { using (LocationDbContext db = new LocationDbContext()) { foreach (string city in JsonLocationReader.Cities()) { Location loc = new Location(city); db.locations.Add(loc); db.SaveChanges(); } } }
public async Task <Unit> Handle(AddUserLocationCommand request, CancellationToken cancellationToken) { _context.UserLocations.Add(new UserLocation( request.UserId, request.BaseCoordinates.Latitude, request.BaseCoordinates.Longitude, request.TargetCoordinates.Latitude, request.TargetCoordinates.Longitude )); _context.SaveChanges(); return(Unit.Value); }
public int SaveChanges() { try { // Transaction işlemleri burada ele alınabilir // veya Identity Map kurumsal tasarım kalıbı kullanılarak // sadece değişen alanları güncellemeyide sağlayabiliriz. return(_dbContext.SaveChanges()); } catch (Exception exception) { // Burada DbEntityValidationException hatalarını handle edebiliriz. Console.Write(exception.Message); throw; } }
public Location GetLocationByIp(string ip = null) { try { var ipDataApi = RestService.For <IIPDataApi>(configuration["IpDataApiDomain"]); Location location = null; if (!string.IsNullOrWhiteSpace(ip)) { location = dbContext.Locations.Find(ip); if (location == null) { var task = ipDataApi.GetLocation(ip, configuration["IPLocation:LocationApiKey"]); task.Wait(); if (task.IsCompletedSuccessfully) { location = task.Result; dbContext.Locations.Add(location); dbContext.SaveChanges(); } else if (task.IsFaulted) { throw new Exception($"Can't get {ip} Location info", task.Exception); } } return(location); } else { var task = ipDataApi.GetLocalLocation(configuration["IPLocation:LocationApiKey"]); task.Wait(); if (task.IsCompletedSuccessfully) { location = task.Result; } else if (task.IsFaulted) { throw new Exception("Can't get local location info", task.Exception); } return(location); } } catch (Exception ex) { Log.Error(ex.ToString()); throw; } }